當前位置: 首頁>>代碼示例>>Python>>正文


Python chess.PAWN屬性代碼示例

本文整理匯總了Python中chess.PAWN屬性的典型用法代碼示例。如果您正苦於以下問題:Python chess.PAWN屬性的具體用法?Python chess.PAWN怎麽用?Python chess.PAWN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在chess的用法示例。


在下文中一共展示了chess.PAWN屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: binary_encode

# 需要導入模塊: import chess [as 別名]
# 或者: from chess import PAWN [as 別名]
def binary_encode(board):
    """ Returns the board as a binary vector, for eval prediction purposes. """
    rows = []
    for color in [chess.WHITE, chess.BLACK]:
        for ptype in range(chess.PAWN, chess.KING + 1):
            mask = board.pieces_mask(ptype, color)
            rows.append(list(map(int, bin(mask)[2:].zfill(64))))
    ep = [0] * 64
    if board.ep_square:
        ep[board.ep_square] = 1
    rows.append(ep)
    rows.append([
        int(board.turn),
        int(bool(board.castling_rights & chess.BB_A1)),
        int(bool(board.castling_rights & chess.BB_H1)),
        int(bool(board.castling_rights & chess.BB_A8)),
        int(bool(board.castling_rights & chess.BB_H8)),
        int(board.is_check())
    ])
    return np.concatenate(rows) 
開發者ID:thomasahle,項目名稱:fastchess,代碼行數:22,代碼來源:proc.py

示例2: pawn_capture_moves_on

# 需要導入模塊: import chess [as 別名]
# 或者: from chess import PAWN [as 別名]
def pawn_capture_moves_on(board: chess.Board) -> List[chess.Move]:
    """Generates all pawn captures on `board`, even if there is no piece to capture. All promotion moves are included."""
    pawn_capture_moves = []

    no_opponents_board = without_opponent_pieces(board)

    for pawn_square in board.pieces(chess.PAWN, board.turn):
        for attacked_square in board.attacks(pawn_square):
            # skip this square if one of our own pieces are on the square
            if no_opponents_board.piece_at(attacked_square):
                continue

            pawn_capture_moves.append(chess.Move(pawn_square, attacked_square))

            # add in promotion moves
            if attacked_square in chess.SquareSet(chess.BB_BACKRANKS):
                for piece_type in chess.PIECE_TYPES[1:-1]:
                    pawn_capture_moves.append(chess.Move(pawn_square, attacked_square, promotion=piece_type))

    return pawn_capture_moves 
開發者ID:reconnaissanceblindchess,項目名稱:reconchess,代碼行數:22,代碼來源:utilities.py

示例3: print_tables

# 需要導入模塊: import chess [as 別名]
# 或者: from chess import PAWN [as 別名]
def print_tables(w):
    for i, color in enumerate([chess.WHITE, chess.BLACK]):
        for j, ptype in enumerate(range(chess.PAWN, chess.KING + 1)):
            table = w[j * 64 + i * 64 * 6:(j + 1) * 64 + i * 64 * 6].reshape(8, 8)
            print(chess.Piece(ptype, color))
            if add_counts:
                print('Val:', w[12 * 64 + 6 * i + j])
            print(table.round(2)) 
開發者ID:thomasahle,項目名稱:fastchess,代碼行數:10,代碼來源:leastsq.py

示例4: add_pawn_queen_promotion

# 需要導入模塊: import chess [as 別名]
# 或者: from chess import PAWN [as 別名]
def add_pawn_queen_promotion(board: chess.Board, move: chess.Move) -> chess.Move:
    piece = board.piece_at(move.from_square)
    if piece is not None and piece.piece_type == chess.PAWN and move.to_square in BACK_RANKS and move.promotion is None:
        move = chess.Move(move.from_square, move.to_square, chess.QUEEN)
    return move 
開發者ID:reconnaissanceblindchess,項目名稱:reconchess,代碼行數:7,代碼來源:utilities.py

示例5: parse_action

# 需要導入模塊: import chess [as 別名]
# 或者: from chess import PAWN [as 別名]
def parse_action (self, action):
        move = adapter.label_flat_to_move(action)

        # TODO: Fix this promotion stuff
        moving_piece = self.state.piece_at(move.from_square)
        if moving_piece.piece_type == chess.PAWN:
            rank, _ = adapter.square_to_index(move.to_square)

            # If pawn moves to edge promote to queen
            if rank == 0 or rank == 7:
                move.promotion = chess.QUEEN

        return move 
開發者ID:crypt3lx2k,項目名稱:Zerofish,代碼行數:15,代碼來源:game_state.py

示例6: apply

# 需要導入模塊: import chess [as 別名]
# 或者: from chess import PAWN [as 別名]
def apply(self, vec, board, move):
        """ Should be called prior to pushing move to board.
            Applies the move to the vector. """

        # Remove from square.
        piece_type = board.piece_type_at(move.from_square)
        color = board.turn
        vec -= self.piece_to_vec[piece_type, color, move.from_square]

        # Update castling rights.
        old_castling_rights = board.clean_castling_rights()
        new_castling_rights = old_castling_rights & ~chess.BB_SQUARES[
            move.to_square] & ~chess.BB_SQUARES[move.from_square]
        if piece_type == chess.KING:
            new_castling_rights &= ~chess.BB_RANK_1 if color else ~chess.BB_RANK_8
        # Castling rights can only have been removed
        for sq in chess.scan_forward(old_castling_rights ^ new_castling_rights):
            vec -= self.castling[sq]

        # Remove pawns captured en passant.
        if piece_type == chess.PAWN and move.to_square == board.ep_square:
            down = -8 if board.turn == chess.WHITE else 8
            capture_square = board.ep_square + down
            vec -= self.piece_to_vec[chess.PAWN, not board.turn, capture_square]

        # Move rook during castling.
        if piece_type == chess.KING:
            if move.from_square == chess.E1:
                if move.to_square == chess.G1:
                    vec -= self.piece_to_vec[chess.ROOK, color, chess.H1]
                    vec += self.piece_to_vec[chess.ROOK, color, chess.F1]
                if move.to_square == chess.C1:
                    vec -= self.piece_to_vec[chess.ROOK, color, chess.A1]
                    vec += self.piece_to_vec[chess.ROOK, color, chess.D1]
            if move.from_square == chess.E8:
                if move.to_square == chess.G8:
                    vec -= self.piece_to_vec[chess.ROOK, color, chess.H8]
                    vec += self.piece_to_vec[chess.ROOK, color, chess.F8]
                if move.to_square == chess.C8:
                    vec -= self.piece_to_vec[chess.ROOK, color, chess.A8]
                    vec += self.piece_to_vec[chess.ROOK, color, chess.D8]

        # Capture
        captured_piece_type = board.piece_type_at(move.to_square)
        if captured_piece_type:
            vec -= self.piece_to_vec[captured_piece_type, not color, move.to_square]

        # Put the piece on the target square.
        vec += self.piece_to_vec[move.promotion or piece_type, color, move.to_square]
        return vec 
開發者ID:thomasahle,項目名稱:fastchess,代碼行數:52,代碼來源:fastchess.py


注:本文中的chess.PAWN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。