In order to attract skilled and wealthy citizens to your settlement, it is necessary to construct neighbourhoods with access to various goods and services. Examples include food, water, healthcare, access to religious facilities, and (crucially) beer.
Whether or not a particular building has access to a given service is determined by whether it is regularly visited by the associated worker. For example, a trader from the bazaar will roam the neighbourhood, delivering food to any house she crosses.
However, these workers do not wander purposefully; a bazaar trader will not seek out houses, nor will she avoid those she has already delivered food to. She will instead execute something of a random walk, constrained to the roads connecting the bazaar to the houses.
This stochastic behaviour means that junctions tend to decrease the efficacy of your workers; the greater the number of forks in the road, the greater the number of opportunities for the bazaar worker to get lost. She may end up missing a house, passing the same house twice, or walking into an industrial district!
So let’s say you have a bazaar at one end of a road and a house at the other, and some network of roads in-between the two. What is the probability of the trader reaching the house? In this post, we’ll look at a particular family of road networks and see if we can come up with a generic expression for the probability of traversing a member of it.
In the following, we’ll make a few assumptions (which are not necessarily reflected in the actual mechanics of Pharaoh):
- on reaching an n-way intersection, the trader chooses any one of the branches with equal probability 1/(n – 1), excluding the branch on which she approached, which she chooses with probability 0;
- the trader will wander forever until she reaches either the house or the bazaar, at which point she will stop.
Let’s get started!
In this first case, we have a single road connecting the bazaar and the house with a single three-way junction somewhere along its length. We will assume that nothing special lies at the end of the branching road, so that, if the trader reaches the end of it, she will simply turn around and walk back towards the junction.
The case of a single T-junction is simple, in that the trader can only take a finite number of paths before stopping. There are only two ways she can reach the house:
- walk along 1 and reach the junction; choose 2 with probability 1/2; walk along 2 and reach the house;
- walk along 1 and reach the junction; choose a with probability 1/2; walk along a and reach the dead end; walk back along a and reach the junction; choose 2 with probability 1/2; walk along 2 and reach the house.
We can denote the paths above with the following condensed notation:
It is fairly easy to see that the total probability of the trader reaching the house is
The first term is the probability of the trader going straight across the junction, the second the probability of her being diverted by the junction, but choosing the correct path the second time she encounters it.
You can see things are now substantially more complicated. With the introduction of this single additional junction, the trader is suddenly able to take infinitely many paths, since she can spend as much time as she likes moving back and forth between the two junctions before finally committing to the road toward the house.
Rather than writing out an exhaustive list of all possible routes the trader can take, it is much easier to evaluate by recycling our result for the single T-junction. We established that the total probability of the trader passing through a T-junction was 3/4. For simplicity, then, let’s replace our junctions with little black boxes, which allow the trader through with probability 3/4 and send her back with probability 1/4.
What now are the possible (simplified) paths? The trader can:
- Pass straight through both black boxes, each with probability 3/4;
- Pass through the first black box with probability 3/4; be reversed by the second black box with probability 1/4; be reversed by the first black box with probability 1/4; pass through the second black box with probability 3/4.
In the third path, the trader is turned around four times, in the fourth path six, and so on. The total probability of her reaching the house is thus
The infinite geometric series is not too hard to evaluate in general:
So the trader’s chances of reaching the house are reduced a little by the introduction of the extra junction. Let’s go further!
I won’t bother writing out the possible paths this time; you can easily imagine the complicated paths the trader can take. We’ll play the same trick as before, and draw a black box around the first two junctions, which we have already established allow the trader to pass with probability 3/5, and one around the third junction, which allows her through with probability 3/4. The logic is very much like that in the preceding case:
Nice! So, after adding and multiplying all of those factors of 1/2 behind the scenes, we end up with 1/2 again!
You might have noticed a pattern starting to unfold here:
This progression is strongly suggestive of the following general expression:
How can we prove our conjecture? By induction, as we’ll see in the next section.
Let’s start by assuming that the probability of the trader passing through a series of n junctions is indeed 3/(3+n). We want to show that, if this assumption is true, it necessarily follows that the probability of the trader passing through n+1 junctions is 3/(3+(n+1)): this is the basis of proof by induction.
We proceed as we have done in the last two cases: we put a black box around the first n junctions, and a second black box around the additional junction. The probability of the trader passing through the first black box is 3/(3+n), so the probability of her being reversed by the same black box is 1 – 3/(3+n) = n/(3+n). Hence, the probability of her passing through n+1 T-junctions is
Bingo! With this result, we have shown that:
- if ;
- if ;
- if ;
and so on and so forth. The final step in the proof is to show that is indeed 1; if we can do that, the probability for every other value of n follows automatically from the above! Happily, that is obviously true, because if there are no junctions in the trader’s way, she is guaranteed to reach the house. Therefore we can state categorically that the probability of the trader reaching the house separated from the bazaar by n three-way junctions is
This result is just the tip of the iceberg. You can easily imagine more complex road networks between the bazaar and the house containing (say) four-way junctions, loops, branches with branches, and so on. Try analysing some for yourself: maybe you’ll discover some elegant equations of your own!