def _clear(self): self.piece_bbs = {} for pc in piece.all(): self.piece_bbs[pc] = 0L self.color_bbs = {} self.color_bbs[0] = 0L self.color_bbs[1] = 0L self.squares = {} for sq in square.all(): self.squares[sq] = 0L self.castle = castle.parse('KQkq') self.enp = square.sq() self.halfmove_clock = 0 self.move_num = 1
with open('attacks.pickle') as f: ATTACKS, MASK, OCC_ATTACKS = pickle.load(f) else: ATTACKS = {} ATTACKS[piece.BISHOP] = {} ATTACKS[piece.ROOK] = {} ATTACKS[piece.KING] = {} ATTACKS[piece.KNIGHT] = {} MASK = {} MASK[piece.BISHOP] = {} MASK[piece.ROOK] = {} OCC_ATTACKS = {} OCC_ATTACKS[piece.BISHOP] = {} OCC_ATTACKS[piece.ROOK] = {} for sq in square.all(): rank = square.BIT_RANKS[square.rank(sq)] file = square.BIT_FILES[square.file(sq)] a1h8 = square.BIT_A1H8[square.a1h8(sq)] a8h1 = square.BIT_A8H1[square.a8h1(sq)] ATTACKS[piece.BISHOP][sq] = a1h8 | a8h1 MASK[piece.BISHOP][sq] = ( (a1h8 & ~bitboard.msb(a1h8) & ~bitboard.lsb(a1h8)) | (a8h1 & ~bitboard.msb(a8h1) & ~bitboard.lsb(a8h1))) ATTACKS[piece.ROOK][sq] = rank | file MASK[piece.ROOK][sq] = ( (rank & ~bitboard.msb(rank) & ~bitboard.lsb(rank)) | (file & ~bitboard.msb(file) & ~bitboard.lsb(file))) OCC_ATTACKS[piece.BISHOP][sq] = _occ_attack_table(sq, piece.BISHOP) OCC_ATTACKS[piece.ROOK][sq] = _occ_attack_table(sq, piece.ROOK)
self.num_captures += 1 self.num_en_passant += 1 elif prm == piece.KING: self.num_castles += 1 else: self.num_promotions += 1 if movegen.king_attacked(self, self.color): self.num_checks += 1 if self._game_over(): self.num_mates += 1 self.unmake_move() return nodes # NOTE(vish): insert constants into locals for sq in square.all(): locals()[square.str(sq)] = sq for pc in piece.all(): locals()[piece.str(pc)] = pc #fen = 'r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1' fen = '8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1' p1 = Position(fen) print piece.str(p1.squares[square.sq('a8')]) import time import prettytable pt = prettytable.PrettyTable() pt.field_names = ['Depth', 'Nodes', 'Captures', 'E.p.', 'Castles', 'Promotions', 'Checks', 'Mates', 'Time'] pt.align = 'l'