Non-player characters (NPCs) are persistent inhabitants of game worlds that are not controlled by players. Rather, their behaviour is determined by a set of pre-scripted conditions created by game developers that evaluate the actions an NPC should take based on the state of the world. NPCs typically take the form of quest-givers and companions enabling dialogue-driven storytelling, vendors dispensing items, or enemies to be battled in combat.
Our game Duck Duck Destruction is a case study demonstrating a pattern enabling players to script decision trees for NPCs and deploy them within an Autonomous World.
Motivation
Our primitive is less opinionated than projects like Gnomik or Sentences, which introduce rule and lore production as gameplay through a dedicated top-down master layer. Instead, our approach allows players to make granular contributions to a world, maintaining its liveliness without disrupting its base mechanics. We see player-deployable NPCs as a conducive medium for collective authorship and emergent storytelling because they enable expressivity and interaction while preserving the integrity of a world's foundational structure.
Mechanics
Duck Duck Destruction is game played entirely by player-scripted NPC ducks that battle in an arena setting. Players program their ducks via decision tree smart contracts, which determine NPC actions as conditional responses to in-game events: “move away from current position if being shot at” or “attack any duck that comes within melee range.”
After a sufficient number of players submit their decision trees, the game host initiates the session. The game then proceeds automatically, with each round prompting the ducks to act based on their programmed decision tree. The game ends with all ducks eliminated, or with the last duck standing.
Contracts
Each NPC script is a smart contract deployed on a MUD/EVM compatible stack. For these scripts to be added to a given world, the world contract requires a register function that allows players to submit the addresses of their deployed NPC smart contracts. This function can be optionally gated based on game progress, ownership of an asset, or a simple address whitelist.
Once a script is registered, the parent world invokes it either directly or as a mediated consequence of player action. Since the MUD/EVM substrate lacks a tick mechanism or another means of autonomously activating the script, it is inherently reactive – any move an NPC makes presupposes a player-initiated action. Therefore, the parent world of the script must incorporate a function call that triggers the NPC script's execution.
Upon being triggered, the NPC script consumes the world state and evaluates a course of action based on its predefined logic and programming.
Applications
Duck Duck Destruction situates NPCs in a fast-paced combat context in order to provide a minimum viable showcase of our primitive's underlying mechanics. With its session-based model, it currently functions as something resembling an NPC nursery, lacking a richer surrounding environment to directly interoperate with.
However, we could imagine the primitive's use in a more open-world sandbox, where NPC reactions are asynchronously triggered through player prompts. An example could be companion pets with programmable personalities that follow a player and uniquely respond to environments and other characters, leading to emergent complexity in their actions. This emergent complexity results in a world that is unpredictable and capable of surprise. An example of what this looks like can be found in Dwarf Fortress, where players stumble upon NPC hippos in sewers they have constructed because their logic determines that an environment containing water is a suitable habitat.
In a world that allows for the deployment of tiered NPCs with access to different sets of actions, players could also collaboratively direct branching quest lines in a chain-tale fashion, where interactions between player characters and their NPCs drive the determination and pursuit of shared goals.
Alternatives
Conceptually, alternatives could utilise player-scripted logics beyond their formulation as NPCs and extend their application to parts of a world's scenery or equipable items. This could be an outpost with flags and decorations that change from clean to deteriorated when besieged by a guerilla faction, or a player-programmed cyberpunk gadget that activates a smoke grenade from the player's inventory whenever their opponent uses a long-range weapon.
While our piece tries to explicitly frame transparency as a generative affordance, an implementation built with zero-knowledge proofs could be leveraged in more competitive settings. An example of this is Topology's Shoshin, which allows players to script and submit combat NPCs with private decision trees. Zero-knowledge stacks such as EZKL, which enable verifiable offloading of computation tasks offchain, also allow for more complex and expressive NPC logics including AI/ML model integrations.
Both of these alternative approaches involve the drawbacks of making chain-tale style interoperability less intuitive. EZKL, in particular, makes the world mechanics less autonomous in the strict sense due to reliance on a proving backend. Nevertheless, we find these alternative approaches interesting as they enable worlds incorporating exploration-as-gameplay, better contributor experience, and possibly strengthened botting resistance.
Extensions
A player initiating the game match of Duck Duck Destruction currently bears the cost of network fees associated with running all NPC contracts registered under it. This could be ameliorated through a dedicated fund contract allowing players to pool resources, or by a gas subsidy model with a paymaster extension.
Acknowledgements
Contract design and engineering by Norswap. Visual asset pack by Tea Strazicic and SFX by Orion Ohana published under the CC BY 4.0.