XMLGameEngine

An engine for describing games built around Xerces, exprtk, and SFML.

View the Project on GitHub beefviper/XMLGameEngine

12. The collision escalation problem, and trading-card-game style resolution

Status: idea under design; not implemented

The problem

The more entity types and abilities a game has, the more collision rules must be written: roughly n x m for n types and m other types (n squared in the worst case). The author thought this was named in the VGDL literature as a scaling problem. A literature search found no source that calls it “collision escalation”, but the mathematics is a well-known one: the binary method problem, handled by double dispatch or multiple dispatch, where even the tidiest mechanism still needs n-squared cases somewhere. A relative, the expression problem, has the same shape for types crossed with operations.

What existing systems do

The author’s idea

Replace (sprite x sprite) rules with (class x class) or (verb x state) resolution over a small, fixed vocabulary and fixed steps, the way a trading card game resolves a new card against existing ones through shared vocabulary and phases.

Worked model: Super Mario Bros.

Mario has states (small, large, fire, dead; or 3, 2, 1, 0 hit points) and direction. The steps:

  1. Declare. Mario, moving down, sends the verb stomp chosen purely from his own state.
  2. Respond. Each thing answers the verb from its own class and state alone: a goomba returns dead and the interaction ends; a koopa returns shell and changes its own state; a spiny returns hit.
  3. Counter phase. hit moves the engine to the next phase, where Mario resolves it against his own state: Invincibility if the star is active, otherwise he takes the hit.
  4. Bookkeeping. Balance any values and apply the next rule set.

Neither side needs to know the other’s concrete type, so a new entity costs about v rules (one per verb it responds to or emits) instead of n. v (the verb alphabet) must stay small and roughly fixed while n grows. This is better than classic double dispatch, which still routes through concrete type pairs.

Points raised while stress-testing it:

Translation to XMLGameEngine

Entities declare classes or tags (the existing class attribute is the anchor). Interaction rules key on (classA, classB, phase) rather than (spriteA, spriteB). A new entity tagged Hazard and Pushable inherits every rule already written for that pair of tags. Honest cost, as with MTG: the taxonomy of tags and phases becomes the hard design artifact and is painful to retrofit.

The engine today is at the first rung only: class and object filters on a collision rule (06, 11).

Second batch: alternatives

Sources