History of board game movements

Hi, i was wondering what would be the most efficient way to save a game's history ( for example tic-tac-toe ). the most logic way is probably save it in the Portable Game Notation (PGN) format, but i would also like users to be able to look at specific moves in the history of a game, should i then walk trough every move, and execute it in the background so that i can rebuild the look of the board as it looked at that specific move?

And entire descriptions of the game board (xml) at every move seems a bit over the top, it needs to be as small as possible

Thanks for any suggestions

[606 byte] By [plokkera] at [2007-9-29 5:09:58]
# 1

Depends on how complex the game state is. You could encode any state of a tic-tac-toe game into a single integer, and still have room to store the latest move in it as well. So to store a game with 15 moves would only need 60 bytes of storage.

But then, the scheme you mentioned (recording moves and iterating through the game move by move) seems perfectly fine... there are only a finite and relatively small number of moves in a game such as tic-tac-toe or chess.

JN_a at 2007-7-14 18:23:26 > top of Java-index,Other Topics,Java Game Development...
# 2
> or chess.*beep* Chess has an infinite number of moves :D
Abusea at 2007-7-14 18:23:26 > top of Java-index,Other Topics,Java Game Development...
# 3
Not infinite but the number of positions is aproximately 10^24th.
davecoma at 2007-7-14 18:23:26 > top of Java-index,Other Topics,Java Game Development...
# 4
Also how about using an array, each position in the array representing a 'square' on the tic tac toe or whatever board. And then you can use different values for the position to designate different pieces, or no value or 0 to designate a blank square.
davecoma at 2007-7-14 18:23:26 > top of Java-index,Other Topics,Java Game Development...
# 5
> > or chess.> > *beep* Chess has an infinite number of moves :DYou're thinking about the number of possible moves. We're talking about the number of historical moves in a game of chess, which is of course finite. Thanks for playing. ;)
JN_a at 2007-7-14 18:23:26 > top of Java-index,Other Topics,Java Game Development...
# 6
hey, i would like to hear some more about how to encode that in a single integer, seems very interesting. If you know just a website that would be more than enough information if you don't have a lot of time.Thanks
plokkera at 2007-7-14 18:23:26 > top of Java-index,Other Topics,Java Game Development...
# 7

> > > or chess.

> >

> > *beep* Chess has an infinite number of moves :D

>

> You're thinking about the number of possible moves.

> We're talking about the number of historical moves in

> a game of chess, which is of course finite. Thanks

> for playing. ;)

I don't get it :o

There are indeed a finite number of states for the board+pieces.

But the sequence of moves that make up a single game can be any number, including infinite :p (assuming the game is still playing :)

Maybe I mis-interpreted the problem, but isn't the sequence of moves what you want to record?

Abusea at 2007-7-14 18:23:27 > top of Java-index,Other Topics,Java Game Development...
# 8

ofcourse.... if you are talking about a game in the past tense, then it has ended.... which by definition I guess means it doesn't have an infinite number of moves it it...

oh yeah, what has to happen for a stalemate to be declared?

That could blow my never ending game out of the water :)

Abusea at 2007-7-14 18:23:27 > top of Java-index,Other Topics,Java Game Development...
# 9

> oh yeah, what has to happen for a stalemate to be declared?

Either insufficient forces to produce checkmate (such as only the kings left) or for a judge/both players to call the stalemate. Usually the reason for a stalemate is the former. Kings alone can be devilish little pieces and can sometimes be used to clean the other player out of pieces without going into check. Thus when there are only kings left, the game is a stalemate due to the fact that kings can only move one space, so any attempt to come within range of the other king would produce a check situation. Most players/judges will call the stalemate long before this tho. Having a Bishop and a king is the perfect example of how it is nigh impossible to trap the opponent in checkmate.

jbanesa at 2007-7-14 18:23:27 > top of Java-index,Other Topics,Java Game Development...
# 10

> I don't get it :o

> There are indeed a finite number of states for the

> board+pieces.

> But the sequence of moves that make up a single

> game can be any number, including infinite :p

> (assuming the game is still playing :)

Since you're only recording moves which have been made (in the past), the number of moves is finite.

JN_a at 2007-7-14 18:23:27 > top of Java-index,Other Topics,Java Game Development...
# 11
I believe there is a rule in chess that prohibits excessive repeats of a pattern of moves, so that rules out an infinite number of moves.
arkillama at 2007-7-14 18:23:27 > top of Java-index,Other Topics,Java Game Development...
# 12

Oh boys Chess is soooo simple game.

For storing in the array.

int[] array=new int[amountOfMoves];

int pos;

private boolean playermoved(int move){

array[pos]=move;

move++; //or +some other number

return DID_IT_HURRAY;

}

int <b> move </b> is number of board's tile. You guessed it right? ~_^

Of course this solution thinks that no player could give up his move.

Lord_of_the_chaosa at 2007-7-14 18:23:27 > top of Java-index,Other Topics,Java Game Development...
# 13
And if you wonder why move should do ++ it should be posarray[pos]=move;pos++; //or +some I need post edit.
Lord_of_the_chaosa at 2007-7-14 18:23:27 > top of Java-index,Other Topics,Java Game Development...