本文整理汇总了Python中chess.Board.is_stalemate方法的典型用法代码示例。如果您正苦于以下问题:Python Board.is_stalemate方法的具体用法?Python Board.is_stalemate怎么用?Python Board.is_stalemate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chess.Board
的用法示例。
在下文中一共展示了Board.is_stalemate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: say_last_move
# 需要导入模块: from chess import Board [as 别名]
# 或者: from chess.Board import is_stalemate [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