notnil / chess

chess package for go
MIT License
517 stars 130 forks source link

Undoing a move pushed to chess.Game? #54

Closed ArmanMaesumi closed 4 years ago

ArmanMaesumi commented 4 years ago

I would like to use this Go library for an AlphaBeta pruning look ahead algorithm, but I don't understand how to neatly undo a move. Say we pushed a move to a game like so

game := chess.NewGame()
moves := game.ValidMoves()
game.Move(moves[0])

How can we then undo the last move that was made?

notnil commented 4 years ago

You can use the position.Update method to move from valid moves directly and skip redundant validation: https://godoc.org/github.com/notnil/chess#Position.Update

notnil commented 4 years ago

Hope this helped.