minimise the worst case scenario (loss). ➤ It’s about minimising one’s maximum loss or maximising one’s minimum gain (hence the term Minimax) ➤ Originally designed for two player games where each player would alternate turns.
Otherwise, get all possible moves in board ➤ For each move ➤ Add minimax of that move to a scores list ➤ If it’s the AI’s turn, return max(scores) ➤ If it’s the player’s turn, return min(scores)
self.get_score(board) if score == 0: # Check for draw if len(empty_cells) == 0: return score else: return score scores = [] for cell in empty_cells: b = list(board) b[cell] = player scores.append(self.minimax(b, self.opponent(player))) if player == self.player: return max(scores) else: return min(scores)