Пример #1
0
    def legalMoves(self,board):
        moves = GoBoardUtil.generate_legal_moves_gomoku(board)
        gtp_moves = []
        for move in moves:
            coords = point_to_coord(move, board.size)
            gtp_moves.append(format_point(coords))

        return gtp_moves
 def legal_moves_for_toPlay_cmd(self, args):
     try:
         color = self.board.current_player
         moves = GoBoardUtil.generate_legal_moves(self.board, color)
         gtp_moves = []
         for move in moves:
             coords = point_to_coord(move, self.board.size)
             gtp_moves.append(format_point(coords))
         sorted_moves = ' '.join(sorted(gtp_moves))
         self.respond(sorted_moves)
     except Exception as e:
         self.respond('Error: {}'.format(str(e)))
Пример #3
0
def writeMoves(board, moves, count, numSimulations):
    """
    Write simulation results for each move.
    """
    gtp_moves = []
    for i in range(len(moves)):
        if moves[i] != None:
            x, y = point_to_coord(moves[i], board.size)
            gtp_moves.append((format_point((x, y)),
                              float(count[i])/float(numSimulations)))
    sys.stderr.write("win rates: {}\n"
                     .format(sorted(gtp_moves, key = byPercentage,
                                    reverse = True)))
Пример #4
0
def writeMoves(board, moves, stats):
    gtp_moves = []
    for i in range(len(moves)):
        if moves[i] != None:
            x, y = point_to_coord(moves[i], board.size)
            pointString = format_point((x, y))
        else:
            continue
        if stats[i][1] != 0:
            gtp_moves.append((pointString, stats[i][0] / stats[i][1],
                              stats[i][0], stats[i][1]))
        else:
            gtp_moves.append((pointString, 0.0, stats[i][0], stats[i][1]))
    sys.stderr.write("Statistics: {}\n".format(
        sorted(gtp_moves, key=byPulls, reverse=True)))
    sys.stderr.flush()
Пример #5
0
def solve_alphabeta(board: SimpleGoBoard, color: int, board_is_evaluated=False):
    result, winner = board.check_game_end_gomoku()
    if result: 
        if winner == color:
            return 10*score.FIVE, None
        else: 
            return -10*score.FIVE, None
    # print('ok')
    alpha, beta = -10*score.FIVE, 10*score.FIVE
    if not board_is_evaluated:
        evaluate_board(board)
    moves = gen_possible_moves(board, color)
    print(list(map(lambda t: (t[0], gtp_connection.format_point(
        gtp_connection.point_to_coord(t[0], board.size)), t[1], t[2]), moves)))
    if len(moves) == 0: 
        return 0, None
    if (gtp_connection.total_steps == 0 or gtp_connection.total_steps == 1) and board.board[36] == EMPTY: 
        return 1, 36

    # best_move = None
    global best_move
    best_move = PASS
    for m in moves:
        move = m[0]

        # move_coord = gtp_connection.point_to_coord(move, board.size)
        # move_as_string = gtp_connection.format_point(move_coord)
        
        board.board[move] = color
        update_board(board, move)
        result = -alphabeta_search(board, move, GoBoardUtil.opponent(color), 40, -beta, -alpha)
        # print("trying move:", move_as_string, "score:", result)

        board.board[move] = EMPTY
        update_board(board, move)
        if result > alpha: 
            alpha = result
            best_move = move
        if result >= beta: 
            return beta, move
    return alpha, best_move
Пример #6
0
def print_moves(moves,boardsize): 
    for m in moves: 
        print('(', gtp_connection.format_point(gtp_connection.point_to_coord(m[0],boardsize)),m[1], m[2], end=' ), ')
    print()
Пример #7
0
 def point_to_string(self, board_size, point):
     if point == None:
         return 'Pass'
     x, y = point_to_coord(point, board_size)
     return format_point((x, y))
Пример #8
0
 def strPoint(self, point):
     return format_point(point_to_coord(point, self.board.size))
Пример #9
0
 def __str__(self):
     return "{} {}/{}".format(
         format_point(point_to_coord(self.move, self.boardsize)), self.wins,
         self.sims)
def sorted_point_string(points, boardsize):
    result = []
    for point in points:
        x, y = point_to_coord(point, boardsize)
        result.append(format_point((x, y)))
    return ' '.join(sorted(result))