Showing posts with label History. Show all posts
Showing posts with label History. Show all posts

December 12, 2019

History XXII: R&D

I have long been fascinated by the Worlds: History project. Go check it out.

One idea I'd like to steal gain inspiration from is the discovery system. People groups have chances to learn new technologies over time (or even lose them). It's quite comprehensive in design if not fully filled out.

I love this. Conceptually, it should synthesize with my existing tech tree, yielding at least the following benefits:
  1. Prehistory is now possible; Year 0 doesn't necessarily start with the first city, and every polity doesn't begin with a city/settlement.
  2. Tribes/polities should be able to migrate more rapidly, reaching more area of the planet's surface.
  3. Technology will be different in different areas. This already exists but is fairly deterministic, based on population density. If your density is X, then you have agriculture, for example. This is captured by the tech level.
The downsides? It's a whole 'nother branch of work for me in addition to all of the research I'm already doing. So it might be useful to build it as a toggled mod. Additionally, DrTardigrade is working on timescales many factors larger than mine.

November 13, 2019

History XXI: Cliodynamics IV

Of the tweaking of parameters there is no end.

I've had to suspend some of my own disbelief regarding civilization decay. For the most part, the simulation runs best if civilizations are allowed to grow to their fullest extent. Cliodynamic pressure can collapse a state but not (by itself) remove them from the map.

I also implemented a few changes for armed forces. Recall the distributions of the ages for each race. Each hegemony is then given a standing army based on the number of civilians between the ages of 15 and 50 (relative to human lifespan). This number is further reduced by 50% (since mostly males will fight), 10% (not all will be fit to fight), and 50% again (not all are willing). This article was helpful. Each year, the army is appreciated by new recruits and depreciated by those who die in battle. I'd like to find a way to depreciate retirees as well but without a cellular automation I'm not sure how just yet.

This significantly speeds up the battle simulation as a new military calculation is not required for each battle. In addition, armies can depreciate to the point where they are no longer viable. The amount of troops able to be concentrated at a single point of attack or defense is as follows: \[H = {A \over c} L(d)\], where $A$ is the army size, $c$ is the number of violent conflicts the hegemony is embroiled in, and $L(d)$ is a function of the distance $d$ between the capital and the point of battle. $L(d)$ encodes the army's logistical ability to supply distant points. Large armies can reach further but require additional support. \[L(d) = {1 \over \left({1 + {1 \over s}}\right)^d}\], where $s$ is the support parameter $s=2.82$.

One thing that becomes immediately apparent in the early years is the small troop sizes. A hegemony of approximately 10,000 people may only be able to support an army of 1000 or fewer (and that's at maximum $H$). In the first few hundred years, battle numbers are commonly in the dozens of troops, not thousands.

I tweaked some of the secession mechanics as well. I'd really like to implement some promotion and linearization but I have to think about how best to implement it and whether or not it'd be too computationally expensive. Currently there are still some issues where polities will either fracture into a billion competing hegemonies or glom together into massive, continent-spanning empires.


It's interesting that most polities haven't been able to stick around long enough to reach higher technologies. Most of them end up staying around Tech 6 or 7, which is barely past animal husbandry; a party in these areas would be hard pressed to find any kind of good gear or even wealth. But I suppose glory is always there for the taking.

October 17, 2019

History XX: Cliodynamics III

Continuing from here.

Recall these equations: \[\dot{\log N} = r_0 \log N \left(1 - {\log N \over k_\textrm{max} - c W}\right) - d \log N W\] \[\dot{\Xi} = \rho_0 \log N \left(1 - {\log N \over k_\textrm{max} - c W}\right) - b \log N\] \[\dot{W} = a \log N^2 - b W - \alpha \Xi\], where $N$ is the population, $\Xi$ is the power of the state, and $W$ is the intensity of warfare.

Turchin's original works don't make it very clear that these are log-scaled numbers. I decided to track this discretely for each individual city, so I imagine there will be a handful of second-order effects.

This does result in some pretty intense cycling.
$S$ in red, $A$ in blue
The total area fluctuates over about 200 years, while the $S$ lags that pattern slightly. I'm trying to think of a good way to tie $W$ or $\Xi$ to $S$, so that internal conflict will not arise when $S$ is high and collective solidarity is strong.

However, an error in the code (neglecting to restrict $k_\textrm{max} - c W$ to positive values) resulted in a situation where populations skyrocketed to billions of people in a single city.

Fixing that error introduced another artifact where it was extremely difficult for any significant hegemonies to arise and stabilize. The largest city topped out at less than 1500 inhabitants: barely a village.

The timescale is appropriate at about 200 years. But we want something more in terms of population, especially if we want the PCs to be able to have steel weapons and access to higher forms of magic such as wizardry and bardic training.

With some work, this could be tweaked to account for the longer lifespans of different races, if that's a thing in your game. If your elves live to 1000, their empires are more likely to last around 2000 years instead.

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.

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 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 18, 2019

History XVI: God Gave a Loaf to Every Bird

The famine mechanic is killing city development. As it should! However, it's too much. Nothing can develop past a few thousand people. Since rural population is dependent on infrastructure, neither can ever increase to the point where actual substantial growth is possible. And that's with a very generous assumption that it only takes 2-3 farmers to feed one urban dweller. Some estimates put this as high as 9.

We want a situation where some settlements can grow and others die out, or where a settlement can be cut off in time of war.

As a "temporary" stop-gap, I've increased the population density significantly in rural areas. This gives you more food-producers. However, starvation still does restrict nation formation. I haven't found a case yet where starvation will completely wipe out a civilization, but it proves significant in politics in the following ways:

Starvation naturally reduces hegemony morale. It can affect it so much that when a larger nation comes knocking on the door, the food-restrained nation acquiesces without a fight. But this in turn can cause problems for the conquerors, who have possibly bitten off more than they can chew.

In addition, hegemonies with very low morale (but no war) are much more likely to experience secession, as cities with large enough infrastructure may feel they're better off striking out on their own. They may or may not be correct.

All of this makes for a complex interplay of resources and politics.

It is very interesting how, watching lines grow in a text file, how I tend to anthropomorphize these collections of bits. I feel national pride swell when a city throws off the yoke of an oppressor, or defeats a stronger neighbor. Let's tell a story.

Menesesese was an elven city founded in 645, in a jungle climate. They named their new civilization Menese. Although they would experience a few major disasters over the years (in 857, 1289, and 1401), they lived in peace with their older neighbor, another elven city called Moterure, which had been founded in 24, six centuries before. By 1543, Mote had founded 8 more cities down the coastline, stretching down to Menesesese.

However, in 1613, Mote attacked and defeated Menesesese, incorporating it into their growing kingdom. This would last until 2185, when Menesesese rebelled, forming the Menesesese hegemony again (I need to add some code so the rebellious hegemon will take its original name, Menese, not the name of the city, which may have prefixes or suffixes as it does in this case).

From 2195-2198, Mote and Menesesese would fight over the cities of Ritikerure, Chorcliste, Mieprure, Wenafrure, Interure, Chorvetek, and Chordmose. Unfortunately, Chrovetek was totally destroyed during the First Mote-Menesesese War. Although Moterure itself did not fall, nearly all its cities now lay in the hands of the Menesesese...-ese. Mote would starve and shrink over the next 50 years.

In 2258, relations again deteriorated, but this time Moterure was more than willing to accept Menesesese rule. Alas, this peace too was not to last, as Mote would rebel only nine years later in 2267, taking with them the cities of Magirure, Neferirure, Savcerure, and Raprurure.

Over the next 1600 years, this story would play out again and again. Cities were destroyed and castles built. As I write this, the simulation is in year 3950. The Twelfth Moterure-Menesesese War ended in 3882. And it surely will not be the last.


This provides me a rich tapestry for a game set around this region. There is plenty of wilderness space, but even the loosely populated landscape is dotted with ruins, reminders of the hatred between these two nations that spans three millennia. I know where all the battles were fought (and where great generals might have fallen and grand items lost), where the ruined cities are located (and where the ghosts of the slain still wander). There are old elves who still fought in the last war...there is peace now, but for how long, they ask? Never trust a Mote. You better be careful not to look too Menesesese in the Neferirure market.

And all of it out of whole cloth.

June 12, 2019

History XV: It Might Be Famine All Around

A hegemony's capital (or largest cities) should be limited by the amount of people they control (hence the working classes ability to keep them supplied).

Currently, this is limited by the carrying capacity, $K$. Therefore, the upper bound on $K$ will be affected by this control.

Assume that $P$ is the population of a city. The farmer ratio $\alpha=3$ can be defined in this case as 3 farmers necessary to support 1 other individual. I'm leaving this as a variable, not a hardcode, because this number is very dependent on who you ask and what time period we're talking about. Therefore, the number of people required to support a city of population $P$ is \[n = \alpha P\]. How many people do we have available? Assuming 100% of the rural population is involved in food production (a bad assumption, again something we can change), then we just need the total amount of rural people in that hegemon $P_r$. How many of those are available to send their goods to our city? If the total urban population of the hegemon is $P_u$, then our city will demand \[{P \over P_u}\] of the resources. This means that only \[{P P_r \over P_u}\] are specifically available to it. We can compare this number to the needed number $n$, and see that \[K_n = \min\left(K, {P P_r \over \alpha P_u}\right)\], that is, if there is enough manual labor, then the city can realize its full potential.

I grabbed a random capital to use for this, Chivenkare. Chivnekare has a population of $P=49920$, and $K\sim55000$. So it is a good test case. It has a good number of cities spread over a large island. Givne this, $n = 149760$. We find that $P_r = 177865$. Already we see danger signs, as Chivenkare is not the only city in its hegemon. However, $P_u = 85887$, so ${P \over P_u} = 0.58$, there may be hope yet.

Ultimately, we find that $K_n = 34460$, meaning that a huge famine is imminent. Sorry, fellas!

This implies a few things for the overall simulation:

  • Cities cut off from the major area of the hegemon will starve and collapse. This is true regardless of the diplomatic relations with the hegemon which surrounds it. Resources are scarce.
  • Hegemons at war could collapse very quickly as food runs out, even if they are technically winning overall. This would be a cascading collapse.
  • Another cascade could be precipitated by an unrelated catastrophic event.
  • Land will be a premium. My automata are not "smart," because they will not seek more land; but those unable to acquire it, spreading influence, infrastructure, and gaining rural working hands, will quickly perish. This mirrors the historical expansion and collapse of many empires, which outgrew their ability to feed themselves and were destroyed in short order.

June 7, 2019

History XIV: Here I Stand (Summary)

I thought for a bit on how to present a total overview of the system (suggested by Ted), but there are so many moving parts. Still, it's good to sit down and think about it a bit.


This ought to help in keeping things straight. Or perhaps it makes it even more confusing.

It's clear there are several feedback loops: most notably that the city growth rate is affected by the overall tech level of the hegemony. This provides a significant obstacle to small starting cities, but gives a boost to established empires. The loops keep things interesting. In addition, many of these links involve some randomness, which means that things will generally tend in the same direction each time I run the whole simulation, but it's never going to be exactly the same.

Desirability is a value, expressed as a percentage, which describes how desirable a piece of land is for settlement. Each race prefers a different arrangement of terrain and weather. The desirability value will affect how large a settlement can arise in a hex, and also captures the number of resources available there (whether or not they are being totally utilized). Because the resource allotment code adds complexity and time to the history simulation, the desirability is used as an approximation of resources in the battle simulator (since a settlement with access to more physical resources will have an inevitable edge over their adversary). Raw desirability is the desirability in the absence of civilization; it is mixed with infrastructure to obtain a measure of desirability for city expansion, when an existing settlement sends out settlers.

Infrastructure is an integer which describes the effect of settlements on surrounding terrain. Although the Tao only uses elevation to limit the spread of infrastructure, I also include local effects such as forest or desert. I also make infrastructure "flow" downriver easier than upstream. A high enough infrastructure (over 400, for now) changes a forested hex into plains or grassland, depending on the local climate (which is a feedback element encouraging a more efficient infrastructure spread). A higher infrastructure implies a better training mechanism for soldiers. Infrastructure spreads from every settlement in a hegemony and stops at the border.

Hexes with infrastructure but no settlement are the hinterlands; they are prime candidates for future settlements. Since the hinterlands are populated (however sparse), reinforcements can be press-ganged. Generally, however, their population is very low. The rural population of any hex with an infrastructure value is an exponential function of that infrastructure number.

If the effect of a hegemony's capital (measured in % of total infrastructure in a hex) drops too low, and a city's self-generated infrastructure is high enough (100), then a rebellion is possible.

Available resources (which are fed into the market system, not shown) are acquired by cross-referencing the available resources (which is somewhat determined by terrain) with the resource definitions. Certain resources cannot be extracted by low-tech cultures, but may become available as the hegemony grows.

The Long-awaited GitLab. There is no README yet: I've been working on this for two years now, and so the code is a garbled mess in places and cleaner in others. Eventually I'll get around to some housekeeping. Enter at your own risk.

June 6, 2019

History XIII: Every Manly Heart is Bounding

Not every war is a total war. More often than not, the loser realizes they're fighting a futile war and they surrender. I'll implement a morale score to keep track of this, as suggested by Lance.

Morale goes down when a successful attack is launched against you or a random natural disaster occurs. It goes up when a successful attack is launched by your forces, or you repel an invader. In addition, morale will creep up every year by a small amount.

Because the potential for disaster is very high (0.1% across all cities), and morale is a hegemonic property, morale will tend to drop much quicker than it can rise (absent success in war). This also implies that larger hegemonies will collapse (speaking in morale terms) much sooner than small ones.

If a hegemony's morale (measured from 0-100%) drops below a critical level (10%), it will unconditionally surrender. This is a bit brute force; these surrenders could be very complicated, with vassal states being formed, or a simple exchange of cities, or a total assumption into the conquering kingdom. This latter situation will be enforced, at least until I tackle the vassal state code.

An interesting situation arose where the city of Pawsapa rebelled against the Khare hegemony (a dwarven kingdom of appreciable size) and then destroyed several cities and conquered others, eventually forcing the outlying settlements to declare fealty to Pawsapa instead of Khare. Vieskhare (the founding city) had been established nearly 2600 years before, but a series of natural disasters left her vulnerable to rebellion. A sad story (if you're a Kharen nationalist).

There's also a bug where a large city which surrenders will immediately trigger the secession code and rebel again, forming a new hegemony with a full morale (albeit usually giving up a few cities). It might be a feature instead...

I'm sure I'll continue to tweak the exact values, but the mechanism is at least in place.



May 31, 2019

History XII: I Was a Sword in the Hand-grip

The scourge of perfect vs imperfect information continues.

Wins in blue, losses in red. Number of forces for A and D

From this we see that larger forces win battles, overwhelmingly. That's somewhat of an obvious conclusion. However, we should instead look at the battles which subverted mere numbers.

Ratio of force sizes to ratio of killing rate. Wins in blue, losses in red.

Very rare, and the ones that do have a significant power advantage, as shown by the $\alpha/\delta$ ratio. However, it's also interesting that the attacker can sometimes lose despite a numbers advantage. It's possible to determine a rough set of equations to determine if one has an advantage in both numbers and power, but I'll leave that for another day.

To improve the chance of victory, then, we'd like to do a little scouting before-hand, and only attack if we believe we have a numbers advantage. The quality of the estimation will depend on our hegemony's tech level.

Minor note: at tech level 11, attacking forces will have access to engineering capabilities, and so the effect of a defending castle is neutralized.

May 30, 2019

History XI: The Kingdoms of this World

I need to understand how the secession mechanic is working in practice, so I disabled it to see what sort of empires are built without it. Previously, many tiny kingdoms would spring up with no clear rhyme or reason - a city would be founded and immediately secede against its hegemon. Why so sensitive?

In addition, there's not enough war overall, and the wars that are fought are ultimately pointless for the attacker (with an overall success rate of about 6%, it's unclear why anyone would bother in the first place).

So there are some issues with the battle system, but I'll table that for now until I know what's going on with rebellion/secession. Really, these are secessions, not civil wars; civil wars are waged in the interest of taking over the central government of the entire hegemon, whereas seceding parties usually just want to be left alone. Of course, they are automatically at war either way according to the system.

These problems were addressed by a few tweaks:
  • Cities will secede only if they provide a certain amount of infrastructure to themselves AND they have a minimal (1%) contribution from their initial hegemon's capital.
  • Peace, being preferable to war, is still common. There is only a 1% chance for a relationship to increase above HIIK 0. However, I removed the restrictions on which cities would be attacked - previously only cities which increased the hegemon's overall desirability would be targeted.
  • In addition, attackers will choose their targets a bit more wisely. If they suspect that the defending force is too large, they won't attack. However, I still think this suffers from perfect information. Perhaps this should only kick in at higher infrastructure levels, where the attacking army would have access to advanced intelligence and a better knowledge of the defender's strength.
  • Cities can now be cut off from reinforcements. If an attacker takes all the hexes around a city, or a region, then those armies will have no expectation to be reinforced, and thus begins a catastrophic snowball. It could even result in another secession, depending on the circumstances. Right now, there's no specific incentive for an army to break the blockade by taking a strategic choke-point.
It's becoming more obvious that sub-kingdoms are the way to go if you want to maintain a large empire. Although I haven't worked out the mechanics for it, the only ideas I have so far are 1) conquest and submission and 2) voluntary submission. I would need a mechanic whereby a country would divide itself into administrative districts unprompted. I can use the current numbers, but the details of it elude me so far.

1160 years

May 28, 2019

History X: Wish Not One Man More

I've simulated 16778 battles so far over 1363 years of history. The attacker has a record of 1073-15712. Atrocious! Why the bad record?

First of all, peace between major nations forms too easily! There needs to be more war between these larger entities. Secondly, secession is too volatile. Small cities will throw off the yoke of their much stronger leaders, sometimes immediately after founding. I thought I was pre-selecting sites that were still controllable but something is going funky. The small city then fruitlessly attacks the larger nation. Thirdly, castles are basically unassailable, especially because these small rebel bands are leading tiny armies against them.

There are a few things I'll tackle to address these issues.
  1. Peace is preferable to war, but long-term peace is hard to obtain in this world.
  2. Work on secession dynamics, make it more difficult at the very least.
  3. Don't attack a castle with a garrison many times larger than your own force.
These factors currently lead to a proliferation of hegemonies, many tiny kingdoms in a smallish area. That's ok from a historical perspective and could lead to some interesting effects, but I'd like to consolidate just a bit from a computing perspective.

Click for larger image. Infrastructure numbers in red. Battles marked by black Xs

May 3, 2019

History IX: Notes from the Front Line

Battles take a long time to resolve (when you're trying to manage many cities), and so they're slowing down the whole enterprise. I've implemented a few changes to hopefully make this smoother.

First, only cities with at least 1000 people can initiate an attack against a neighbor. This fixes an "issue" where small tribes would get locked into a constant series of battles so that neither could grow larger than a few hundred persons. This is a fascinating outcome, but I want to see if I can let some cities grow a bit larger so the battles get more interesting. If I can squash some bugs that this rock is covering, maybe I'll remove the restriction.

Second, the rout percentages have been changed to random distributions, centered on 30% losses for attacker and 50% losses for defender. This gives a bit of salt to the simulation.

Third, when an attack is initiated, I have to think broader than just "this little town attacks its large neighbor." The capital city is the one calling the shots here, and so it makes more sense to gather an army and send them to the battlefield, rather than just hoping that the national military will show up and back your power play. This should allow more decisive (and "strategic") victories, as much larger forces will be able to overwhelm smaller intermediate cities.

Fourth, I've implemented treaties. When two nations drop from HIIK 1 (dispute) to HIKK 0 (no conflict), they can agree to an armistice for a certain period of time: about 5-40 years. This mechanic is also triggered after a drop from HIIK 4/5 (limited war/war) to HIIK 3 (violent crisis). During the armistice, both nations are at HIIK 0. After the armistice ends, the normal transition mechanism resumes. This should reduce the overall number of wars and allow nations to gain some strength before plunging themselves into mutually destructive conflicts.

May 1, 2019

History VIII: The Long Arm of the State

How far does influence extend?

As empires grow large, it becomes difficult to control the extremities. Eventually, it collapses under its own weight. There are several mechanisms to describe this, but first I'll concentrate on the physical size of the hegemony.

As of the last running of my history simulator, the largest hegemony (Drudny) covers 785 cities. It's massive, and contains a huge number of people (around 64M) when both rural and urban populations are considered. For comparison, the zenith of the Roman Empire had around 90M people and the equivalent of about 5500 cities/hexes of area. Based on that, I think my population equation is somewhat skewed.

An empire of this physical distribution would be nearly impossible to maintain given the restraints of the fantasy-tech level, where technology and travel are severely limited and magic is rare. The degree of control that the capital city $i$ has on a given city $j$ located $\delta_{ij}$ days away (not necessarily the straight line distance) can be quantified by the following metric: \[C_{ij} = {P_i \over \delta_{ij} ^ n}\], where $n$ is the distance modifier, usually 2. Values for the Drudny hegemony range from 32531.15 (right next to the capital) to 11.32 (over a month's travel away).

How much of a "rebellion index" does this number represent? It's difficult to say. The best way forward for now is to fix a number and test it out. A Monte-Carlo by fire. A city with $C_{ij} \leq 25$ is susceptible (not automatically!) to revolution. A value of 25 means that a city of 1000 can reliably control hexes up to 6 days away, and a city of 25,000, about 30 days. For these threshold cities, the chance of revolution each year is 25%, which would lead to a revolution within 25 years max if the situation is not resolved.

This obviously leads to the conclusion (as many empires reached throughout real history), that a massive empire is best controlled with some measure of decentralization. China solidified itself with jùn and xiàn; Russia with oblasts; Rome with provinces; Wales, with cantrefi. This decentralization would ensure that every city maintained the threshold score. I will need to think more about how to implement this later.

So far I have not had any empires grow large enough to experience a revolt.

April 16, 2019

History VII: Blood Alone Moves the Wheels of History

The simulator is working pretty well, so I took a few moments to make a nice historical snapshot. This image represents the growth of settlements over 2700 years. It's rotated so that north is to the left, to get a good view of the central continent.


There is a large band of civilization right in the middle. This represents the Cfb Koppen climate, so a European-type climate, where the jungles of the equator give way to lighter forest.

After 2700 years, the oldest empires are:
  • Delig, est. 1, population: 1,303,170. The capital city is Hvatfar (pop. 2,103). The largest city, however, is Jakom (pop. 28,001). They produce mostly agricultural products but have access to iron and copper ores and coal. Delig is a small halfling kingdom, with only 8 cities. Deligfar itself, the founding city, stood until 1030, when it fell to disaster (disease or natural disasters).
  • Tilaj, est. 1, population: 2,128,289. A dwarf kingdom, Tilaj is much bigger than Delig, with 31 cities (but hence a lower density). The capital city is Nzuavjuab (pop. 3,229). The largest city is Limai (pop. 13,839). Tilaj mines silver, iron, and copper. Tilajp lasted until 1701, quite a run.
I haven't run the full trade network yet, so I'm not sure if this will change, but notice that neither of these empires have access to gold or steel (which requires manganese and nickel). This will severely limit the trade abilities of these ancient peoples.

The largest empire is:
  • Popach, est. 3, population (human): 11,064,595. The capital is Tepwyð (pop. 151 - really??). The largest city is Dwrzwie (pop. 20,806). Comprises 176 cities. Again, no gold! Perhaps I should place a very high emphasis on gold during city placement.
The largest city is:
  • Ldwia, est. 2058, population (human): 69,402. Part of the Umidyl hegemony. Ldwia is due for a crash - they are far above their carrying capacity.
All told, there are 716,318,766 persons accounted for. That's a lot, especially for the short amount of time, but remember that I've got 5 races, not just one.

I like the war simulation so far, but the transition matrix does not account for empire minded cultures. The chance of a Cyrus the Great arising (20 year campaign) or an Alexander the Great sweeping across the world, moving so fast he appears to be flying, is very low. And perhaps it should be. But we have many examples of this type of thing in our own world, so I would imagine it could happen more often here. Perhaps there might be a special mechanic where a great leader arises and pushes the boundaries of the empire without suing for peace.

I'd also like to incorporate more bloodless politics (two kingdoms joining in a confederation or an empire) or more bloody politics (secession or balkanization). All things in time.


April 8, 2019

History VI: It Is Well That War Is So Terrible

The enemy said, 'I will pursue, I will overtake, I will divide plunder, my desire will be full of them, I will draw my sword, my hand will destroy them.' - Exodus 15:9 LEB

The Heidelberg Institute for International Conflict Research (HIIK) defines 6 levels of violence intensity between nations.

lvldesc.
0no conflict
1dispute
2non-violent crisis
3violent crisis
4limited war
5war

Levels 0-2 are non-violent, while 3-5 are escalated into actual conflict. This fascinating paper gives me a great set of models to use to predict conflict between nations [1]. For example, a variable for "border conflict" $C$ can be used as a "bad neighbor index": \[C = \sum_1^n x_i p_i,\] where $n$ is the number of bordering nations, $x_i$ is the previous year intensity for nation $i$, and $p_i$ is the percent of border shared with nation $i$. This paper [2] takes it a step further by providing a transition probability matrix between peace and war!

However, Hegre's robust model only transitions between no conflict (0-2), minor conflict (3), and major conflict (4-5). So I can use this to create a full transitional matrix between the 6 levels (using my old friend Inverse Distance Weighting).


After a bit of testing, that seems like it transitions way too quickly. My tests devolved into war within 10 years. Guess that's possible when everyone is super touchy. Let's try something more fundamentally based.


That does a little better. Doing a few tests shows it has a nice spread leading up to war, between 70 and 280 years for 5 tests. Perhaps it could even be modified per nation. Some are naturally peaceful, some are naturally expansionist. It is quite obvious from even a few tests how massively the matrix affects behavior.


At creation, every nation will be at Level 0 with its neighbors (barring circumstances like a secession from the parent hegemony, in which case it would already be at war).

However, this transition matrix is situationally agnostic. It doesn't know how much border I share with that crazy king who's always eyeing my silver mines. It doesn't remember the bloody civil war in which my people were brutally defeated but still nurse their wounds with undaunted pride and opportunistic ears. So while this system can add some substantial random salt, it's not the end all be all. We need a few more mechanics and numbers for that (rebellions, treaties, overall population contentment, confederations, etc). But for now we will assume that war is only governed by this single mechanic.

If two nations are at war, they will seek to capture the bordering city which has the highest raw desirability.

Now, how do two nations actually fight? There has been some work done about this from a game design perspective, but I'm particularly drawn to the Lanchester equations. These are very simple equations which describe the attrition rates of two armies of size $A$ and $B$ at battle: \[A'(t) = - \beta A(0)^{2-n} B(t)\] \[B'(t) = - \alpha B(0)^{2-n} A(t)\], where $\alpha$ and $\beta$ are the combat effectiveness of $A$ and $B$ respectively, and $n$ is the attrition parameters. $n=1$ is the linear case, where one solider kills one soldier, but $n=2$ is the square case, more applicable to modern warfare. It also turns out that when a defender is fortified, the attack attacks linearly, while the defender defends with the square law. This makes sense intuitively - it is difficult to take a position. So how do I use this in my game?

First I need to determine the raw number of troops. I'll pull random low percentage (3-6%) from the rest of the country to determine a standing army size, and 5x that from the attacked hex. This includes both urban and rural populations (right now, my rural calculation is 5 times the infrastructure number but I don't like this and will address it soon).

Potential issues: it doesn't make much sense for the entire standing army to reinforce a single city in every case. It may not be strategically important, or it may be the fortress upon which the whole balance hangs. There's no way to know, and I'm looking for verisimilitude, not accuracy.

Consider the following free cities:
  • Wienw, population 559 (rural 11,670), founded 3604. Militarization rate: 5.6%. Total military: 2,860.
  • Aedcad, population 6,694 (rural 31,110), founded 3325. Militarization rate: 4.9%. Total military: 1,742.
Aedcad attacks Wienw but is met with a much larger defending force (Wienw gets a boost because it's being attacked). To figure out who wins and how many troops are lost, I need a measure of $\alpha$ and $\beta$. If one side has steel swords and the other has bamboo canes, it almost doesn't matter how many people you have with canes. Technically, I can get numbers for weapon availability by leveraging the market system, but I can't computationally afford to do that every simulated year. So instead, I'll use the desirability and infrastructure indexes, which are updated regularly. The theory being that resource availability yields a higher desirability, and a higher infrastructure gives you a better mechanism to train your troops. For Wienw ($\alpha$) and Aedcad ($\beta$), this gives \[\alpha = {0.7368 \cdot 103 \over 10} = 7.589\] \[\beta = {0.5242 \cdot 21 \over 10} = 1.101\] The indexes are averages of the entire hegemony (which in these cases is only one hex) and they are divided by 10 to bring it into a reasonable range. A soldier from Wienw can kill almost 8 enemies before he dies, but an Aedcadian can only manage around 1.

The solutions for the above equations are too long to display here, but suffice it to say that Aedcad was soundly defeated (using $n=1.25$). Defenders will hang on until they have lost 50% of their troops; attackers will break off if they have lost 30%. Aedcad (red) loses 528 men in the attack - a costly battle, and Wienw (blue) only loses 467. Because these are single cities, it's easy to just subtract the casualties; in the case of larger hegemonies, all cities will lose some in proportion to how many they supplied.


However, as robust as this may seem, I don't know if it will be fast enough to use as my primary engine of war. I'll have to run some tests with some non-linear solvers. But otherwise, it's a fair start.

Potential issues: why would Aedcad attack Wienw in the first place, given Wienw's military and numbers advantage? However, we have information that Aedcad does not: perfect information on the likelihood of a victory or loss. Until we salt the system, Aedcad will always lose this battle. It's just a question of by how much. I'd also like to create some castles/other fortifications, because these are gameably cool, would most likely be built in highly contested areas, and would give a significant defensive boost.

References:

  1. B. Boekestein, “A Predictive Logistic Regression Model of World Conflict Using Open Source Data,” Air Force Institute of Technology, 2015.
  2. H. Hegre, J. Karlsen, H. M. Nygård, H. Strand, and H. Urdal, “Predicting Armed Conflict, 2010-2050,” Int. Stud. Q., vol. 57, no. 2, pp. 250–270, Jun. 2013.

February 27, 2019

History V: The Darkness Dwells in Durin's Halls

I nuked the dwarfs.

The problem had something to do with how the carrying capacities were calculated. Due to the dwarves geographical blessings, they generated massive cities and huge numbers for infrastructure, allowing them to spread much more quickly.

No more.

Darker color = bigger city

Of course, now the human settings might be too high. But such tweaking is still progress.

There are also almost no elves now. Interesting! Part of the fascination of doing this is observing how different parameter combinations generate such unique historical/social outcomes.