How does this minimax function work? def minimax(self, game,…

Question Answered step-by-step How does this minimax function work? def minimax(self, game,… How does this minimax function work?  def minimax(self, game, time_left, depth=float(“inf”), maximizing_player=True): “””Implementation of the minimax algorithm. Args: player (CustomPlayer): This is the instantiation of CustomPlayer() that represents your agent. It is used to call anything you need from the CustomPlayer class (the utility() method, for example, or any class variables that belong to CustomPlayer()). game (Board): A board and game state. time_left (function): Used to determine time left before timeout depth: Used to track how deep you are in the search tree my_turn (bool): True if you are computing scores during your turn. Returns: (tuple, int): best_move, val “”” best_move = None best_queen = None moves = [(queen, move) for queen, legal_moves in game.get_legal_moves().iteritems() for move in legal_moves] value_list = [] if depth == 1 or len(moves) == 0: return best_move, best_queen, self.utility(game) for queen, move in moves: forecasted_game = game.forecast_move(move, queen) _, _, val = self.minimax(forecasted_game, time_left, depth=(depth – 1), maximizing_player=(not maximizing_player)) value_list.append(val) if maximizing_player: index, best_val = max(enumerate(value_list), key=itemgetter(1)) else: index, best_val = min(enumerate(value_list), key=itemgetter(1)) best_queen, best_move = moves[index] return best_move, best_queen, best_val Computer Science Engineering & Technology Python Programming CSC 8520 Share QuestionEmailCopy link Comments (0)