Exemple #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))
Exemple #2
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
Exemple #3
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
Exemple #4
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
Exemple #5
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
Exemple #6
0
# pretty square encoding
def prettysquareencoding():
    for r in xrange(7,-1,-1):
        for f in xrange(0,8):
            i = r*8+f
            print pr(i),
            if hfile(i):
                print

print "----- Pretty printing a game score ---------"
# about the best we can do without knowing all legal moves

print "game=",game
for i in xrange(0,len(game),2):
    print "%s. %-8s" % (move.num(game[i]),move.pr(game[i])),
    if i+1<len(game):
       print "   ",move.pr(game[i+1])
    else:
       print

print "----- Test of attack logic -------"
import attack
for i in xrange(0,len(game)):
   move.make(game[i])
   board.dump()

def displaywhiteattacks():
    for r in xrange(7,-1,-1):
        print "\nMap of squares under attack by white"
        for f in xrange(0,8):
Exemple #7
0
def pr(tmoves):
    for m in tmoves:
        if move.hmc(m) % 2 == 1:
            print "%s. ... %s" % (move.num(m), move.pr(m))
        else:
            print "%s. %s" % (move.num(m), move.pr(m))