I am experimenting with writing a game in the style of functional programming, which involves representing the state of the game with purely functional, immutable data structures.
One of the most important data structures will be a three-dimensional grid representing the world where objects can be stored anywhere on the grid [x, y, z]. The properties I want for this data structure are:
- Unchanging
- Fast continuous update - i.e. creating a new version of the entire grid with minor modifications is cheap and is achieved through structural exchange. The grid can be large, so copy-by-copy is not an option.
- Effective management of sparse areas / identical values - empty / uninhabited areas should not consume resources (to provide large open spaces). Bonus points if they are also effective when storing large "blocks" of the same value
- Unlimited - can grow in any direction as needed
- Fast read / search - i.e. can quickly get an object in [x, y, z]
- The fast volume of queries , that is, a quick search in the region [x1, y1, z1] โ [x2, y2, z2], ideally using sparsity, so that empty spaces are quickly passed through
Any suggestions on the best data structure you can use for this?
PS I know that this may not be the most practical way to write a game, I just do it as a learning experience and stretch my abilities using FP ......
language-agnostic data-structures functional-programming
mikera
source share