8

Imagine we're creating a multiplayer dungeon crawl (a roguelike) using FP where we emphasize pure functions and immutable data structures. We generate a dungeon composed of rooms, corridors, heroes, monsters and loot. Our world is effectively an object graph of structures and their relationships. It sounds to me that for our hero to even pick up a coin, we have to recreate the entire world. That is, our hero now has a coin he didn't have and our room now lacks that coin. Thus our hero and our room structures are both augmented to reflect the change (for memory efficiency we reuse the original structures in as much as possible building on top of them, similar to how we would cons a new item onto the head of our list in Lisp). Additionally, every structure that referenced our hero or the room must now be amended to reference the new structures.

Is this a correct mental picture that every modification causes our entire world to be reconstructed?

I am trying to mentally model how making this simple world change could be made as simple as possible.

It occurred to me that structures in this object graph should not hold direct references to one another, that these direct references (touches) will all have to be amended when the referenced structure (object) is changed. It seems like holding indirect references via ids or keys might be better.

Can someone paint a good mental model for how these whole-world changes are most efficiently handled?

0

0

Browse other questions tagged or ask your own question.