2 ms·
Immutability gives you elegant command-query separation, and it's sometimes useful (for example you can use the same function in physics, and in AI to predict w
by ajuc 12y ago
Immutability gives you elegant command-query separation, and it's sometimes useful (for example you can use the same function in physics, and in AI to predict where player will be in 5 frames). Of course you pay with performance.
I wonder if keeping a tree of game states in persistent variable (like Clojure datastructures) could help with that.
We could keep the current state as a root of game states tree, AI code will calculate possible future states a few steps ahead (these future states would mostly share memory with parent and sibling states, and if we predict n frames forward AI can start in each frame from states in step t+n-1 and calculate their immediate kids only). This is trivialy parallelizable BTW.
And in each frame game engine would move the tree root to one of the kids depending on player action, culling the previous root and the branches not taken from the tree.