Got some chores done once kids were at school. Lots of work-related chatter. Did three or four hours over the weekend so took it easy. Feeling less sore today, so did three circuits of the 7-minute workout while listening to a podcast. Eggs, toast and coffee for lunch while watching an episode of The West Wing (now that I’ve caught up on the podcasts I need to watch a few episodes again).
Thinking about rules. Lots of thought experiments, like having magnets that repell a ball. What happens when a ball-magnet pair face each other with a gap in-between? There are three possibilities.
- One ball wins, which blocks the other ball from moving. This isn’t ideal, because it breaks the assumption that all rules are processed in parallel. Why would one win?
- Neither ball wins (we detect there is a conflict, which causes both rules to fail). This isn’t ideal, because there’s an obvious gap for the balls to move into.
- Both rules succeed, and the two balls begin moving towards each other. But then both rules are reverted (because of the conflict) and they move back to their original position.
I like this last solution, as it yields the intuitively correct behaviour; the balls will wobble back-and-forth. The magnets have an obvious and consistent effect on the world, and the world rule of one entity per cell is visually not violated. It implies rules having multiple states, and the engine updating between rule transitions. Things like sound effects could be triggered by the rule beginning to execute, by the rule succeeding, or by the rule being rolled back. That should give a lot of expressiveness to the engine.
Another thought experiment is an NPC that has four rules, each telling it to move in a different direction. In this case, only one rule can succeed, as they are all attempting to move the entity. Essentially the movement command requires exclusive access to the resource. It’s fairest to select one rule to win at random, meaning NPCs will get random (brownian) movement for free. Nice.
Apart from movement, there aren’t too many commands that require exclusive access to a resource. Really just movement and mutating a register.
Final thought experiment is back to the magnet-ball rule, where the balls are adjacent, with another rule that adjacent balls de-spawn (in a fiery explosion), with magnets strategically positioned to push the balls apart. What should happen here?
- The rule to explode the balls beats the rule to move the balls, and so they explode.
- The rule to move the balls beats the rule to explode the balls. and so they move.
- Both rules fire, so the balls explode while they’re moving.
Again, this last case seems intuitively correct. The rule to explode the ball simply de-spawns both balls (which plays an explosion animation), and triggers an explosion sound effect. The rules to move the balls still fires, but the entity engine can handle moving an entity while it’s de-spawning, so there’s no conflict to rollback.
All of this comes naturally when we think of the 3x3 grid as providing context to decide if a rule should fire, and the rule itself then issuing a series of commands (such as move entity and so on), rather than the rule mutating the 3x3 grid (which is what the user may see when editing rules, but not what the engine works with when executing rules).
Anyway, that’s a bit of a thesis. Hopefully things will solidify somewhat over the next day or two so I can begin coding this up.
Jack had school photos today. I cooked bolognaise for dinner. Full from overeating! Dzung and Jack watched Australian Ninja Warrior. Eliza practising her viola. Just a regular Monday night.