Building your first model
The fastest way to learn is to make a small one yourself. Open the + New model button in the library; you'll get an empty world.
1. Add an agent type
Open the Code tab. Under Agent types click + Agent type. Rename it to creature in the inspector.
2. Give it a property
Under creature, click + Property. Call it energy and set default to 50. This is the expression that runs once per agent at setup; you can put anything DSL-shaped there.
3. Add a setup rule
Under Setup rules click + Rule. The default rule body is empty - replace it with:
create_agents('creature', 30)
Now click Setup. Thirty agents appear, scattered randomly.
4. Add a behaviour rule
Under creature → Rules click + Rule. Body:
self.heading = self.heading + random(-20, 20)
forward(1)
self.energy = self.energy - 1
This is a classic random walk with energy decay. Click Setup, then hold Go - you should see your creatures meander around.
5. Add a die-off rule
Under creature → Rules, add another rule:
when: self.energy <= 0
do: die()
That's the whole loop: agents wander, lose energy, eventually die. From here you can plot population over time, add food patches, give creatures the ability to reproduce - whichever direction you want to take it.
Everything described here works in the live editor. Open Stigmery and follow along.
Open the app →