def noKingCapture(mvs): for mv in mvs: if tag(mv) in ["x","x/"]: if isKing(move.cmn(mv)): print "error (king capture): ",mv return False if isKing(manAt(move.nsq(mv))): print "error (king at nsq): ",mv return False return True
def moves(d): mvlist = legal.moves() if d > 0: # sort captures to the front of the list mvlist.sort(cmp) return mvlist elif d > depth2: # after depth limit reach, we only look at a captures return filter(lambda mv: move.tag(mv) in ["x", "x/", "xep"], mvlist) else: return []
'P': man.pawn } atbl = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8} ntbl = {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8} #------------------------------------------------------------------------------ # Each pattern corresponds to a function we can use to filter the moves. # The function is given as a lambda expression that operates on # a move tuple mv evaluating to truth if that tuple matches the move string s. # See header comment in move.py for the format of the move tuples #------------------------------------------------------------------------------ fm = { "ln": lambda s, mv: tag(mv) == "-" and nsq(mv) == rd(s) and isPawn(manAt(osq(mv)) ), "pln": lambda s, mv: tag(mv) == "-" and nsq(mv) == rd(s[1:3]) and isKind( manAt(osq(mv)), kind[s[0]]), "pxln": lambda s, mv: tag(mv) == "x" and nsq(mv) == rd(s[2:4]) and isKind( manAt(osq(mv)), kind[s[0]]), "lxln": lambda s, mv: tag(mv) in ["x", "xep"] and nsq(mv) == rd(s[2:4]) and file( osq(mv)) == atbl[s[0]] and isPawn(manAt(osq(mv))), "lnxln": lambda s, mv: tag(mv) in ["x", "xep"] and nsq(mv) == rd(s[3:5]) and osq(mv) == rd(s[0:2]), "O-O": lambda s, mv: tag(mv) == "OO",
def isCapture(mv): return move.tag(mv) in ["x", "x/", "xep"]
def prcapture(mv, mvs): assert tag(mv) in ["x", "x/", "xep"] if isPawn(manAt(osq(mv))): return prcapturePawn(mv, mvs) else: return prcapturePiece(mv, mvs)
def prdash(mv, mvs): assert tag(mv) == "-" or tag(mv) == "-/" if isPawn(manAt(osq(mv))): return prdashPawn(mv, mvs) else: return prdashPiece(mv, mvs)