本文整理汇总了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)
示例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
示例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))
示例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
示例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
示例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