## September 11, 2019

### History XIX: Cliodynamics II

Continuing from here.

I'm still a little confused how Turchin's original spatial simulation could collapse at all, given an $S_\textrm{crit}=0.003$. Theoretically, this implies a frontier of 3 to a total area of 1000. My calculations indicate that this could be achieved by a circular area of radius 666 (oddly enough). Which is absolutely enormous. In his real-world simulations, he implements a restriction on what constitutes a frontier space, and this makes much more sense in terms of generating low $S$. Adjusting $S_\textrm{crit}$ doesn't help much: even at $S_\textrm{crit}=0.02$, the theoretical empire is three times the size of Europe before it undergoes spontaneous collapse.
A few more changes to implement before the next run:
• Mountains and rivers make $S$ decay more slowly.
• Cities can now send settlers as soon as they reach a population of $2P_0=300$.
• However, only hexes which derive at least 25% of their infrastructure from the parent city can be settled. This forces a condition where capitals must be dependent on growth from their satellite hubs at a certain point.
Let's see how these do.
 $S$ in red; $A$ in blue (hinterlands in light blue dashed, cities in darker blue dashed)
 $P$
One interesting thing I noticed right away was that the population of the largest cities (and then the kingdoms) quickly stabilized. No fresh blood was available to work the fields, and all resources were efficiently distributed with no surplus. No new cities could form because of the rules listed above. In the absence of mechanisms to shake up the existing power structure, the hegemony remained in relative status. $S$ and $P$ fluctuated somewhat, based mostly in this case on fluctuations in the population of the largest city moving around a transition point.

Because my cities are grown from scratch, there is a practical limitation on how soon they can "meet" and create metaethnic frontiers. In almost all cases, a hegemony is surrounded not by other hegemonies, but by the wilderness, which should certainly provide enough danger to increase collective solidarity.

However, a random troll in the wilderness is not as dangerous to society as another hegemony who might be eyeing your infrastructure and resources. To this end, I can consider increasing $S\to0.25$ or a similar value in cases where the frontier is not a metaethnic border but a wilderness border.

How does that help?

Better! Interesting that $S$ begins to increase as the total $A$ does - it looks like this is when Mengj starts to bump up against other competing hegemonies.

More things to try:

## September 9, 2019

### History XVIII: Cliodynamics I

I have recently been reading up on cliodynamics, which is the application of mathematical models to historical population sociodynamics. If this sounds familiar, that's because it's exactly what I've been doing for the last few months. So it's good to put a name on it.

One thing that particularly interests me is the theory of social collapse. This is something that's been missing from my own work, try as I might. I think that cliodynamics might be able to help me answer this question.

In one of his models, Peter Turchin defines a measure called asabiya, which is an Arabic term implying social cohesion. Turchin applies this in a simulation by logistically raising the asabiya of a hinterland/border cell to 1, while internal cells exponentially decay to 0. If the average asabiya of a whole hegemony reaches a critical value, the entire thing collapses. $S_{t+1} = S_t + r_0 S_ t (1 - S_t)$ $S_{t+1} = S_t - \delta S_t$
The effect of this is that empires should only last about 200 years on median, which is much closer to the real world than the massive empires I've been dealing with. Once a critical mass is reached, my empires last...forever. There's no real pressure to collapse, barring a random extinction event such as a plague.

Another paper in the same vein explores secession and hierarchy elements in a manner that is very similar to mine. So I'm happy to synthesize it into my body of knowledge.

However, I still need to account for the size to asabiya feedback mechanism. In all these models, the size of the polity $A(t)$ is part of a larger model which is affected by $S(t)$ (the asabiya), or even the metaasabiya $R(t)$. My own $A(t)$ is determined by the growth of cities and their infrastructure reach.

Therefore, I'm going to pull in another model developed by Turchin to correlate population $N$, state resources $S$, and internal warfare $W$. This provides a way to "hook into" the $K$ carrying capacity mechanism and thereby connect the two models. In particular, we have: $\dot{N} = r_0 N \left(1 - {N \over k_\textrm{max} - c W}\right) - d N W$ $\dot{S} = \rho_0 N \left(1 - {N \over k_\textrm{max} - c W}\right) - b N$ $\dot{W} = a N^2 - b W - \alpha S$
So as population $N$ varies, it will affect total area $A$ and therefore $S$ (I don't know why he uses the same variable for asabiya and state resources).

The question is how to discretize this function. The model as given is a hegemony/polity-level equation, governing the total state. Therefore, I have to scale W to the individual city:$\dot{N_i} = r_0 N_i \left(1 - {N_i \over k_{i,\textrm{max}} - c W {N_i\over\sum_j N_j}}\right) - d N_i W {N_i\over\sum_j N_j}$

I also don't have to collapse the entire hegemony at once if the critical point $S_{crit}$ is reached. Normally, secession is controlled by a loyalty variable. I'll still maintain this, but I'll also make secession likely to happen if the average asabiya is below the critical point, regardless of loyalty score. This will cause quick collapse if the empire overextends itself but also provides an opportunity for it to "recover" after that collapse.

First: some testing of the basic asabiya concept. I'll run the model as normal, while keeping track of what the asabiya should be. Then examine which hegemonies should have collapsed. The only change I'll make to the normal model is to suppress other collapsing mechanisms such as surrender and secession.

Initially, I thought that I should use the area-dependent asabiya model: $S_{t+1} = S_t + r_0 \left(1 - {A \over 2 b}\right) S_ t (1 - S_t)$ to account for the size of the polity. This proved to a very strong feedback effect to the point where $S$ decayed to its end-state nearly immediately.

Examining the largest hegemony (the Thav empire) using the non-area-dependent model:
 S (red), A (blue): over time
It quickly becomes clear that there is an effect introduced by Turchin's simulation space which accelerates empire demise. Here, the asabiya of this large empire does not drop even close to the $S_\textrm{crit}=0.003$ value which provides Turchin with such historical variation. I believe this to be due to a few factors.

In these early stages of implementation, there is still no feedback from $S\to A$. Therefore, there can be no collapsing mechanism as $S$ enters a positive (and mutually destructive) feedback loop. There are a couple of places I can connect this loop. The first is in terms of warfare escalation. If the power differential between two hegemonies is above a threshold, it becomes more likely that the stronger will invade. Individual hex power is defined by the following equation: $P = A \bar S \exp(-d/h)$, where $d$ is the distance from the capital and $h$ is a drop-off factor usually equal to 2. We can average this for every hex in the hegemony to determine the $\bar P$ for the hegemony. In the case of Thav above, $\bar P = 4.72036$. This will also be interesting to examine over time to see if it's useful anywhere else.

The largest hegemony during this 500-year run is the Winan empire:

The jump in $A$ appears to be directly attributable to the expansion mechanic kicking in around 335. All of a sudden, the few (4) cities that Winan has conquered begin pumping out colony cities. This dramatically increases the reach of the empire, which has a detrimental effect on $S$. From this and the Thav simulation we can see that it takes between 300-400 years for a city to grow to expansion size (under the current rules).

Of course, there is no law in the real world that demands that settlements refuse to send out settlers unless they have more than 5000 people. But these rules are justified elsewhere on this blog.

Looking at overall power:

There's a slight bump during the initial expansive "golden age", but this quickly returns to what appears to be a pretty steady number. The interesting thing is that $\bar P$ appears to be steady regardless of the continued movement of $S$ or $A$.

The other place is in the infrastructure spread calculation. Remember that as cities grow, they spread their influence, creating new borderlands for the empire (and eventually butting heads with other empires). What if this growth (already affected by terrain) were also affected by the power of the city in question? More powerful cities could spread their influence further and vice versa. In addition, when Turchin applies this model to real-world conditions, he imposes an additional constraint that regions must experience a certain amount of cultural conflict to be considered true "frontiers." For example, linguistic and religious borders contributed to this intensity score. That shouldn't be terribly difficult to implement. I'll try these next time.

Through all this, I feel very much as if I'm exploring an actual history. Although it's shaped by my own decisions and preconditions, on net it's stochastic to feel alien. And that's pretty cool.

## August 9, 2019

### History XVII: Cradle of Civilizations

I have been working mostly on updates to the code. Now it runs a little smoother.

To this point, I've been randomly placing cities across the map. Because each race has a highly preferred climate, this usually means that, e.g., elven cities will all end up in roughly the same place. But occasionally there will be a city placed far across the map, on the other side of the world.

I'm not, for the moment, interested in creating a grand mythology. They're cool, and maybe I'll work on some lore at some point, but for now it's irrelevant. However, I do wonder if a single-origin point for each race wouldn't give even more verisimilitude.

The first settlement (for each race) will be randomly placed. Each subsequent city must then be a specific distance from an existing settlement. This can model expansion from a single-origin point.

If the initial city is not in an optimally desirable location, then migration should naturally occur up towards those optimal locations.

Seems good-ish so far. I think the city generation ought to be a bit higher to account for the additional constraints.With this model, none of the races would have met another "civilized" race yet after 1200 years.

Whether that's likely or not is up to the discretion of the reader.

Yes, yes, I know that Stranger Things is responsible for "helping revive" mainstream interest in D&D.

Who cares?

The people making money off of D&D, of course. The hobby is not significantly enriched by this.

In fact, it's hurt.

This is the same effect that brought us the vapidity of 5th edition, reinforced by high budget dramatic productions which pretend to play D&D.

Stranger Things S3 is no different. Its heavy-handed lip service sends the message that this way to "play" is not only acceptable, but desirable.

All season long, Will wants to play D&D with his friends, who are increasingly mired with girl-problems. When he finally gets his board and story set up, he is able to force them to sit at the table. Conveniently hidden from accountability behind his screen, he railroads their characters through his plot with the subtlety of John Henry's hammer.

In the Stranger Things game philosophy, the players must dance to the DM's tune. There is no opportunity for the players to make choices. Only false choices can be presented, otherwise the "game" (of course, it's not really a game) is ruined.

Fed up, Mike makes a choice. And it's a good one! To save the village (why do they care) and become heroes (which, of course, is the only possible outcome of this so-called game), they must defeat the zombies. Mike decides that the best option is to ignite the room they are in, killing the party but also the zombies and living on forever as heroes.

Of course, in the grand scheme of the season, this is a signpost to the climatic scene. But more importantly, it's a deviation from the Supreme Overload Will's script. "You can't do that!" he whines. Why not? It's the only meaningful choice the players have made!

Without these meaningful choices, the game is not a game. It's just a series of guesses to see which way the DM wants the party to go; and never fear, you can't guess wrong. Sure, you have "agency" as long as you select from the following pre-approved list of actions.

Don't worry, you can't make the wrong choice, because all roads lead to the same point.

## July 16, 2019

### Resources XXI: Aurochs

The auroch was a breed of very large cattle which went extinct in the 1600s. Rather than a generic "cattle" reference, I want to use them for a bit more exotic feel.

Since we have no live aurochs, I'm going to use stats for the Indian gaur, another very large taurine, as my base.

An auroch calf weighs about 50 lbs at birth. Based on current calf prices relative to gold, a reference of gold can purchase 15,000 head of calves. They are found in A/B/C Koppen climates.

A calf is economically useful after it's been weaned, which for aurochs is approximately 8 months. During this time, there is already a material upkeep cost because the mother's milk is gradually being replaced by solid food. This is factored as an upkeep cost even if the animal is largely grazing, because any forage the auroch gets off my land is potential food I can't grow and sell; it is a sacrificial investment. Overall, this works out to 483 pounds of food, selected by the lowest price available in the region.

Once the calf is weaned (about 200 lb), its food uptake is significantly increased. The animal will eat about 2% of its body weight per day for the next 2 years and 4 months (more or less). This is 23,679 pounds of food up to its full weight (2,500 lb).

Each of these costs is mixed with the labor of local herdsmen, which increases the cost somewhat. However, herdsmen are usually in good supply and so the added labor cost is generally low.

This makes a full-grown auroch quite valuable (depending on the cost of feed). This cost will be used to determine the local costs for meat, leather, horn, and bone glue (and perhaps other things, but these are the most important for now).

Looking at the city of Kwazfulnis (population: 3896 dwarfs, 795humans, 237 halflings, 101 elves): you can get a calf for about a copper; but a weaned calf will cost you 28 sp, and a fully grown beast is 141 gp!

It's possible these prices don't make sense. I feel like every time I look at my base commodities table I see another mistake to correct. But I'm making slow progress, and I'm more concerned that the system work flawlessly (or good enough) so that updates/corrections can be made more easily.

## July 15, 2019

### Trade V: Money Makes the World Go Round

The fantasy economy runs on gold.

But gold is rare.

Yet trade still manages to happen. How?

My world is very disconnected. There are many separate networks which do not interact at all: the tech level is too low, the roads haven't been built, the markets aren't connected.

Many places do not have any gold at all.

But they have silver.

So what I've done is check each sub-network to see if gold is available. If it is, all is well. If not, we move to a silver standard. If (and this is more rare still), silver is not available either, I fix the price of chalcopyrite, since copper is a Stage 1 good (gold and silver are both Stage 0). If copper is not available, you're out of luck; for now anyway. If I add another precious metal it should be easy enough to go back and add it into this selector. So eventually, everyone should have something to base a coinage economy on.

I do think it might be worth it to adjust the rarity of gold. In the iteration I'm testing at the moment, I have 10 gold mines for 17,290 settled hexes. That's an occurrence of about 0.058%, whereas gold should be around 0.3%. Of course, there is more gold...it just hasn't been found yet. In reality, it's a little higher than the target, around 0.5%. I think I'll add a stronger effect on desirability since gold is so important.

## July 10, 2019

### History XVI: Loyalty

Based on a comment by Scott.

Each new settlement begins with a loyalty of 0. This score will increase or decrease over time, stochastically.

Positive effects include: being the capital and being surrounded with other cities of the same hegemony.

Negative effects include: being of a different race than the capital city, being in an enclave, and starvation.

A low loyalty will not immediately incite rebellion. A negative loyalty will, however, make it possible, and lower the bar to rebel. Because the score moves semi-randomly (nudged by the factors above), it's possible for a town to pull back from the brink, as it were.

Cities which are conquered have their loyalties reset to 0. Previously, towns would trade hands and rebel constantly, and a kingdom would put down a rebellion only to have it erupt again the next year. With the loyalty score, that behavior is still possible, but tempered. Depending on the random outcome, peace and order may be restored, or not.

This can also have effects during war. A disloyal city, faced with the threat of attack, will simply surrender.

Speaking of war, I fixed a "small bug" where nations would claim to be at war and then not do any actual fighting. This is odd because the normal way of doing things today is to do a lot of fighting and then claim to not be at war at all.

## June 26, 2019

### Detail VI: Lakes

Adding lakes was easy once I decided that I wasn't going to approach the beautiful detail of Undiscovered Worlds. All I need is a representation of a concept (which, at its heart, is the essence of a map anyway).

Low-quality lakes are easy to make. All I do is find where two rivers meet, then expand the lake around that point, flowing into any lower hexes. Usually, this means I end up with lots of long "lakes" which simply follow the river. This is a side effect of the terrain generation.

Still, small inconsistencies in the system are outweighed by its usefulness (and can always be addressed later). I can search over my 20-hex world map, find a place that looks interesting, and generate it quickly in detail.

One thing that inevitably comes to mind is just how much of this country is wild...but at the same time, there are a good number of scattered villages. How much conflict happens here between the humanoids and their encroaching civilization and the intelligent creatures who want to stay put? A good deal, I'll reckon. Not to mention, with a couple good scouts in your party, you might be able to hide from the law here for years. That's a lot of area to search.

I do have plans to implement a suggestion from Scott and blend the terrain edges together more smoothly.

Now if only I could get a proper SVG to PNG export...Inkscape is ok for some things but my installation has proved miserable when it comes to applying filters and blends.

## June 21, 2019

### History XV: A Feebleness Bereft of Breeding

There remain a few mechanics to topple empires that I haven't yet tackled. The next one on the list is the Plague.

For now, "plague" is intentionally vague. In modern parlance, the term generally refers to the three kinds of disease spread by the Yersinia pestis bacterium: bubonic, septicemic, and pnuemonic plagues. The properties of each are different, so for now I want to think about a general model for plague transmission of infectious diseases. Diseases which may cause epidemics but are not usually transmitted infectiously, such as cholera, are also interesting but can be tackled separately.

Alexis addresses some initial thoughts about a player catching disease (or building up a town's resistance to such) here. As a town's infrastructure rises, the individual's chance for becoming diseased grows, to the tune of $I \ over 10000$. For a settlement of $I = 474$, the chance would then be $0.0474\%$. That's not so bad. In addition, this is just "disease." That's pretty broad. Let's place the chance of contracting actual plague at 0.2%, on top of the chance to contract any disease. That makes the overall chance really low, 0.009%.

Like anything else you might care to learn about, the amount of research done on the subject is staggering. Consider these sources:
Even from just these, a clearer picture emerges of how to model such an event. Particularly, a set of equations (the SIR model), which always interests me. ${\partial S \over \partial t} = B - {\beta S I \over N} - d S$${\partial I \over \partial t} = {\beta S I \over N} - \gamma I - d I$${\partial R \over \partial t} = \gamma m I - d R$, where $S$ is the susceptible population, $I$ is the infected population, $R$ is the recovered population, $N = S + I + R$ is the total population, $B = 0.4$ is the birth rate, $\beta=0.5$ is the contact rate, $d=0.4$ is the death rate, ${1 \over \gamma} = 26$ is the infectious period, and $m=0.33$ is the mortality. By tweaking these parameters (this particular set is for bubonic plague) we can model different kinds of diseases when we wish.

I don't really care about $B$ and $d$ since these time steps are usually modeled in days and I step history forward one year at a time. So all the calculation will take place in a single fell swoop. ${\partial S \over \partial t} = -{\beta S I \over N}$${\partial I \over \partial t} = {\beta S I \over N} - \gamma I$${\partial R \over \partial t} = \gamma m I$. This generates a curve that's quite nice when modeled with the above parameters, for a city that begins with a population of 32,210 and a single infection:

That's pretty devastating.

The plague then spreads to a neighboring city, which must make its own save against infection. And the cycle repeats. A city could shake off the plague but then get it again from a neighbor. This makes a death spiral possible to wipe out an entire civilization.

....Now having done all this work, it occurs to me that the fancy equations are irrelevant. The only way to be removed from the pool entirely is to die...which means that the only calculation necessary is $N_1 = \mu N_0$. Huh. However, the full calculation can still tell me how long the epidemic lasts, in order to spread it to other settlements over more than one year. Plus, it might be interesting to know how many total are infected in case the party is caught in the middle of an epidemic.

Somewhat anticlimatic.

## June 19, 2019

Roads are easier than rivers because they do not shape the terrain they "flow" through as rivers do. I thought they would be more complicated but they turned out to be quite simple.

The river ingress and egress hexes are found by doing a transform on the character values of the strings of the names of the hexes. This gives a nice stochastic but repeatable location. For the roads, I simply reverse the inputs. Badabingbadaboom.

The roads (which are defined at the 20-hex level) enter the hex and make their way to the 1-hex with the highest infrastructure, which is located on the river and is assumed to be the settlement center. Where there are no roads, there are trails. Trails may or may not be well maintained, and they are not suitable for significant trade. But they allow transportation of goods and supplies to and from remote outposts such as mines which may not have access to a main trade road. Again, these trails all seek the assumed central hex.

Trails are also defined at the 20-hex level to connect settlements with low infrastructures. Generally speaking, a road will only occur through a 20-hex with $I\geq 50$. An exception is made if the road is being laid (and maintained) from capital to capital. Therefore, trails are used instead to connect lower $I$ settlements as well as provide access to hinterlands.

 Darker hexes are less civilized, road in red

As a note on the trade system: only 20-hexes with a road can have a market. If your settlement has no market, you'll have to travel to find one. All goods produced in a 20-hex without a market must find their way down a trail to somewhere they can be sold. Therefore, for the purposes of the system, these goods are credited as being produced in the market settlement, even though their physical location might be different. My trade system engine assigns them to the market which is closest in the network.

This raises interesting gameplay situations. Most people in these remote locations would either make their own tools or carefully guard something they took a specific trip to buy. Very rarely would a merchant make their way down these dangerous and unfriendly trails to sell their wares. Plan accordingly.