def make_move_ai(self, board): best_move = -1, -1 if self.val == "O": best_val = -1000 for cols in range(3): for rows in range(3): if board.isValidMove(cols, rows): temp_board = GameBoard() temp_board.board = copy.deepcopy(board.board) temp_board.playpiece(cols, rows, self.val) move_val = self.minimax(temp_board, 0, False) if move_val > best_val: best_val = move_val best_move = cols, rows else: best_val = 1000 for cols in range(3): for rows in range(3): if board.isValidMove(cols, rows): temp_board = GameBoard() temp_board.board = copy.deepcopy(board.board) temp_board.playpiece(cols, rows, self.val) move_val = self.minimax(temp_board, 0, True) if move_val < best_val: best_val = move_val best_move = cols, rows print("Player " + self.val + ": Minimax Score = " + str(best_val) + " - Optimal move = " + str(best_move)) board.playpiece(best_move[0], best_move[1], self.val)