本文整理汇总了Python中chess.WHITE属性的典型用法代码示例。如果您正苦于以下问题:Python chess.WHITE属性的具体用法?Python chess.WHITE怎么用?Python chess.WHITE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类chess
的用法示例。
在下文中一共展示了chess.WHITE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_move
# 需要导入模块: import chess [as 别名]
# 或者: from chess import WHITE [as 别名]
def find_move(self, board, debug=False):
# Should we flip the board to make sure it always gets it from white?
vec_board = board_to_vec(
board if board.turn == chess.WHITE else board.mirror())
vec_board = tensor_sketch(vec_board, self.sketches)
probs = self.move_clf.predict_proba([vec_board])[0]
score = self.score_clf.predict([vec_board])[0]
for n, (mp, from_to) in enumerate(sorted((-p, ft) for ft, p in enumerate(probs))):
to_square, from_square = divmod(from_to, 64)
if board.turn == chess.BLACK:
from_square = chess.square_mirror(from_square)
to_square = chess.square_mirror(to_square)
move = chess.Move(from_square, to_square)
if move in board.legal_moves:
print(f'Choice move {n}, p={-mp}')
return move, score
示例2: binary_encode
# 需要导入模块: import chess [as 别名]
# 或者: from chess import WHITE [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)
示例3: __init__
# 需要导入模块: import chess [as 别名]
# 或者: from chess import WHITE [as 别名]
def __init__(self, mode=TimeMode.FIXED, fixed=0, blitz=0, fischer=0, internal_time=None):
super(TimeControl, self).__init__()
self.mode = mode
self.move_time = fixed
self.game_time = blitz
self.fisch_inc = fischer
self.internal_time = internal_time
self.clock_time = {chess.WHITE: 0, chess.BLACK: 0} # saves the sended clock time for white/black
self.timer = None
self.run_color = None
self.active_color = None
self.start_time = None
if internal_time: # preset the clock (received) time already
self.clock_time[chess.WHITE] = int(internal_time[chess.WHITE])
self.clock_time[chess.BLACK] = int(internal_time[chess.BLACK])
else:
self.reset()
示例4: num_turns
# 需要导入模块: import chess [as 别名]
# 或者: from chess import WHITE [as 别名]
def num_turns(self, color: Color = None) -> int:
"""
Get the number of turns taken in the game. Optionally specify the color of the player to get the number of turns
for.
Examples:
>>> history.num_turns()
9
>>> history.num_turns(WHITE)
5
>>> history.num_turns(BLACK)
4
:param color: Optional player color indicating which player's number of turns to return.
:return: The number of turns saved in this object. If `color` is specified, get the number of turns for that
player.
"""
return len(list(self.turns(color=color)))
示例5: first_turn
# 需要导入模块: import chess [as 别名]
# 或者: from chess import WHITE [as 别名]
def first_turn(self, color: Color = None) -> Turn:
"""
Gets the first turn of the game.
Examples:
>>> history.first_turn()
Turn(WHITE, 0)
>>> history.first_turn(WHITE)
Turn(WHITE, 0)
>>> history.first_turn(BLACK)
Turn(BLACK, 0)
:param color: Optional color indicating which player's first turn to return.
:return: The :class:`Turn` that is the first turn in the game.
"""
if self.is_empty():
raise ValueError('GameHistory is empty')
return Turn(color if color is not None else chess.WHITE, 0)
示例6: has_sense
# 需要导入模块: import chess [as 别名]
# 或者: from chess import WHITE [as 别名]
def has_sense(self, turn: Turn) -> bool:
"""
Checks to see if the game has a sense action for the specified turn. The game may not if it ended because of
timeout.
This intended use is to call this before calling :meth:`sense` and :meth:`sense_result`, to verify that there
is a sense before querying for it.
Examples:
>>> history.has_sense(Turn(WHITE, 0))
True
>>> history.has_sense(Turn(WHITE, 432))
False
:param turn: The :class:`Turn` in question.
:return: `True` if there is a sense action, `False` otherwise.
"""
return 0 <= turn.turn_number < len(self._senses[turn.color])
示例7: sense
# 需要导入模块: import chess [as 别名]
# 或者: from chess import WHITE [as 别名]
def sense(self, turn: Turn) -> Optional[Square]:
"""
Get the sense action on the given turn.
Examples:
>>> history.sense(Turn(WHITE, 0))
E7
>>> history.sense(Turn(BLACK, 0))
E2
>>> history.sense(Turn(WHITE, 1))
None
:param turn: The :class:`Turn` in question.
:return: The executed sense action as a :class:`Square`.
"""
self._validate_turn(turn, self._senses)
return self._senses[turn.color][turn.turn_number]
示例8: sense_result
# 需要导入模块: import chess [as 别名]
# 或者: from chess import WHITE [as 别名]
def sense_result(self, turn: Turn) -> List[Tuple[Square, Optional[chess.Piece]]]:
"""
Get the result of the sense action on the given turn.
Examples:
>>> history.sense(Turn(WHITE, 0))
B7
>>> history.sense_result(Turn(WHITE, 0))
[
(A8, Piece(ROOK, BLACK)), (B8, Piece(KNIGHT, BLACK)), (C8, Piece(BISHOP, BLACK)),
(A7, Piece(PAWN, BLACK)), (B7, Piece(PAWN, BLACK)), (C7, Piece(PAWN, BLACK)),
(A6, None), (B6, None), (C8, None)
]
>>> history.sense(Turn(BLACK, 0))
None
>>> history.sense_result(Turn(BLACK, 0))
[]
:param turn: The :class:`Turn` in question.
:return: The result of the executed sense action.
"""
self._validate_turn(turn, self._sense_results)
return self._sense_results[turn.color][turn.turn_number]
示例9: has_move
# 需要导入模块: import chess [as 别名]
# 或者: from chess import WHITE [as 别名]
def has_move(self, turn: Turn) -> bool:
"""
Checks to see if the game has a move action for the specified turn. The game may not if it ended because of
timeout.
This intended use is to call this before calling :meth:`requested_move`, :meth:`taken_move`,
:meth:`capture_square`, and :meth:`move_result` to verify that there is a move before querying for it.
Examples:
>>> history.has_move(Turn(WHITE, 0))
True
>>> history.has_move(Turn(WHITE, 432))
False
:param turn: The :class:`Turn` in question.
:return: `True` if there is a move action, `False` otherwise.
"""
return 0 <= turn.turn_number < len(self._requested_moves[turn.color])
示例10: taken_move
# 需要导入模块: import chess [as 别名]
# 或者: from chess import WHITE [as 别名]
def taken_move(self, turn: Turn) -> Optional[chess.Move]:
"""
Get the executed move action on the given turn. This may be different than the requested move, as the requested
move may not be legal.
Examples:
>>> history.requested_move(Turn(WHITE, 0))
Move(E2, D3)
>>> history.taken_move(Turn(WHITE, 0))
None
>>> history.requested_move(Turn(WHITE, 1))
Move(E2, E4)
>>> history.taken_move(Turn(WHITE, 1))
Move(E2, E3)
:param turn: The :class:`Turn` in question.
:return: `None` if the player requested to pass or made an illegal move, the executed move action as a
:class:`chess.Move` otherwise.
"""
self._validate_turn(turn, self._taken_moves)
return self._taken_moves[turn.color][turn.turn_number]
示例11: capture_square
# 需要导入模块: import chess [as 别名]
# 或者: from chess import WHITE [as 别名]
def capture_square(self, turn: Turn) -> Optional[Square]:
"""
Get the square of the opponent's captured piece on the given turn. A capture may not have occurred, in which
case `None` will be returned.
Examples:
>>> history.capture_square(Turn(WHITE, 0))
None
>>> history.capture_square(Turn(WHITE, 4))
E4
:param turn: The :class:`Turn` in question.
:return: If a capture occurred, then the :class:`Square` where it occurred, otherwise `None`.
"""
self._validate_turn(turn, self._capture_squares)
return self._capture_squares[turn.color][turn.turn_number]
示例12: truth_fen_before_move
# 需要导入模块: import chess [as 别名]
# 或者: from chess import WHITE [as 别名]
def truth_fen_before_move(self, turn: Turn) -> str:
"""
Get the truth state of the board as a fen string before the move was executed on the given turn. Use
:meth:`truth_board_before_move` if you want the truth board as a :class:`chess.Board` object.
Examples:
>>> history.truth_fen_before_move(Turn(WHITE, 0))
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -"
>>> history.taken_move(Turn(WHITE, 0))
Move(E2, E4)
>>> history.truth_fen_before_move(Turn(BLACK, 0))
"rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq -"
:param turn: The :class:`Turn` in question.
:return: The fen of the truth board.
"""
self._validate_turn(turn, self._fens_before_move)
return self._fens_before_move[turn.color][turn.turn_number]
示例13: truth_board_before_move
# 需要导入模块: import chess [as 别名]
# 或者: from chess import WHITE [as 别名]
def truth_board_before_move(self, turn: Turn) -> chess.Board:
"""
Get the truth state of the board as a :class:`chess.Board` before the move was executed on the given turn. Use
:meth:`truth_fen_before_move` if you want the truth board as a fen string.
Examples:
>>> history.truth_board_before_move(Turn(WHITE, 0))
Board("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -")
>>> history.taken_move(Turn(WHITE, 0))
Move(E2, E4)
>>> history.truth_fen_before_move(Turn(BLACK, 0))
Board("rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq -")
:param turn: The :class:`Turn` in question.
:return: A :class:`chess.Board` object.
"""
self._validate_turn(turn, self._fens_before_move)
board = chess.Board(self._fens_before_move[turn.color][turn.turn_number])
board.turn = turn.color
return board
示例14: truth_board_after_move
# 需要导入模块: import chess [as 别名]
# 或者: from chess import WHITE [as 别名]
def truth_board_after_move(self, turn: Turn) -> chess.Board:
"""
Get the truth state of the board as a :class:`chess.Board` after the move was executed on the given turn. Use
:meth:`truth_fen_after_move` if you want the truth board as a fen string.
Examples:
>>> history.truth_board_before_move(Turn(WHITE, 0))
Board("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -")
>>> history.taken_move(Turn(WHITE, 0))
Move(E2, E4)
>>> history.truth_fen_after_move(Turn(WHITE, 0))
Board("rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq -")
:param turn: The :class:`Turn` in question.
:return: A :class:`chess.Board` object.
"""
self._validate_turn(turn, self._fens_after_move)
board = chess.Board(self._fens_after_move[turn.color][turn.turn_number])
board.turn = turn.color
return board
示例15: collect
# 需要导入模块: import chess [as 别名]
# 或者: from chess import WHITE [as 别名]
def collect(self, get_turn_data_fn: Callable[[Turn], T], turns: Iterable[Turn]) -> Iterable[T]:
"""
Collect data from multiple turns using any of :meth:`sense`, :meth:`sense_result`, :meth:`requested_move`,
:meth:`taken_move`, :meth:`capture_square`, :meth:`move_result`, :meth:`truth_fen_before_move`,
:meth:`truth_board_before_move`, :meth:`truth_fen_after_move`, or :meth:`truth_board_after_move`.
Examples:
>>> history.collect(history.sense, [Turn(WHITE, 0), Turn(BLACK, 0)])
[E7, E2]
>>> history.collect(history.requested_move, history.turns(WHITE))
[Move(E2, E4), Move(D1, H5), ...]
:param get_turn_data_fn: One of the getter functions of the history object.
:param turns: The turns in question.
:return: A list of the data, where each element is the value of the getter function on the corresponding turn.
"""
if get_turn_data_fn not in [self.sense, self.sense_result, self.requested_move, self.taken_move,
self.capture_square, self.move_result, self.truth_board_before_move,
self.truth_board_after_move, self.truth_fen_before_move, self.truth_fen_after_move]:
raise ValueError('get_turn_data_fn must be one of the history getter functions')
for turn in turns:
yield get_turn_data_fn(turn)