def prcapturePawn(mv, mvs): assert tag(mv) in ["x", "x/", "xep"] assert isPawn(manAt(osq(mv))) # simplest form - fxln f = "abcdefgh"[col(osq(mv))] ln = square.pr(nsq(mv)) if tag(mv) == "x/": q = man.pr(pmn(mv)) s = "%sx%s=%s" % (f, ln, q) else: s = "%sx%s" % (f, ln) found = algebraic.find(s, mvs) if len(found) == 1: return s # disambiguate by both - rfxln rf = square.pr(osq(mv)) if tag(mv) == "x/": s = "%sx%s=%s" % (rf, ln, q) else: s = "%sx%s" % (rf, ln) found = algebraic.find(s, mvs) if len(found) == 1: return s # if move is legal there should be no other cases assert False
def prdashPiece(mv, mvs): assert tag(mv) == "-" assert isPiece(manAt(osq(mv))) # simplest form - pln p = man.pr(manAt(osq(mv))) ln = square.pr(nsq(mv)) s = "%s%s" % (p, ln) found = algebraic.find(s, mvs) if len(found) == 1: return s # disabiguate by file - pfln f = "abcdefgh"[col(osq(mv))] s = "%s%s%s" % (p, f, ln) found = algebraic.find(s, mvs) if (len(found)) == 1: return s # disambiguate by rank - prln r = "12345678"[row(osq(mv))] s = "%s%s%s" % (p, r, ln) found = algebraic.find(s, mvs) if (len(found)) == 1: return s # disambiguate by both -rare but possible - prfln s = "%s%s%s%s" % (p, r, f, ln) if (len(found)) == 1: return s # there should be no other cases given that move is legal assert False
def prcapturePiece(mv, mvs): assert tag(mv) in ["x", "x/", "xep"] assert isPiece(manAt(osq(mv))) # simplest form - pxln p = man.pr(manAt(osq(mv))) ln = square.pr(nsq(mv)) s = "%sx%s" % (p, ln) found = algebraic.find(s, mvs) if len(found) == 1: return s # disambiguate by file - pfxln f = "abcdefgh"[col(osq(mv))] s = "%s%sx%s" % (p, f, ln) found = algebraic.find(s, mvs) if len(found) == 1: return s # disambiguate by rank - prxln r = "12345678"[row(osq(mv))] s = "%s%sx%s" % (p, r, ln) found = algebraic.find(s, mvs) if len(found) == 1: return s # disambiguate by both - prfxln s = "%s%s%sx%s" % (p, r, f, ln) found = algebraic.find(s, mvs) if len(found) == 1: return s # if move is legal there should be no other cases assert False
def prdashPawn(mv, mvs): assert tag(mv) == "-" or tag(mv) == "-/" assert isPawn(manAt(osq(mv))) # simplest form - ln ln = square.pr(nsq(mv)) if tag(mv) == "-/": q = man.pr(pmn(mv)) s = "%s=%s" % (ln, q) else: s = ln found = algebraic.find(s, mvs) if len(found) == 1: return s
if board.blackAllowOO: av = av + "k" if board.blackAllowOOO: av = av + "q" if av=="": av = "-" def prEpTargetSq(): if len(board.history)=0: return "-" mv = board.lastmove() if move.tag(mv)=="-" and board.manAt(move.nsq(mv))==man.pawn: if move.color(mv)=='white': if square.rank(move.osq(mv))==2 and square.rank(move.nsq(mv))==4: return square.pr(square.fwd(move.osq(mv))) else: assert move.color(mv)=='black' if square.rank(move.osq(mv))==7 and square.rank(move.nsq(mv))==5: return square.pr(square.bak(move.osq(mv))) else: return "-" def prHalfMoveClock(): #number of half moves since the last pawn advance or capturing move return "0" # TBD def prFullMoveNumber(): return str(len(history)/2 + 1) # converting FEN to board position
def prcapture(mv): manthatmoves = man.pr(board.theBoard[osq(mv)]) fromsquare = square.pr(osq(mv)) tosquare = square.pr(nsq(mv)) return "%s%sx%s" % (manthatmoves, fromsquare, tosquare)
def XOR(h, mn, sq): if mn == 0: return h else: return h ^ ran1[sym[mn] + square.pr(sq)]
def genTbl(tbl): for sq in xrange(0, 64): for m in sym.keys(): tbl[sym[m] + square.pr(sq)] = random.randint(1, 2**N)