Closed PedanticHacker closed 4 years ago
There are many ways. What are you trying to achieve?
I am trying to display a particular chessboard position when a move item (QTableWidgetItem) is clicked in the moves widget (QTableWidget).
Just like in lichess.org
: when you click on a move item in the moves widget, the chessboard redraws itself to display the position that existed for when that clicked move was played. I wanna do the same.
Any alternatives to push()
and set_fen()
?
Here is how to do the operations with python-chess datastructures:
import chess.pgn
# How to append moves to a game
game = chess.pgn.Game()
node = game
node = node.add_variation(chess.Move.from_uci("e2e4"))
node = node.add_variation(chess.Move.from_uci("e7e5"))
node = node.add_variation(chess.Move.from_uci("g1f3"))
node = node.add_variation(chess.Move.from_uci("b8c6"))
# How to get the board of the nth node
n = 3
node = game
for _ in range(n):
node = node.variations[0]
print(node.board())
You can also easily use your own list of moves.
What about using the from_board()
class attribute instead? So like chess.pgn.Game.from_board(board)
?
Why are you doing that node = game
thing? Is this really necessary?
I know 2 ways of changing the state of the board: one is
push()
and the other isset_fen()
. How else is one able to change the state of the board?