Пример #1
0
def attacked(pos, sq, opp_cl=None):
    if opp_cl is None:
        opp_cl = not pos.color
    opp_occ = pos.color_bbs[opp_cl]
    if ATTACKS[piece.KING][sq] & opp_occ & pos.piece_bbs[piece.KING]:
        return True
    if ATTACKS[piece.KNIGHT][sq] & opp_occ & pos.piece_bbs[piece.KNIGHT]:
        return True
    for pc in (piece.ROOK, piece.BISHOP):
        occ = pos.occupied & MASK[pc][sq]
        pcs_or_qs = pos.piece_bbs[piece.QUEEN] | pos.piece_bbs[pc]
        if OCC_ATTACKS[pc][sq][occ] & opp_occ & pcs_or_qs:
            return True
    if opp_cl:
        pawn_attacks = square.sw(sq) | square.se(sq)
    else:
        pawn_attacks = square.nw(sq) | square.ne(sq)
    if pawn_attacks & opp_occ & pos.piece_bbs[piece.PAWN]:
        return True
    return False
Пример #2
0
def attacked(pos, sq, opp_cl=None):
    if opp_cl is None:
        opp_cl = not pos.color
    opp_occ = pos.color_bbs[opp_cl]
    if ATTACKS[piece.KING][sq] & opp_occ & pos.piece_bbs[piece.KING]:
        return True
    if ATTACKS[piece.KNIGHT][sq] & opp_occ & pos.piece_bbs[piece.KNIGHT]:
        return True
    for pc in (piece.ROOK, piece.BISHOP):
        occ = pos.occupied & MASK[pc][sq]
        pcs_or_qs = pos.piece_bbs[piece.QUEEN] | pos.piece_bbs[pc]
        if OCC_ATTACKS[pc][sq][occ] & opp_occ & pcs_or_qs:
            return True
    if opp_cl:
        pawn_attacks = square.sw(sq) | square.se(sq)
    else:
        pawn_attacks = square.nw(sq) | square.ne(sq)
    if pawn_attacks & opp_occ & pos.piece_bbs[piece.PAWN]:
        return True
    return False
Пример #3
0
def get_pawn_moves(pos, moves):
    pawns = pos.piece_bbs[piece.PAWN] & pos.color_bbs[pos.color]
    not_occ = ~(pos.occupied)
    enp = pos.enp
    opp_occ = pos.color_bbs[not pos.color] | enp
    if pos.color:
        # single pawn moves
        regular = pawns & ~square.BIT_RANKS[6]
        promoting = pawns & square.BIT_RANKS[6]
        single = bitboard.n(pawns) & not_occ
        for sq in bitboard.squares(single):
            moves.append(move.mv(piece.PAWN, square.s(sq), sq))
        for sq in bitboard.squares(bitboard.n(promoting) & not_occ):
            _make_promotions(moves, sq, square.s(sq))

        # east attacks
        for sq in bitboard.squares(bitboard.ne(regular) & opp_occ):
            prm = piece.PAWN if sq == enp else piece.NONE
            moves.append(move.mv(piece.PAWN, square.sw(sq), sq, prm))
        for sq in bitboard.squares(bitboard.ne(promoting) & opp_occ):
            _make_promotions(moves, sq, square.sw(sq))

        # west attacks
        for sq in bitboard.squares(bitboard.nw(regular) & opp_occ):
            prm = piece.PAWN if sq == enp else piece.NONE
            moves.append(move.mv(piece.PAWN, square.se(sq), sq, prm))
        for sq in bitboard.squares(bitboard.nw(promoting) & opp_occ):
            _make_promotions(moves, sq, square.se(sq))

        # double pawn moves
        doubles = bitboard.n(single & square.BIT_RANKS[2])
        for sq in bitboard.squares(doubles & not_occ):
            moves.append(move.mv(piece.PAWN, square.ss(sq), sq))

    else:
        # single pawn moves
        regular = pawns & ~square.BIT_RANKS[1]
        promoting = pawns & square.BIT_RANKS[1]
        single = bitboard.s(pawns) & not_occ
        for sq in bitboard.squares(single):
            moves.append(move.mv(piece.PAWN, square.n(sq), sq))
        for sq in bitboard.squares(bitboard.s(promoting) & not_occ):
            _make_promotions(moves, sq, square.n(sq))

        # east attacks
        for sq in bitboard.squares(bitboard.se(regular) & opp_occ):
            prm = piece.PAWN if sq == enp else piece.NONE
            moves.append(move.mv(piece.PAWN, square.nw(sq), sq, prm))
        for sq in bitboard.squares(bitboard.se(promoting) & opp_occ):
            _make_promotions(moves, sq, square.nw(sq))

        # west attacks
        for sq in bitboard.squares(bitboard.sw(regular) & opp_occ):
            prm = piece.PAWN if sq == enp else piece.NONE
            moves.append(move.mv(piece.PAWN, square.ne(sq), sq, prm))
        for sq in bitboard.squares(bitboard.sw(promoting) & opp_occ):
            _make_promotions(moves, sq, square.ne(sq))

        # double pawn moves
        doubles = bitboard.s(single & square.BIT_RANKS[5])
        for sq in bitboard.squares(doubles & not_occ):
            moves.append(move.mv(piece.PAWN, square.nn(sq), sq))
Пример #4
0
def _king_moves(sq):
    return (square.n(sq) | square.s(sq) | square.e(sq) | square.w(sq)
            | square.ne(sq) | square.se(sq) | square.sw(sq) | square.nw(sq))
Пример #5
0
def get_pawn_moves(pos, moves):
    pawns = pos.piece_bbs[piece.PAWN] & pos.color_bbs[pos.color]
    not_occ = ~(pos.occupied)
    enp = pos.enp
    opp_occ = pos.color_bbs[not pos.color] | enp
    if pos.color:
        # single pawn moves
        regular = pawns & ~square.BIT_RANKS[6]
        promoting = pawns & square.BIT_RANKS[6]
        single = bitboard.n(pawns) & not_occ
        for sq in bitboard.squares(single):
            moves.append(move.mv(piece.PAWN, square.s(sq), sq))
        for sq in bitboard.squares(bitboard.n(promoting) & not_occ):
            _make_promotions(moves, sq, square.s(sq))

        # east attacks
        for sq in bitboard.squares(bitboard.ne(regular) & opp_occ):
            prm = piece.PAWN if sq == enp else piece.NONE
            moves.append(move.mv(piece.PAWN, square.sw(sq), sq, prm))
        for sq in bitboard.squares(bitboard.ne(promoting) & opp_occ):
            _make_promotions(moves, sq, square.sw(sq))

        # west attacks
        for sq in bitboard.squares(bitboard.nw(regular) & opp_occ):
            prm = piece.PAWN if sq == enp else piece.NONE
            moves.append(move.mv(piece.PAWN, square.se(sq), sq, prm))
        for sq in bitboard.squares(bitboard.nw(promoting) & opp_occ):
            _make_promotions(moves, sq, square.se(sq))

        # double pawn moves
        doubles = bitboard.n(single & square.BIT_RANKS[2])
        for sq in bitboard.squares(doubles & not_occ):
            moves.append(move.mv(piece.PAWN, square.ss(sq), sq))

    else:
        # single pawn moves
        regular = pawns & ~square.BIT_RANKS[1]
        promoting = pawns & square.BIT_RANKS[1]
        single = bitboard.s(pawns) & not_occ
        for sq in bitboard.squares(single):
            moves.append(move.mv(piece.PAWN, square.n(sq), sq))
        for sq in bitboard.squares(bitboard.s(promoting) & not_occ):
            _make_promotions(moves, sq, square.n(sq))

        # east attacks
        for sq in bitboard.squares(bitboard.se(regular) & opp_occ):
            prm = piece.PAWN if sq == enp else piece.NONE
            moves.append(move.mv(piece.PAWN, square.nw(sq), sq, prm))
        for sq in bitboard.squares(bitboard.se(promoting) & opp_occ):
            _make_promotions(moves, sq, square.nw(sq))

        # west attacks
        for sq in bitboard.squares(bitboard.sw(regular) & opp_occ):
            prm = piece.PAWN if sq == enp else piece.NONE
            moves.append(move.mv(piece.PAWN, square.ne(sq), sq, prm))
        for sq in bitboard.squares(bitboard.sw(promoting) & opp_occ):
            _make_promotions(moves, sq, square.ne(sq))

        # double pawn moves
        doubles = bitboard.s(single & square.BIT_RANKS[5])
        for sq in bitboard.squares(doubles & not_occ):
            moves.append(move.mv(piece.PAWN, square.nn(sq), sq))
Пример #6
0
def _king_moves(sq):
    return (square.n(sq) | square.s(sq) | square.e(sq) | square.w(sq) |
            square.ne(sq) | square.se(sq) | square.sw(sq) | square.nw(sq))