Example #1
0
def legals():
    mvs = legal.moves()
    for mv in mvs:
        if board.whiteToMove():
            print "%s %s" % (move.num(mv), san.pr(mv, mvs))
        else:
            print "%s ...%s" % (move.num(mv), san.pr(mv, mvs))
Example #2
0
def best(mvlist):
    global t0
    if board.whiteToMove():
        alpha = -inf
        for mv in mvlist:
            move.make(mv)
            t0 = time.clock()
            #score = max(score,itterative_deepening())
            #score = itterative_deepening()
            score = MDTF(0, depth + 1)
            if score > alpha:
                bestmv, alpha = mv, score
            move.umake(mv)
            print score, san.pr(mv, mvlist)
        return bestmv, alpha, 0, 0  # the 0,0 are just dummy placeholder values
    else:
        assert board.blackToMove()
        beta = inf
        for mv in mvlist:
            move.make(mv)
            t0 = time.clock()
            #score = min(score,itterative_deepening())
            #score = itterative_deepening()
            score = MDTF(0, depth + 1)
            if score < beta:
                bestmv, beta = mv, score
            move.umake(mv)
            print score, san.pr(mv, mvlist)
        return bestmv, beta, 0, 0  # the 0,0 are just a dummy placeholder values
Example #3
0
def mybest_static(silent=False):
    mvlist = legal.moves()
    if len(mvlist) > 0:
        if board.whiteToMove():
            mv, score = best.forWhite(mvlist)
        else:
            mv, score = best.forBlack(mvlist)
        if not silent:
            if move.color(mv) == 'white':
                msg = "After %s %s [%s]" % (move.num(mv), san.pr(
                    mv, mvlist), score)
            else:
                msg = "After %s ...%s [%s]" % (move.num(mv), san.pr(
                    mv, mvlist), score)
        move.make(mv)
        if not silent:
            print msg
            auto()
        if verbose:
            board.dump()
            assert board.valid()  # aggressive validation
        return True
    else:
        print "no moves"
        return False
Example #4
0
def find(s):
    mvs = legal.moves()
    found = algebraic.find(s, mvs)
    if len(found) == 0:
        print " " * 13 + "no such move"
    if len(found) == 1:
        print " " * 13 + "found unique", san.pr(found[0], mvs)
    elif len(found) > 1:
        print " " * 13 + "ambiguous, choices are:"
        for mv in found:
            print " " * 17, san.pr(mv, mvs)
    return found
Example #5
0
def prline(mvs):
    s = ""
    c = 0
    for mv in mvs:
        legals = legal.moves()
        if move.color(mv) == 'white':
            s = s + ("%s %s" % (num(mv), san.pr(mv, legals)))
        else:
            if c == 0:
                s = "%s ...%s " % (num(mv), san.pr(mv, legals))
            else:
                s = s + (" %s " % san.pr(mv, legals))
        move.make(mv)
        c = c + 1
    while c > 0:
        move.umake(board.lastMove())
        c = c - 1
    return s
Example #6
0
def rand(silent=False):
    mvlist = legal.moves()
    if len(mvlist) > 0:
        #n = random.randint(0,len(mvlist)-1)
        mv = random.choice(mvlist)
        if not silent:
            if move.color(mv) == 'white':
                msg = "After %s %s" % (move.num(mv), san.pr(mv, mvlist))
            else:
                msg = "After %s ...%s" % (move.num(mv), san.pr(mv, mvlist))
        move.make(mv)
        if not silent:
            print msg
            auto()
        if verbose:
            board.dump()
            assert board.valid()  # aggressive validation
        return True
    else:
        print "no moves"
        return False
Example #7
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()
Example #8
0
def mybest():
    mvlist = legal.moves()
    if len(mvlist) > 0:
        #mv,score,cnt,sec = alphabeta.best(mvlist)
        mv, score, cnt, sec = searchfunction(mvlist)
        if not silent:
            if move.color(mv) == 'white':
                fmt = "After %s %s [%s] searched %s positions in %s sec"
            else:
                fmt = "After %s ...%s [%s] searched %s positions in %s sec"
            print fmt % (move.num(mv), san.pr(mv, mvlist), score, cnt, sec)
            print "ttHits=%s   |WTT|=%s  |BTT|=%s" % (
                alphabeta.ttHits, len(alphabeta.WTT), len(alphabeta.BTT))
        move.make(mv)
        auto()
        if verbose:
            board.dump()
            assert board.valid()  # aggressive validation
        return True
    else:
        print "no moves"
        return False
Example #9
0
def reply():
    global playing
    assert playing
    mvs = legal.moves()
    if len(mvs) > 0:
        mv = random.choice(mvs)
        s = san.pr(mv, mvs)  # use a different notation
        put_move(s)
        move.make(mv)
    else:
        assert len(mvs) == 0
        playing = False
        if board.whiteToMove():
            if blackAttacks(board.whiteKingAt):
                put_result("1-0", "white checkmated")
            else:
                put_result("1/2-1/2", "stalemate")
        else:
            assert board.blackToMove()
            if whiteAttacks(board.blackKingAt):
                put_result("0-1", "black checkmated")
            else:
                put_result("1/2-1/2", "stalemate")