jordanbray / chess

A rust library to manage chess move generation
https://jordanbray.github.io/chess/
MIT License
243 stars 55 forks source link

Display Game as PGN #69

Open yzoug opened 2 years ago

yzoug commented 2 years ago

Hello,

To ease the task of analysing a game (after it is played using this crate), displaying a Game using PGN could be interesting, so that it can be plugged into the Lichess analysis board for example (https://lichess.org/analysis).

I have started working on this but I am a very new Rust dev so mistakes are bound to be made. Would this project still be interested in a PR for this?

Since the Game struct is already not as efficient as Board and not recommended for chess engines, I went for something very simple, but not so efficient: implementing Display for the Game struct, iterating over all the actions, ignoring every MakeMove except ChessMove, applying the move in a Board, copied from starting_pos (so that I can easily get the Piece that is in each Square from a ChessMove), and with this creating the full PGN string.

If another approach should be preferred, I would be interested in details and I'll try to do it!

Thanks a lot, yzoug