Skip to content

Immutability

A key aspect of CentriFuGe is the use of a central immutable state. Whenever a new game state occurs, such as through a move or event, the whole state is copied and new new changes applied.

A benefit of this is reproducible game states. The same move applied to the same state always creates the same resulting state. States can be easily compared to find changes.

A downside is that Godot lacks intrinsic immutable functionality. The idea of immutable needs to be enforced through code writing, rather than at an enforcable fundamental level. It is simple to write some code which reads and writes to the gamestate at any point. Which is why it is important to only alter the game state through Moves, and events via the accessible functions in the GameManager.

It is also why it is very hard to write truely immutable code. A properly immutable function takes in a variable, and returns a copy of that variable.

func immutable_func(data):
    return data.new()
Instead here, the copying is handled by the framework, so that the copy the move function is given is a fresh copy ready to be altered, and then commited as a recorded snapshot afterwards. A plus side is that this way of coding is more in-line with how the rest of the Godot language works, which hopefully makes development still natural without enforcing too many rigid requirements.