Beispiel #1
0
def do_nn():
    best, node = search.UCT_search(board, NODES, net=net, C=3.4)
Beispiel #2
0
def main():

    send("A0 Lite")
    board = chess.Board()
    nn = None
    cuda = False
    while True:
        line = sys.stdin.readline()
        line = line.rstrip()
        log("<{}".format(line))
        tokens = line.split()
        if len(tokens) == 0:
            continue

        if tokens[0] == "uci":
            send('id name A0 Lite')
            send('id author Dietrich Kappe')
            send('option name cuda type check default false')
            send('uciok')
        elif tokens[0] == "setoption":
            if tokens[2] == "cuda":
                cuda = tokens[4] == 'true'
        elif tokens[0] == "quit":
            exit(0)
        elif tokens[0] == "isready":
            if nn == None:
                nn = load_network()
            send("readyok")
        elif tokens[0] == "ucinewgame":
            board = chess.Board()

        elif tokens[0] == 'position':
            board = process_position(tokens)

        elif tokens[0] == 'go':
            my_nodes = NODES
            my_time = None
            if (len(tokens) == 2) and (tokens[1] == 'infinite'):
                my_nodes = sys.maxsize
            if (len(tokens) == 3) and (tokens[1] == 'nodes'):
                my_nodes = int(tokens[2])
            if (len(tokens) == 3) and (tokens[1] == 'movetime'):
                my_time = int(tokens[2]) / 1000.0
                if my_time < MINTIME:
                    my_time = MINTIME
            if (len(tokens) == 9) and (tokens[1] == 'wtime'):
                wtime = int(tokens[2])
                btime = int(tokens[4])
                winc = int(tokens[6])
                binc = int(tokens[8])
                if (wtime > 5 * winc):
                    wtime += 5 * winc
                else:
                    wtime += winc
                if (btime > 5 * binc):
                    btime += 5 * binc
                else:
                    btime += binc
                if board.turn:
                    my_time = wtime / (TIMEDIV * 1000.0)
                else:
                    my_time = btime / (TIMEDIV * 1000.0)
                if my_time < MINTIME:
                    my_time = MINTIME
            if nn == None:
                nn = load_network(cuda)

            if my_time != None:
                best, score = search.UCT_search(board,
                                                sys.maxsize,
                                                net=nn,
                                                C=C,
                                                max_time=my_time,
                                                send=send)
            else:
                best, score = search.UCT_search(board,
                                                my_nodes,
                                                net=nn,
                                                C=C,
                                                send=send)
            send("bestmove {}".format(best))
Beispiel #3
0
SELFPLAY = True

board = LeelaBoard()
while True:
    if not SELFPLAY:
        print(board.unicode())
        print("Enter move: ", end='')
        sys.stdout.flush()
        line = sys.stdin.readline()
        line = line.rstrip()
        board.push_uci(line)
    print(board.unicode())
    print("thinking...")
    start = time.time()
    best, node = search.UCT_search(board, nodes, net=nn, C=3.4)
    elapsed = time.time() - start
    print("best: ", best)
    print("Time: {:.3f} nps".format(nodes / elapsed))
    print(nn.evaluate.cache_info())
    board.push_uci(best)
    if board.pc_board.is_game_over() or board.is_draw():
        result = board.pc_board.result(claim_draw=True)
        print("Game over... result is {}".format(result))
        print(board.unicode())
        print()
        pgn_game = chess.pgn.Game.from_board(board.pc_board)
        pgn_game.headers['Result'] = result
        print(pgn_game)
        break