Esempio n. 1
0
def opponent_move(s):
    assert engineColor in ['white', 'black', None]
    assert board.colorToMove() != engineColor
    mvs = legal.moves()
    found = algebraic.find(s, mvs)
    if len(found) == 0:
        put_illegalmove(s, "not found")
    elif len(found) == 1:
        assert board.colorToMove() != engineColor
        assert move.color(found[0]) != engineColor
        move.make(found[0])
        if board.colorToMove() == engineColor:
            assert board.colorToMove() == engineColor
            reply()
    elif len(found) > 1:
        put_illegalmove(s, "ambiguous")
Esempio n. 2
0
def bmobility(mvs):
    if board.colorToMove() == 'black':
        return len(mvs)
    else:
        move.make((len(board.history), 'null'))
        cnt = len(trial.trialmoves())
        move.umake(board.lastMove())
        return -cnt
Esempio n. 3
0
def go():
    #Leave force mode and set the engine to play the color that is on
    # move. Associate the engine's clock with the color that is
    # on move, the opponent's clock with the color that is not on move.
    # Start the engine's clock. Start thinking and eventually make a move.
    global engineColor
    assert engineColor == None
    engineColor = board.colorToMove()
    assert engineColor in ['white', 'black']
    time.sleep(1)
    reply()
Esempio n. 4
0
def usermove(cmd):
    # By default, moves are sent to the engine without a command name;
    # the notation is just sent as a line by itself. Beginning in protocol
    # version 2, you can use the feature command to cause the command
    # name "usermove" to be sent before the move. Example: "usermove
    # e2e4".
    assert engineColor in ['black', 'white', None]
    if board.colorToMove() == engineColor:
        put_error(cmd, "out of turn move ignored")
    else:
        mvstring = cmd.split(" ")[1]
        opponent_move(mvstring)
Esempio n. 5
0
def reply():
    #if not board.colorToMove()==engineColor:
    #    return None
    assert board.colorToMove() == engineColor
    mvs = legal.moves()
    #time.sleep(0.1)
    if len(mvs) > 0:
        if len(board.history) > 300:
            resign()
        else:
            mv, score, cnt, sec = alphabeta.best(mvs)
            s = san.pr(mv, mvs)
            put_move(s)
            move.make(mv)
    else:
        assert len(mvs) == 0
        report_result()