本文整理汇总了Python中chess.BLACK属性的典型用法代码示例。如果您正苦于以下问题:Python chess.BLACK属性的具体用法?Python chess.BLACK怎么用?Python chess.BLACK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类chess
的用法示例。
在下文中一共展示了chess.BLACK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_move
# 需要导入模块: import chess [as 别名]
# 或者: from chess import BLACK [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 BLACK [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 BLACK [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: first_turn
# 需要导入模块: import chess [as 别名]
# 或者: from chess import BLACK [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)
示例5: sense_result
# 需要导入模块: import chess [as 别名]
# 或者: from chess import BLACK [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]
示例6: requested_move
# 需要导入模块: import chess [as 别名]
# 或者: from chess import BLACK [as 别名]
def requested_move(self, turn: Turn) -> Optional[chess.Move]:
"""
Get the requested move action on the given turn.
Examples:
>>> history.requested_move(Turn(WHITE, 0))
Move(E2, E4)
>>> history.requested_move(Turn(BLACK, 0))
Move(E7, E5)
>>> history.requested_move(Turn(WHITE, 1))
None
:param turn: The :class:`Turn` in question.
:return: If the player requested to move, then the requested move action as a :class:`chess.Move`, otherwise
`None` if the player requested to pass.
"""
self._validate_turn(turn, self._requested_moves)
return self._requested_moves[turn.color][turn.turn_number]
示例7: truth_fen_before_move
# 需要导入模块: import chess [as 别名]
# 或者: from chess import BLACK [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]
示例8: truth_board_before_move
# 需要导入模块: import chess [as 别名]
# 或者: from chess import BLACK [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
示例9: collect
# 需要导入模块: import chess [as 别名]
# 或者: from chess import BLACK [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)
示例10: print_tables
# 需要导入模块: import chess [as 别名]
# 或者: from chess import BLACK [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))
示例11: run_games
# 需要导入模块: import chess [as 别名]
# 或者: from chess import BLACK [as 别名]
def run_games(self, book, game_id=0, games_played=2):
score = 0
games = []
assert games_played % 2 == 0
for r in range(games_played//2):
init_board = random.choice(book)
for color in [WHITE, BLACK]:
white, black = (self.enginea, self.engineb) if color == WHITE \
else (self.engineb, self.enginea)
game_round = games_played * game_id + color + 2*r
game = chess.pgn.Game({
'Event': 'Tune.py',
'White': white.id['name'],
'WhiteArgs': repr(white.id['args']),
'Black': black.id['name'],
'BlackArgs': repr(black.id['args']),
'Round': game_round
})
games.append(game)
# Add book moves
game.setup(init_board.root())
node = game
for move in init_board.move_stack:
node = node.add_variation(move, comment='book')
# Run engines
async for _play, er in self.play_game(node, game_round, white, black):
# If an error occoured, return as much as we got
if er is not None:
return games, score, er
result = game.headers["Result"]
if result == '1-0' and color == WHITE or result == '0-1' and color == BLACK:
score += 1
if result == '1-0' and color == BLACK or result == '0-1' and color == WHITE:
score -= 1
return games, score/games_played, None
示例12: reset
# 需要导入模块: import chess [as 别名]
# 或者: from chess import BLACK [as 别名]
def reset(self):
"""Reset the clock's times for both players."""
if self.mode == TimeMode.BLITZ:
self.clock_time[chess.WHITE] = self.clock_time[chess.BLACK] = self.game_time * 60
elif self.mode == TimeMode.FISCHER:
self.clock_time[chess.WHITE] = self.clock_time[chess.BLACK] = self.game_time * 60 + self.fisch_inc
elif self.mode == TimeMode.FIXED:
self.clock_time[chess.WHITE] = self.clock_time[chess.BLACK] = self.move_time
self.internal_time = {chess.WHITE: float(self.clock_time[chess.WHITE]),
chess.BLACK: float(self.clock_time[chess.BLACK])}
self.active_color = None
示例13: get_internal_time
# 需要导入模块: import chess [as 别名]
# 或者: from chess import BLACK [as 别名]
def get_internal_time(self, flip_board=False):
"""Return the startup time for setting the clock at beginning."""
i_time = copy.copy(self.internal_time)
if flip_board:
i_time[chess.WHITE], i_time[chess.BLACK] = i_time[chess.BLACK], i_time[chess.WHITE]
return int(i_time[chess.WHITE]), int(i_time[chess.BLACK])
示例14: set_clock_times
# 需要导入模块: import chess [as 别名]
# 或者: from chess import BLACK [as 别名]
def set_clock_times(self, white_time: int, black_time: int):
"""Set the times send from the clock."""
logging.info('set clock times w:%s b:%s', hms_time(white_time), hms_time(black_time))
self.clock_time[chess.WHITE] = white_time
self.clock_time[chess.BLACK] = black_time
示例15: _out_of_time
# 需要导入模块: import chess [as 别名]
# 或者: from chess import BLACK [as 别名]
def _out_of_time(self, time_start):
"""Fire an OUT_OF_TIME event."""
self.run_color = None
if self.mode == TimeMode.FIXED:
logging.debug('timeout - but in "MoveTime" mode, dont fire event')
elif self.active_color is not None:
display_color = 'WHITE' if self.active_color == chess.WHITE else 'BLACK'
txt = 'current clock time (before subtracting) is %f and color is %s, out of time event started from %f'
logging.debug(txt, self.internal_time[self.active_color], display_color, time_start)
Observable.fire(Event.OUT_OF_TIME(color=self.active_color))