本文整理匯總了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)