小编Jus*_*eng的帖子

如何获取python-chess模块​​中所有合法动作的列表?

我正在使用 python 国际象棋模块。在网站上,它显示您可以通过使用检查移动是否合法

import chess

board = chess.Board()
move = input("Enter a chess move: ")
if move in board.legal_moves:
    # Some code to do if the move is a legal move
Run Code Online (Sandbox Code Playgroud)

但是,我希望能够从board.legal_moves. 当我尝试这个时:

print(board.legal_moves[0])
Run Code Online (Sandbox Code Playgroud)

这将返回以下错误:

TypeError: 'LegalMoveGenerator' object is not subscriptable
Run Code Online (Sandbox Code Playgroud)

如何像使用列表一样选择移动?那么,我将如何使用选择作为移动?

python list python-3.x python-chess

3
推荐指数
2
解决办法
1908
查看次数

标签 统计

list ×1

python ×1

python-3.x ×1

python-chess ×1