Gates & randomness
Add Gates and randomness to the Loot and Craft diagram so repeated Plays can produce different outcomes. Every time we hit Play.
So far, our model contains no variability or random elements. Every time we hit Play, the outcome is exactly the same. In this section, we will explain how to implement variability.
Best practice: Real games are unpredictable. Whether because of hard-coded randomness or because players make different decisions, each playthrough will be different. The model must reflect this, otherwise it will be unable to predict all the different outcomes.
Currently, in our diagram, the player is guaranteed to earn 2 wood and 1 stone per minute/step. Suppose instead that the player can only loot one thing per minute/step. I.e. if they loot wood, they give up the ability to earn stone and vice versa. This can be achieved using Gates.
Gates
Gates are resource distributors. They take in resources via their input connection and pick one of the multiple output connections to send them down.
On a Random Gate, the Chance on an outgoing connection sets how likely resources are to travel down that connection (on average) versus any other outgoing connection. In the example above, resources are twice as likely to travel to the bottom pool as the top pool.
In the example above, the Loot Choice Gate acts like a player choosing which item they want to loot. The connections leading out of the Gate and to the Wood and Stone Pools both have a Chance of 50. This means the player is equally likely to loot wood and stone (a 50/50 chance).
Best practice: Players are the most unpredictable agents in any game system. It is best to model their decisions using a simple Random Gate. Only make them act smarter if you’re confident you know how they’ll act.
The setup below shows the same 50/50 split, with a Chance of 50 on both output connections.
Deterministic and Random Gates
A deterministic Gate looks like an empty diamond.

In the Properties panel, the Distribution row switches a Gate between deterministic (an empty diamond) and random (a diamond with a dice). The Gate button in the toolbar also has an arrow beside it to pick a random or a deterministic Gate.

Deterministic Gates distribute resources in the exact same way every time.
Random Gates roll a dice for each resource that passes through them.


If we used a Deterministic Gate in our model, the player would always loot wood and stone in a 1:1 ratio. E.g. after 60 minutes/steps, they would have looted 30 wood and 30 stone.
If we used a Random Gate, there would be random variation in the player’s decisions each step, so that they’re not always guaranteed a perfect 30:30 split (even though an even split is more likely). This is what we require.
Try rebuilding the existing model to include a Random Gate, making the player twice as likely to loot Wood than Stone.
Increasing loot
Suppose in testing out the model, we decide that the pace of looting is too slow, so we increase the amount of loot the player collects each minute/step. As before, we can do this by increasing how much loot is produced by the Player Loots Source.


Notice that resources are treated independently by the Gate, meaning they won’t all travel down the same output connection.
Other ways to add variability
Suppose that the player has other things to do other than looting or that they’re sometimes luckier at finding loot. In other words, the loot they collect each minute/step varies.
To model this variability, we can use the notation “Dx” to roll a dice with x sides each step. In this case, we roll a D10, resulting in the player looting anywhere between 1 and 10 items each step.
You can also write “randomInt(1,11)” to achieve the same result.
Our documentation contains a list of all math.js functions you can use in Formula fields.
Looting Gold
We want to add a new item alongside wood and stone: Gold. This will be used to hire Workers who will help the player loot additional materials from the world.
Try to implement looting gold and hiring workers into the model yourself before continuing.


The player has a chance to loot Gold. Once the player has enough, they can spend that gold to create an extra Worker.
We will build on the Workers mechanic later.