def str(mv): if promotion(mv) == ivory_piece.KING: return 'O-O-O' if square.file(tosq(mv)) == 'c' else 'O-O' out = [] if piece(mv) == ivory_piece.PAWN: if is_capture(mv): out.append(square.file(frsq(mv))) out.append('x') else: out.append(ivory_piece.str(piece(mv)).upper()) if is_show_file(mv): out.append(square.file(frsq(mv))) if is_show_rank(mv): out.append(square.rank(frsq(mv))) if is_capture(mv): out.append('x') out.append(square.str(tosq(mv))) if promotion(mv): print square.str(frsq(mv)), square.str(tosq(mv)) out.append('=') out.append(ivory_piece.str(promotion(mv)).upper()) if is_check(mv): out.append('+') if is_mate(mv): out.append('#') return ''.join(out)
def _disambiguate_moves(self, moves): files = {} ranks = {} unamb = list(moves) for mv in moves: if move.promotion(mv): continue ps = (move.piece(mv), move.tosq(mv)) files.setdefault(ps, []) ranks.setdefault(ps, []) files[ps].append(square.file(move.frsq(mv))) ranks[ps].append(square.rank(move.frsq(mv))) opp_cl = not self.color for i, mv in enumerate(moves): ps = (move.piece(mv), move.tosq(mv)) if files[ps].count(square.file(move.frsq(mv))) > 1: unamb[i] = moves[i].set_show_rank() if ranks[ps].count(square.rank(move.frsq(mv))) > 1: unamb[i] = moves[i].set_show_file() return unamb
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) ATTACKS[piece.KING][sq] = _king_moves(sq) ATTACKS[piece.KNIGHT][sq] = _knight_moves(sq)
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)