Skip to content

Conversation

@stefanpeiculeasa
Copy link

Add ability to load and play chess games from PGN (Portable Game Notation) files in Solo mode. Players can now press 'p' to open a file dialog and load any standard PGN file to continue playing from that position.

Features:

  • New PGN parser module using shakmaty library
  • Parse standard algebraic notation with full move validation
  • Support for all chess moves (castling, en passant, promotions)
  • Automatic board state restoration from PGN moves
  • Board orientation adjustment based on current turn
  • Keyboard shortcut 'p' in Solo mode to trigger PGN loading
  • File path input popup with increased character limit (200 chars)
  • Comprehensive error handling and debug logging to dbg.txt
  • Move history and board state preservation

Implementation:

  • Created src/game_logic/pgn_loader.rs with PGN parsing logic
  • Added EnterPGNPath popup variant for file input
  • Extended App state with pgn_file_path field
  • Updated keyboard handler for 'p' key in Solo mode
  • Added UI rendering for PGN file path input
  • Increased prompt input limit for long file paths
  • Updated help menu with PGN loading instructions

Add ability to load and play chess games from PGN (Portable Game Notation)
files in Solo mode. Players can now press 'p' to open a file dialog and
load any standard PGN file to continue playing from that position.

Features:
- New PGN parser module using shakmaty library
- Parse standard algebraic notation with full move validation
- Support for all chess moves (castling, en passant, promotions)
- Automatic board state restoration from PGN moves
- Board orientation adjustment based on current turn
- Keyboard shortcut 'p' in Solo mode to trigger PGN loading
- File path input popup with increased character limit (200 chars)
- Comprehensive error handling and debug logging to dbg.txt
- Move history and board state preservation

Implementation:
- Created src/game_logic/pgn_loader.rs with PGN parsing logic
- Added EnterPGNPath popup variant for file input
- Extended App state with pgn_file_path field
- Updated keyboard handler for 'p' key in Solo mode
- Added UI rendering for PGN file path input
- Increased prompt input limit for long file paths
- Updated help menu with PGN loading instructions

Testing:
- Added unit tests for PGN parsing
- Included example PGN files for testing
- Debug output to dbg.txt for troubleshooting
@thomas-mauran
Copy link
Owner

Hello looking that asap ! thank you for the contribution

@thomas-mauran
Copy link
Owner

Hello @stefanpeiculeasa is this pr ready for review ? while trying it out with random pgn files from this db nothing happens after clicking on p, pasting the absolute path of the pgn file and pressing enter ?

I tried trimming the pgn with only that

1.d4 d5 2.g3 Nf6 3.Bg2 c5 4.Nf3 e6 5.O-O Be7 6.dxc5 Bxc5 7.a3 O-O 8.b4 Be7
9.Nbd2 a5 10.b5 Nbd7 11.c4 Nb6 12.Bb2 dxc4 13.Ne5 Qc7 14.Qc2 Bd7 15.a4 Rac8
16.Rfc1 Rfd8 17.Ndxc4 Nxc4 18.Qxc4 Bc5 19.Qf4 Be8 20.Nd3 Qe7 21.Nxc5 Rxc5
22.Rxc5 Qxc5 23.Bxb7 Qc2 24.Bxf6 gxf6 25.Bf3 Kg7 26.Kg2 e5 27.Rc1 Qb2 28.Qg4+ Kf8
29.Rc8 h5 30.Qf5 Rxc8  1-0

Can you show me an example of pgn files you used ?

@thomas-mauran
Copy link
Owner

Hello @stefanpeiculeasa I merged main (which got a complete code refactor) into your branch, tell me if you need help to adapt the code due to the huge refactor which was made, this was done to prepare the v2 of chess-tui

@thomas-mauran thomas-mauran force-pushed the main branch 10 times, most recently from cf5db72 to c75428c Compare December 16, 2025 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants