On the subject of chess games, Numberphile has a nice video:
The problem of counting chess games (and therefore, how to encode them) is a fairly old one.
Using the restriction that all games must follow the rules, the space is multiplied at each ply by all the legal moves available to the player at that time. A state machine can enumerate those possibilities in a defined order, which yields a residue for that move that we can then add to get a longer number encoding the state of the game.
Integer state = 0
For each move n do:
state = state*CountLegalMoves(state) + IndexOfMove(state,newMove)
End;
You need to allow for players resigning as a legal move, otherwise the reason for termination is unknown.