FS#7174 - Chessbox - Store game history in PGN format

Attached to Project: Rockbox
Opened by Mauricio Peccorini (mpeccorini) - Tuesday, 15 May 2007, 20:50 GMT
Last edited by Nils Wallménius (nls) - Sunday, 02 September 2007, 10:12 GMT
Task Type Patches
Category Plugins
Status Closed
Assigned To No-one
Operating System All players
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No


Modifications to chessbox.c, gnuchess.c and gnuchess.h so the history of games played is stored in a file called chessbox.pgn. It considers all (up to what I know) rules of PGN annotation including the handling of checks, checkmates, taking pieces, resolution of ambiguous moves by adding the row or column of the moving piece as needed, castling kingside and queenside, promotions (only to queens since the chessbox plugin itself doesn't allow the player to choose), pawns taking "en passant", etc.

Currently, it has some limitations:
-The abbreviation of the pieces are always in english regardless of the language the player is using.
-The PGN header is constant:
[Event "Chessbox Chess Game"]
[White "player"]
[Black "Chessbox (powered by GnuChess)"]
-The players could be swapped but you can swap them in the middle of the game and the header has already been stored at that time.
-I didn't find where to get the system date (I don't even know if this is possible at all)
-The result could be added but I'm not storing the history in memory but instead storing it as you play. I didn't want to use too much memory for this. It would be relatively easy to change though and that would lead to other improvements like "undo move" (I know, I know, that's cheating !!! ;-) ).
-The history is being stored but there's no way of watching previously played matches in the player, you have to download the file to a computer and use a different software for that (I plan to make this possible in the future but that includes adding a menu, a PGN parser and a lot of user interaction so it can take some time)

This task depends upon

Closed by  Nils Wallménius (nls)
Sunday, 02 September 2007, 10:12 GMT
Reason for closing:  Accepted
Comment by Mauricio Peccorini (mpeccorini) - Thursday, 17 May 2007, 00:16 GMT
As linuxstb made me realize in the IRC channel, the way I've implemented the feature will be too power consuming in hard disk based players. I'll rewrite the whole thing and post it as soon as I can.

In the mean time, I don't think committing the patch as it is would be any wise.
Comment by Dave Chapman (linuxstb) - Thursday, 17 May 2007, 00:24 GMT
You may also want to look at how the Sudoku plugin handles saved games. It's a plugin (meaning it can be started from the Browse Plugins menu), but also a viewer - if you select a ".ss" file in the file browser, then Rockbox will load the sudoku plugin and pass the filename of the selected .ss file to it as a parameter. You could use this approach to load .pgn files without the need for any extra UI in chessbox itself - selecting a .pgn file would load chessbox.
Comment by Mauricio Peccorini (mpeccorini) - Friday, 01 June 2007, 20:41 GMT
Complete rewrite of the feature now storing the history of the game in memory and saving it to file only when the game finishes. It was also changed to use GNU Chess data structures instead of having its own. Also, some of the limitations initially stated were tackled:

- The header now has the correct date (assuming the player has the correct date set ;-) )
- The header also includes the "mandatory" 7 tags according to the PGN specification
- The result of the game is stated both at the end of the game and in the header, just like the specification requires (0-1, 1-0, 1/2-1/2 or * for unknown result)
- Watching the games stored in PGN files and using chessbox as a viewer as linuxstb suggested was taken care of in task #7209 which is already committed to the SVN repository.

I'm also including the modifications to the manual so it stays up to date.
Comment by Mauricio Peccorini (mpeccorini) - Thursday, 07 June 2007, 16:51 GMT
Fix the date of the game (set it to ????.??.?? according to the PGN spec) in non-RTC targets.

Thanks to pixelma for pointing this out.

The patch for the manual is still valid.
Comment by parafin (parafin) - Tuesday, 21 August 2007, 12:14 GMT
There was two bugs in date saving - current_time->tm_year < 2000 must be changed to current_time->tm_year < 100 and current_time->tm_year + 1899 must be changed to current_time->tm_year + 1900
I fixed them + converted patch to unix newlines (source in svn is already has unix newlines)
Comment by Nils Wallménius (nls) - Sunday, 02 September 2007, 07:16 GMT
parafin, I need your real name if your changes are to be included in a commit.