Store game moves

Code, algorithms, languages, construction...
Post Reply
lilleskut
Posts: 1
Joined: Tue Mar 15, 2016 10:14 am

Store game moves

Post by lilleskut » Tue Mar 15, 2016 10:31 am

I just started writing my own chess program (GUI and computer player) which is working fine so far. It is written in java, I know it is not the best choice, but bare with me.

Now my simple problem:

I would like to store the moves made so that they can be displayed in the GUI and also that I can play/move back and forth through the game. What is the best/recommended format to store the game?

1. I could extend my Move class (startPosition, endPosition, movingPiece) to include information on the captured pieces and then store the game as array of the extended move class.

2. Or I could take my original Move class and re-create any position from the starting position.

3. Or I could store a String array of all positions in FEN-notation.

4. Or something else?

Also, how do you store variations? If I want to create some kind of analysis feature.

H.G.Muller
Posts: 190
Joined: Sun Jul 14, 2013 10:00 am
Real Name: H.G. Muller

Re: Store game moves

Post by H.G.Muller » Tue Mar 15, 2016 5:10 pm

WinBoard stores all positions of the game, as 2D arrays. It also stores all moves, but only as from-square and to-square (and possibly promotion piece). But that is used only for displaying the moves made from any position above the board, not to derive positions from.

Variations are done in WinBoard by moving the 'tail' of the main line to a free part of the array of boards (organized as a stack), truncating the game to that point, and then writing the positions from the variation behind it. By hitting 'Revert' the original tail is then copied back,to overwrite the variation.

In my engines I usually implement 'undo' by setting up the initial position again, and replaying all moves.

Post Reply