Exemplo n.º 1
0
    def genmove_cmd(self, args):

        try:
            color = GoBoardUtil.color_to_int(args[0].lower())
            move = self.policy_moves_return_cmd(color)
            if move is None:
                self.respond("pass")
                return
            print(move)
            one_move = move[0]
            print(one_move)
            if not self.board.check_legal(one_move, color):
                one_move = self.board._point_to_coord(one_move)
                board_move = GoBoardUtil.format_point(one_move)
                self.respond("Illegal move: {}".format(board_move))
                raise RuntimeError("Illegal move given by engine")

            # move is legal; play it
            self.board.move(one_move, color)

            self.debug_msg("Move: {}\nBoard: \n{}\n".format(
                one_move, str(self.board.get_twoD_board())))
            one_move = self.board._point_to_coord(one_move)
            board_move = GoBoardUtil.format_point(one_move)
            self.respond(board_move)
        except Exception as e:
            print(e)
            self.respond('Error: {}'.format(str(e)))
Exemplo n.º 2
0
    def genmove_cmd(self, args):
        """
        generate a move for the specified color

        Arguments
        ---------
        args[0] : {'b','w'}
            the color to generate a move for
            it gets converted to  Black --> 1 White --> 2
            color : {0,1}
            board_color : {'b','w'}
        """
        try:
            board_color = args[0].lower()
            color = GoBoardUtil.color_to_int(board_color)
            move = self.go_engine.get_move(self.board, color)
            if move is None:
                self.respond("pass")
                return

            if not self.board.check_legal(move, color):
                move = self.board._point_to_coord(move)
                board_move = GoBoardUtil.format_point(move)
                self.respond("Illegal move: {}".format(board_move))
                raise RuntimeError("Illegal move given by engine")

            # move is legal; play it
            self.board.move(move, color)
            self.debug_msg("Move: {}\nBoard: \n{}\n".format(move, str(self.board.get_twoD_board())))
            move = self.board._point_to_coord(move)
            board_move = GoBoardUtil.format_point(move)
            self.respond(board_move)
        except Exception as e:
            self.respond('Error: {}'.format(str(e)))
    def genmove_cmd(self, args):
        """
        generate a move for the specified color

        Arguments
        ---------
        args[0] : {'b','w'}
            the color to generate a move for
            it gets converted to  Black --> 1 White --> 2
            color : {0,1}
            board_color : {'b','w'}
        """
        try:
            board_color = args[0].lower()
            color = GoBoardUtil.color_to_int(board_color)
            self.debug_msg("Board:\n{}\nko: {}\n".format(
                str(self.board.get_twoD_board()), self.board.ko_constraint))
            self.current_player = color
            move = self.go_engine.get_move(self.board, color)

            # policy_moves, type_of_move = GoBoardUtil.generate_all_policy_moves(self.board,
            #self.go_engine.pattern,
            #self.go_engine.selfatari)
            # result = []
            # for i in range(len(policy_moves)):
            #     result1 = []
            #     result1.append(policy_moves[i])
            #     result.append(GoBoardUtil.sorted_point_string(result1, self.board.NS))
            # print(len(result))
            # if len(result) != 0:
            #     row, col = GoBoardUtil.move_to_coord(random.choice(result), self.board.size)
            #     move = self.board._coord_to_point(row, col)

            # print(policy_moves[0])
            # row, col = GoBoardUtil.move_to_coord(policy_moves[0], self.board.size)
            # move = policy_moves[0]

            if move is None:
                self.respond("pass")
                return

            if not self.board.check_legal(move, color):
                move = self.board._point_to_coord(move)
                board_move = GoBoardUtil.format_point(move)
                self.respond("Illegal move: {}".format(board_move))
                raise RuntimeError("Illegal move given by engine")

            # move is legal; play it
            self.board.move(move, color)
            self.debug_msg("Move: {}\nBoard: \n{}\n".format(
                move, str(self.board.get_twoD_board())))
            move = self.board._point_to_coord(move)
            board_move = GoBoardUtil.format_point(move)
            self.respond(board_move)
        except Exception as e:
            self.respond('Error: {}'.format(str(e)))
Exemplo n.º 4
0
    def genmove_cmd(self, args):
        """
        generate a move for the specified color

        Arguments
        ---------
        args[0] : {'b','w'}
            the color to generate a move for
            it gets converted to  Black --> 1 White --> 2
            color : {0,1}
            board_color : {'b','w'}
        """
        try:
            board_color = args[0].lower()
            color = GoBoardUtil.color_to_int(board_color)
            self.debug_msg("Board:\n{}\nko: {}\n".format(str(self.board.get_twoD_board()),
                                                          self.board.ko_constraint))

            # Assignment4 - policy probabilistic player
            # =========================================
            if color != self.board.current_player:
                self.respond("Opponent's turn")
                return

            move_prob_tuples = self.get_move_prob()
            if move_prob_tuples[0][0] == 'pass':
                self.respond("pass")
                self.go_engine.update('pass')
                self.board.move(None, color)
                return

            # based on
            # https://docs.python.org/3.5/library/random.html
            population = [val for val, cnt in move_prob_tuples for _ in range(int(cnt*1e5))]
            move = random.choice(population)
            move = GoBoardUtil.move_to_coord(move, self.board.size)
            move = self.board._coord_to_point(move[0], move[1])
            # =========================================

            if not self.board.check_legal(move, color):
                move = self.board._point_to_coord(move)
                board_move = GoBoardUtil.format_point(move)
                self.respond("Illegal move: {}".format(board_move))
                traceback.print_exc(file=sys.stdout)
                self.respond('Error: {}'.format(str(e)))
                raise RuntimeError("Illegal move given by engine")

            # move is legal; play it
            self.board.move(move, color)
            self.debug_msg("Move: {}\nBoard: \n{}\n".format(move, str(self.board.get_twoD_board())))
            move = self.board._point_to_coord(move)
            board_move = GoBoardUtil.format_point(move)
            self.respond(board_move)
        except Exception as e:
            self.respond('Error: {}'.format(str(e)))
Exemplo n.º 5
0
    def genmove_cmd(self, args):
        """
        generate a move for the specified color

        Arguments
        ---------
        args[0] : {'b','w'}
            the color to generate a move for
            it gets converted to  Black --> 1 White --> 2
            color : {0,1}
            board_color : {'b','w'}
        """
        try:
            board_color = args[0].lower()
            color = GoBoardUtil.color_to_int(board_color)
            self.debug_msg("Board:\n{}\nko: {}\n".format(
                str(self.board.get_twoD_board()), self.board.ko_constraint))
            #move = self.go_engine.get_move(self.board, color)
            policy_moves, type_of_move = GoBoardUtil.generate_all_policy_moves(
                self.board, self.go_engine.pattern, self.go_engine.selfatari,
                color)
            if len(policy_moves) == 0:
                self.respond("Pass")
            else:
                #print(policy_moves)
                move = policy_moves[randint(0, len(policy_moves) - 1)]
                #print(move)
                #move = GoBoardUtil.point_to_coord(move)
                #move = GoBoardUtil.sorted_point_string(policy_moves[randint(0,len(policy_moves)-1)], self.board.NS)
                #print(move)
                #print(move)
                #response = type_of_move + " " + GoBoardUtil.sorted_point_string(policy_moves, self.board.NS)
                #self.respond(response)

            if move is None:
                self.respond("pass")
                return

            if not self.board.check_legal(move, color):
                move = self.board._point_to_coord(move)
                board_move = GoBoardUtil.format_point(move)
                self.respond("Illegal move: {}".format(board_move))
                raise RuntimeError("Illegal move given by engine")

            # move is legal; play it
            self.board.move(move, color)
            self.debug_msg("Move: {}\nBoard: \n{}\n".format(
                move, str(self.board.get_twoD_board())))
            move = self.board._point_to_coord(move)
            board_move = GoBoardUtil.format_point(move)
            self.respond(board_move)
        except Exception as e:
            self.respond('Error: {}'.format(str(e)))
Exemplo n.º 6
0
    def genmove_cmd(self, args):
        """
        generate a move for the specified color

        Arguments
        ---------
        args[0] : {'b','w'}
            the color to generate a move for
            it gets converted to  Black --> 1 White --> 2
            color : {0,1}
            board_color : {'b','w'}
        """
        try:
            board_color = args[0].lower()
            color = GoBoardUtil.color_to_int(board_color)

            # First try to solve the state and generate a best move
            to_play_bkp = self.board.to_play
            self.board.to_play = color
            score = self.board.call_search()
            if score == 1:
                # The player can win, make a move
                _, move = self.board.tree_cache[self.board]
                coord = GoBoardUtil.move_to_coord(move, self.board.size)
                point = self.board._coord_to_point(coord[0], coord[1])
                self.board.move(point, color)
                self.respond(GoBoardUtil.format_point(coord))
                return
            # Opponent can win or timeout, use the existing code to generate
            # a random move
            self.board.to_play = to_play_bkp

            move = self.go_engine.get_move(self.board, color)
            if move is None:
                # self.respond("pass")
                self.respond("resign")
                return

            if not self.board.check_legal(move, color):
                move = self.board._point_to_coord(move)
                board_move = GoBoardUtil.format_point(move)
                self.respond("Illegal move: {}".format(board_move))
                raise RuntimeError("Illegal move given by engine")

            # move is legal; play it
            self.board.move(move, color)
            self.debug_msg("Move: {}\nBoard: \n{}\n".format(
                move, str(self.board.get_twoD_board())))
            move = self.board._point_to_coord(move)
            board_move = GoBoardUtil.format_point(move)
            self.respond(board_move)
        except Exception as e:
            self.respond('Error: {}'.format(str(e)))
Exemplo n.º 7
0
    def genmove_cmd(self, args):
        """
        generate a move for the specified color

        Arguments
        ---------
        args[0] : {'b','w'}
            the color to generate a move for
            it gets converted to  Black --> 1 White --> 2
            color : {0,1}
            board_color : {'b','w'}
        """
        try:
            board_color = args[0].lower()
            color = GoBoardUtil.color_to_int(board_color)
            self.debug_msg("Board:\n{}\nko: {}\n".format(
                str(self.board.get_twoD_board()), self.board.ko_constraint))

            # Assignment4 - policy max player
            # =========================================
            if color != self.board.current_player:
                self.respond("Opponent's turn")
                return

            move = self.get_move_prob()[0][0]
            if move == 'pass':
                self.respond("pass")
                self.go_engine.update('pass')
                self.board.move(None, color)
                return
            move = GoBoardUtil.move_to_coord(move, self.board.size)
            move = self.board._coord_to_point(move[0], move[1])
            # =========================================

            if not self.board.check_legal(move, color):
                move = self.board._point_to_coord(move)
                board_move = GoBoardUtil.format_point(move)
                self.respond("Illegal move: {}".format(board_move))
                traceback.print_exc(file=sys.stdout)
                self.respond('Error: {}'.format(str(e)))
                raise RuntimeError("Illegal move given by engine")

            # move is legal; play it
            self.board.move(move, color)
            self.debug_msg("Move: {}\nBoard: \n{}\n".format(
                move, str(self.board.get_twoD_board())))
            move = self.board._point_to_coord(move)
            board_move = GoBoardUtil.format_point(move)
            self.respond(board_move)
        except Exception as e:
            self.respond('Error: {}'.format(str(e)))
 def _point_to_move(self, point):
     if point == 'pass':
         return 'pass'
     elif point:
         coord = self.board._point_to_coord(point)
         return GoBoardUtil.format_point(coord)
     return None
Exemplo n.º 9
0
    def prior_knowledge_cmd(self, args):
        '''
        '''
        # get moves and probs for legal moves using function given in GoBoardUtilGo4, but with pass move
        moves, probs = GoBoardUtilGo4.generate_moves_with_feature_based_probs(
            self.board)
        priorKnowledgeList = GoBoardUtilGo4.prior_knowledge_initialization(
            moves, probs)
        color = self.board.current_player
        response = ""

        # convert moves from format 9 to a1
        for move in priorKnowledgeList:
            # jank? need to print PASS as Pass
            if move[0] == 'PASS':
                move[0] = 'Pass'
            else:
                move[0] = GoBoardUtil.format_point(
                    self.board._point_to_coord(move[0]))

        # sort by winrate, breaking ties alphabetically
        sortedList = sorted(priorKnowledgeList, key=lambda x: x[0])
        sortedList = sorted(sortedList, key=lambda x: x[3], reverse=True)
        for move in sortedList:
            response += move[0] + ' ' + str(int(
                (round(move[1])))) + ' ' + str(int(round((move[2])))) + ' '
        self.respond(response)
Exemplo n.º 10
0
 def solve(self, board, connection):
     self.startTime = time.process_time()
     self.timedOut = False
     winnable, best = self.negamax(board, board.current_player, 0,
                                   connection)
     if not winnable:
         return GoBoardUtil.int_to_color(
             GoBoardUtil.opponent(board.current_player))
     if not best:
         best = GoBoardUtil.format_point(best)
     else:
         best = GoBoardUtil.format_point(board._point_to_coord(best))
     # Unsure of how to deal with this
     if self.timedOut:
         return 'Unknown'
     return GoBoardUtil.int_to_color(board.current_player) + ' ' + best
Exemplo n.º 11
0
 def solve_cmd(self, args=None):
     colour = self.board.current_player
     can_win, move = self.solve(args)
     if self.timed_out:
         self.respond("unknown")
     else:
         if can_win:
             if move:
                 formatted_move = GoBoardUtil.format_point(
                     self.board._point_to_coord(move))
             else:
                 formatted_move = GoBoardUtil.format_point(move)
             self.respond(
                 GoBoardUtil.int_to_color(colour) + ' ' + formatted_move)
         else:
             self.respond(
                 GoBoardUtil.int_to_color(GoBoardUtil.opponent(colour)))
Exemplo n.º 12
0
    def genmove(self, args):
        #original code from util
        """
        generate a move for the specified color

        Arguments
        ---------
        args[0] : {'b','w'}
            the color to generate a move for
            it gets converted to  Black --> 1 White --> 2
            color : {0,1}
            board_color : {'b','w'}
        """
        try:
            board_color = args[0].lower()
            color = GoBoardUtil.color_to_int(board_color)
            self.debug_msg("Board:\n{}\nko: {}\n".format(
                str(self.board.get_twoD_board()), self.board.ko_constraint))

            solver_color, solver_move = self.solve_genmove("1")
            move = self.go_engine.get_move(self.board, color)
            if move is None:
                self.respond("pass")
                return
            if (solver_color == self.color_convert(color)):
                moves = list(
                    GoBoardUtil.move_to_coord(solver_move, self.board.size))
                solver_move = self.board._coord_to_point(moves[0], moves[1])
                move = solver_move

            elif not self.board.check_legal(move, color):
                move = self.board._point_to_coord(move)
                board_move = GoBoardUtil.format_point(move)
                self.respond("Illegal move: {}".format(board_move))
                raise RuntimeError("Illegal move given by engine")

            # move is legal; play it
            self.board.move(move, color)

            self.debug_msg("Move: {}\nBoard: \n{}\n".format(
                move, str(self.board.get_twoD_board())))
            move = self.board._point_to_coord(move)
            board_move = GoBoardUtil.format_point(move)
            self.respond(board_move)
        except Exception as e:
            self.respond('Error: {}'.format(str(e)))
Exemplo n.º 13
0
 def solve_cmd(self, args):
     try:
         winner, move = self.solve()
         if move:
             move = self.board._point_to_coord(move)
             move = GoBoardUtil.format_point(move)
         self.respond("{} {}".format(winner, move))
     except Exception as e:
         self.respond("Error: {}".format(str(e)))
Exemplo n.º 14
0
 def format_list(board, sims_wins_list):
     for item in sims_wins_list:
         if item[0] == "PASS":
             item[0] = "Pass"
         else:
             row, col = board._point_to_coord(item[0])
             move = GoBoardUtil.format_point((row, col))
             item[0] = move
     sorted_list = sorted(sims_wins_list, key=lambda element: (-element[1], element[0]))
     return sorted_list
Exemplo n.º 15
0
 def safety_cmd(self, args):
     try:
         color = GoBoardUtil.color_to_int(args[0].lower())
         safety_list = self.board.find_safety(color)
         safety_points = []
         for point in safety_list:
             x, y = self.board._point_to_coord(point)
             safety_points.append(GoBoardUtil.format_point((x, y)))
         self.respond(safety_points)
     except Exception as e:
         self.respond('Error: {}'.format(str(e)))
Exemplo n.º 16
0
 def transform(self, T, coord):
     new = self.copy()
     for i in range(1, self.size + 1):
         for j in range(1, self.size + 1):
             # print('in:', i, j)
             y, x = T(i, j)
             # print('T ->', y, x)
             # print()
             new.board[new._coord_to_point(
                 y, x)] = self.board[self._coord_to_point(i, j)]
     move = GoBoardUtil.format_point(T(coord[0], coord[1]))
     return new, move
Exemplo n.º 17
0
def writeMoves(board, moves, count, numSimulations):
    gtp_moves = []
    for i in range(len(moves)):
        if moves[i] != None:
            x, y = board._point_to_coord(moves[i])
            gtp_moves.append((GoBoardUtil.format_point(
                (x, y)), float(count[i]) / float(numSimulations)))
        else:
            gtp_moves.append(('Pass', float(count[i]) / float(numSimulations)))
    sys.stderr.write("win rates: {}\n".format(
        sorted(gtp_moves, key=byPercentage, reverse=True)))
    sys.stderr.flush()
Exemplo n.º 18
0
    def solve_cmd(self, args):

        color, position = self.board.solve()
        # didn't finish
        if color == None:
            self.respond('\nunknown')
        # winner
        elif position != None:
            self.respond('\n' + str(
                GoBoardUtil.int_to_color(color) + ' ' + str(
                    GoBoardUtil.format_point(
                        self.board._point_to_coord(position)))))
        # loser
        else:
            self.respond('\n' + str(GoBoardUtil.int_to_color(color)))
Exemplo n.º 19
0
def get_dict(board):
    p_dict = dict()
    legal_moves = []
    color = board.current_player
    w = []
    m = []
    p = []
    sims = []
    winrate = []
    wins = []
    moves = board.get_empty_points()
    for move in moves:
        if board.check_legal(move, color) and not board.is_eye(move, color):
            legal_moves.append(move)
    legal_moves.append("PASS")
    for move in legal_moves:
        weight = get_the_prob(move, board)
        if move is not "PASS":
            i = board._point_to_coord(move)
            m.append(GoBoardUtil.format_point(i))
            w.append(weight)
        else:
            m.append("Pass")
            w.append(weight)
    length = len(m)
    gamma_sum = sum(w)
    for i in range(length):
        p.append(w[i] / gamma_sum)
    h_prob = max(p)
    for i in range(length):
        sims.append(int(round((p[i] / h_prob) * 10)))
        winrate.append((((p[i] / h_prob) + 1) * 0.5))
        wins.append(int(round(winrate[i] * ((p[i] / h_prob) * 10))))
    results = sort_function(m, sims, winrate, wins)
    results = split_list(results)
    results = sorted(sorted(results, key=lambda x: x[0]),
                     key=lambda x: x[3],
                     reverse=True)
    for result in results:
        if result[0] is not "Pass":
            move = GoBoardUtil.move_to_coord(result[0], board.size)
            m = board._coord_to_point(move[0], move[1])
            p_dict[m] = (int(result[1]), int(result[2]))
        else:
            p_dict["Pass"] = (int(result[1]), int(result[2]))
    return p_dict
Exemplo n.º 20
0
 def solve_cmd(self, args):
     self.move = []
     self.start = time.process_time()
     self.time = False
     win = self.negamaxBoolean(0)
     if self.time:
         self.respond("unknown")
         return False
     elif win:
         self.respond(
             GoBoardUtil.int_to_color(self.board.current_player) + ' ' +
             GoBoardUtil.format_point(
                 self.board._point_to_coord(self.move[0])))
         return True
     else:
         self.respond(
             GoBoardUtil.int_to_color(
                 GoBoardUtil.opponent(self.board.current_player)))
Exemplo n.º 21
0
 def prior_knowledge_cmd(self, args):
     legal_moves = []
     color = self.board.current_player
     w = []
     m = []
     p = []
     sims = []
     winrate = []
     wins = []
     moves = self.board.get_empty_points()
     for move in moves:
         if self.board.check_legal(
                 move, color) and not self.board.is_eye(move, color):
             legal_moves.append(move)
     legal_moves.append("PASS")
     for move in legal_moves:
         weight = self.get_the_prob(move)
         if move is not "PASS":
             i = self.board._point_to_coord(move)
             m.append(GoBoardUtil.format_point(i))
             w.append(weight)
         else:
             m.append("Pass")
             w.append(weight)
     length = len(m)
     gamma_sum = sum(w)
     for i in range(length):
         p.append(w[i] / gamma_sum)
     h_prob = max(p)
     for i in range(length):
         sims.append(int(round((p[i] / h_prob) * 10)))
         winrate.append((((p[i] / h_prob) + 1) * 0.5))
         wins.append(int(round(winrate[i] * ((p[i] / h_prob) * 10))))
     results = self.sort_function(m, sims, winrate, wins)
     results = split_list(results)
     results = sorted(sorted(results, key=lambda x: x[0]),
                      key=lambda x: x[3],
                      reverse=True)
     response = ''
     for i in results:
         response = response + i[0] + ' ' + str(i[1]) + ' ' + str(
             i[2]) + ' '
     self.respond(response)
Exemplo n.º 22
0
 def solve_cmd(self, args):
     """
     Solves the current game state and returns the winner and the winning move.
     
     """
     signal.signal(signal.SIGALRM, self.handler)
     signal.alarm(self.timelimit)
     
     
     try:
         winner, last_move, first_move = GoBoardUtil.solve(self.board)
     
         if self.board.to_play is winner:
             self.respond("{} {}".format(GoBoardUtil.int_to_color(winner), GoBoardUtil.format_point(self.board._point_to_coord(last_move))))
         else:
             self.respond("{}".format(GoBoardUtil.int_to_color(winner)))
             
     except RuntimeError:
         self.respond("unknown")
         warnings.warn("Times Up")
         
     signal.alarm(0) 
Exemplo n.º 23
0
    def policy_moves_cmd(self, args):
        """
            Return list of policy moves for the current_player of the board
        """
        policy_moves = GoBoardUtil.generate_all_policy_moves(
            self.board, self.go_engine.pattern, self.go_engine.selfatari)
        # if len(policy_moves) == 0:
        # self.respond("Pass")
        # else:
        # response = type_of_move + " " + GoBoardUtil.sorted_point_string(policy_moves, self.board.NS)
        # self.respond(response)

        # response = GoBoardUtil.sorted_point_string(policy_moves, self.board.NS)

        if len(policy_moves) == 0:
            response = ['pass', '{:.5f}'.format(1.0)]
        else:
            response = []
            for k, v in policy_moves:
                x, y = GoBoardUtil.point_to_coord(k, self.board.NS)
                response.append(GoBoardUtil.format_point((x, y)))
                response.append('{:.5f}'.format(v))
        self.respond(' '.join(response))
Exemplo n.º 24
0
 def point_to_string(self, point):
     if point == None:
         return 'Pass'
     x, y = GoBoardUtil.point_to_coord(point, self.NS)
     return GoBoardUtil.format_point((x, y))
Exemplo n.º 25
0
    def genmove_cmd(self, args):
        """
        generate a move for the specified color

        Arguments
        ---------
        args[0] : {'b','w'}
            the color to generate a move for
            it gets converted to  Black --> 1 White --> 2
            color : {0,1}
            board_color : {'b','w'}
        """
        try:
            self.notdone = False
            board_color = args[0].lower()
            color = GoBoardUtil.color_to_int(board_color)
            #TODO
            if self.board.get_winner() != None:
                self.respond("resign")
                return
            self.winMoves = []
            self.genCall = True
            if args[0] != None:
                if args[0] == 'b':
                    self.board.to_play = BLACK
                else:
                    self.board.to_play = WHITE
            self.solve_cmd(args)

            self.genCall = False

            if len(self.winMoves) != 0:
                row, col = GoBoardUtil.move_to_coord(self.winMoves[0],
                                                     self.board.size)
                move = self.board._coord_to_point(row, col)
                #self.respond(self.winMoves[0])

            else:
                move = GoBoardUtil.generate_random_move(self.board, color)
                move = self.board._point_to_coord(move)
                move = GoBoardUtil.format_point(move)
                row, col = GoBoardUtil.move_to_coord(move, self.board.size)
                move = self.board._coord_to_point(row, col)
                #self.respond(move)

            if not self.board.check_legal(move, color):
                move = self.board._point_to_coord(move)
                board_move = GoBoardUtil.format_point(move)
                self.respond("Illegal move: {}".format(board_move))
                raise RuntimeError("Illegal move given by engine")

            # move is legal; play it

            self.board.move(move, color)
            self.debug_msg("Move: {}\nBoard: \n{}\n".format(
                move, str(self.board.get_twoD_board())))
            move = self.board._point_to_coord(move)
            board_move = GoBoardUtil.format_point(move)
            self.respond(board_move)
        except Exception as e:
            self.respond('Error: {}'.format(str(e)))
Exemplo n.º 26
0
            the color to generate a move for
            it gets converted to  Black --> 1 White --> 2
            color : {0,1}
            board_color : {'b','w'}
        """
        #try:
        board_color = args[0].lower()
        color = GoBoardUtil.color_to_int(board_color)
        self.debug_msg("Board:\n{}\nko: {}\n".format(str(self.board.get_twoD_board()),
                                                      self.board.ko_constraint))
        move = self.go_engine.get_move(self.board, color)
        #move = GoBoardUtil.generate_move_with_filter(self.board, True, True)
        if move is None:
            self.respond("pass")
            return

        if not self.board.check_legal(move, color):
            move = self.board._point_to_coord(move)
            board_move = GoBoardUtil.format_point(move)
            self.respond("Illegal move: {}".format(board_move))
            raise RuntimeError("Illegal move given by engine")

        # move is legal; play it
        self.board.move(move, color)
        self.debug_msg("Move: {}\nBoard: \n{}\n".format(move, str(self.board.get_twoD_board())))
        move = self.board._point_to_coord(move)
        board_move = GoBoardUtil.format_point(move)
        self.respond(board_move)
        #except Exception as e:
        #    self.respond('Error: {}'.format(str(e)))