本文整理匯總了Python中chess.Board.is_check方法的典型用法代碼示例。如果您正苦於以下問題:Python Board.is_check方法的具體用法?Python Board.is_check怎麽用?Python Board.is_check使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類chess.Board
的用法示例。
在下文中一共展示了Board.is_check方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: say_last_move
# 需要導入模塊: from chess import Board [as 別名]
# 或者: from chess.Board import is_check [as 別名]
def say_last_move(game: chess.Board):
"""Take a chess.BitBoard instance and speaks the last move from it."""
move_parts = {
'K': 'king.ogg',
'B': 'bishop.ogg',
'N': 'knight.ogg',
'R': 'rook.ogg',
'Q': 'queen.ogg',
'P': 'pawn.ogg',
'+': '',
'#': '',
'x': 'takes.ogg',
'=': 'promote.ogg',
'a': 'a.ogg',
'b': 'b.ogg',
'c': 'c.ogg',
'd': 'd.ogg',
'e': 'e.ogg',
'f': 'f.ogg',
'g': 'g.ogg',
'h': 'h.ogg',
'1': '1.ogg',
'2': '2.ogg',
'3': '3.ogg',
'4': '4.ogg',
'5': '5.ogg',
'6': '6.ogg',
'7': '7.ogg',
'8': '8.ogg'
}
bit_board = game.copy()
move = bit_board.pop()
san_move = bit_board.san(move)
voice_parts = []
if san_move.startswith('O-O-O'):
voice_parts += ['castlequeenside.ogg']
elif san_move.startswith('O-O'):
voice_parts += ['castlekingside.ogg']
else:
for part in san_move:
try:
sound_file = move_parts[part]
except KeyError:
logging.warning('unknown char found in san: [%s : %s]', san_move, part)
sound_file = ''
if sound_file:
voice_parts += [sound_file]
if game.is_game_over():
if game.is_checkmate():
wins = 'whitewins.ogg' if game.turn == chess.BLACK else 'blackwins.ogg'
voice_parts += ['checkmate.ogg', wins]
elif game.is_stalemate():
voice_parts += ['stalemate.ogg']
else:
if game.is_seventyfive_moves():
voice_parts += ['75moves.ogg', 'draw.ogg']
elif game.is_insufficient_material():
voice_parts += ['material.ogg', 'draw.ogg']
elif game.is_fivefold_repetition():
voice_parts += ['repetition.ogg', 'draw.ogg']
else:
voice_parts += ['draw.ogg']
elif game.is_check():
voice_parts += ['check.ogg']
if bit_board.is_en_passant(move):
voice_parts += ['enpassant.ogg']
return voice_parts