Beispiel #1
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:
            pointString = 'Pass'
        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()
Beispiel #2
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
Beispiel #3
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()
 def distance_to_line(board, p):
     halfSize = (board.size + 1) / 2
     row, col = point_to_coord(p, board.size)
     lineRow = board.size + 1 - row if row > halfSize else row
     lineCol = board.size + 1 - col if col > halfSize else col
     return min(lineRow, lineCol)
Beispiel #5
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))
Beispiel #6
0
 def strPoint(self, point):
     return format_point(point_to_coord(point, self.board.size))
Beispiel #7
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))