本文整理汇总了Python中chess.Board.is_legal方法的典型用法代码示例。如果您正苦于以下问题:Python Board.is_legal方法的具体用法?Python Board.is_legal怎么用?Python Board.is_legal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chess.Board
的用法示例。
在下文中一共展示了Board.is_legal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_san
# 需要导入模块: from chess import Board [as 别名]
# 或者: from chess.Board import is_legal [as 别名]
def get_san(self, message, is_xl=False):
"""Create a chess.board plus a text ready to display on clock."""
def move(text: str, language: str, capital: bool, short: bool):
"""Return move text for clock display."""
if short:
directory = {}
if language == 'de':
directory = {'R': 'T', 'N': 'S', 'B': 'L', 'Q': 'D'}
if language == 'nl':
directory = {'R': 'T', 'N': 'P', 'B': 'L', 'Q': 'D'}
if language == 'fr':
directory = {'R': 'T', 'N': 'C', 'B': 'F', 'Q': 'D', 'K': '@'}
if language == 'es':
directory = {'R': 'T', 'N': 'C', 'B': 'A', 'Q': 'D', 'K': '@'}
if language == 'it':
directory = {'R': 'T', 'N': 'C', 'B': 'A', 'Q': 'D', 'K': '@'}
for i, j in directory.items():
text = text.replace(i, j)
text = text.replace('@', 'R') # replace the King "@" from fr, es, it languages
if capital:
return text.upper()
else:
return text
bit_board = Board(message.fen, chess960=message.uci960)
if bit_board.is_legal(message.move):
if message.long:
move_text = message.move.uci()
else:
move_text = bit_board.san(message.move)
else:
logging.warning('[%s] illegal move %s found - uci960: %s fen: %s', self.get_name(), message.move,
message.uci960, message.fen)
move_text = 'er{}' if is_xl else 'err {}'
move_text = move_text.format(message.move.uci()[:4])
if message.side == ClockSide.RIGHT:
move_text = move_text.rjust(6 if is_xl else 8)
return bit_board, move(move_text, message.lang, message.capital and not is_xl, not message.long)