First Cities

So I had a go at building a model based on the idea that trade range determines city size.

In each town there are some people (the size of the circle represents how many people live there). There are 5 resources. Four of them can be harvested from the environment. The fifth needs a combination of three others to be produced. Each town gets a bonus to one type of resource (the colour represents which bonus it gets, green is food, the others are red, blue and grey).

Each town has an infinitely deep market. So you can make something and sell it immediately, with the price falling a little. And you can buy anything you like, any time, with the price rising a little. This circumvents the problem of arranging barters.

Every turn each person does the most economically profitable thing for them. So either they will produce something and sell it on the market. Or they will trade by going to a neighbouring town and buy something and bring it back and sell it for a profit. They will then spend the money on as much stuff as they can afford, prioritising food. The more of their needs are filled the happier they are.

Once in a while a person will look around and if the average happiness in another town is higher than the average happiness in their town they will move to the other town.

The model runs super fast (like hundreds of turns per second). This video shows some runs with trade factor (how much you can trade with your neighbours) going from 0 (no trade) to 8 (super high trade). As you can see at first the people like to live in the agricultural areas (though this is partly a glitch) and this represents hunter gatherers. However as the trade factor increases trade (represented by grey lines) starts to become important and then dominate. The population starts to cluster in places where all the resources are available.

I am not very happy with the outcome, it’s a bit odd. I think it might be better to explicitly program in these relationships rather than “go in blind” and have each agent be selfish. The advantage of this model is that it is the product of many selfish agents and could make a good basis. The idea was that you would be able to interfere as much (authoritarian communism) or as little (libertarian capitalism) as you liked with the people in your area. There could be banking crises and trade wars and inflation problems etc.

See what you think.

1 Like

I like how it is not predetermined and shifts with changing conditions.

I don’t like a few of them how the cities(??) would stutter in size from very large to very small. To make the economy more dynamic and the population more spread out, you should try limiting each town to having access to two or three resources, and only a few that have population above X can produce the fifth. This would make a supply-demand economy.

The limitless market is a good idea, but how did you make the probability that a trader would buy it? that the next town over sells it for more? That it is way below market average? That there is a shortage on the other side of the continent?

Additionally, have you yet considered how the planet might play into interstellar trade? it exports surplus and imports shortages the same way as the town-scale?

One last question, how does population factor in? is it dependent on existing population size (directly or inversely), food surplus?

I do like the thought you put into this, I really do, and the animation is a great demonstration.

And I just realized this post was almost 2 years old.

Sorry for any inconvenience.:grimacing:

No problem, if you have something to add to any topic feel free. It’s much better to update old topics and have all the discussion in one place instead of always starting new topics and splitting all the information.

@rastro thanks

I’m not sure about whether cities should have a limit on how fast migration can happen into or out of them. For example there were gold rush boom towns which grew quite big quite fast and then disappeared as soon as the gold was gone. There needs to be some sensible limits but over a long time period things can oscillate quite a lot.

The way trade was determined was that each person would do whatever activity would get them the most money. So either they would produce a resource and sell it to the market. Or they would buy some resources off the market and use them to produce another resource and then sell that. Or they would look at the neighbouring cities and the price difference on a resource and would buy from the neighbouring city and sell to their own city. They would do whatever netted them the most money.

Yeah I think that interstellar trade would be much the same as city to city trade.

I can’t remember exactly how food worked. I think it did nothing to the population (the population was fixed for the world as a whole and they could only migrate from city to city (which changed to size of the circles)). I think food was the thing everyone would preferentially buy and they would only buy other stuff once they had food.

True, the gold rush left a lot of ghost towns, but the people who migrated there for the Gold stayed in the California Territory, and formed California.

Would traders consider just the immediate city neighbors? or would they consider all cities on the planet?
Like if there is food aplenty in one part of the world but not enough in another, would they make “the long trip” to make a bigger profit?

I could try making a formula for population growth that takes into account multiple variable like food demand and supply, climate (by latitude), and existing population.

Yeah that sounds like a cool idea.

I think in general, if there are traders in each city, then there actually isn’t a difference between having them only look at neighbours vs look far away. If there is a price gradient between city A and city Z which are far away then this will translate to a small gradient at each of the steps along the way which will cause each trader to move goods locally down the gradient. I could be wrong but I think, over time, the flow of goods will be pretty much the same.

It’s basically a scalar graph where the gradient causes goods to flow.

1 Like

That is a lot clearer, but only because I know what a scalar graph and a gradient are.

So the overall answer would be “yes”, just to clarify?

Okay, I will start on that sometime next week, and when I’m done, should I put that just here or is there a special place for game formulas?

In terms of cities I was looking at some procedural city stuff for an unrelated project and came across this http://cgchan.com/store/scenecity

It looks really interesting. I like the paradigm of placing roads first and then buildings around the roads. Here’s some thinking out loud about city generation.

In terms of actual city building gameplay I think the problem is much more complicated if you build things over time (build some buildings, then build some roads, then build some buildings, then knock down some old buildings to make room for new ones etc). This is how cities skylines or sim city works. It makes it much harder for the ai to build a city because it has to factor in a lot of different things when choosing where to add each building.

Being able to generate each city in one step (add all roads then add all buildings) means that it’s much easier to write the algorithm. I guess maybe if we started from the same seed on the same terrain then maybe a generated city of 20 buildings would look quite a lot like a generated city of 5 buildings had organically grown into it. I guess maybe there’s some way of putting the list of buildings in historical order and then generating the city so monuments always end up in the same place.

It would be very powerful if all you had to do was maintain a seed and a list of buildings and a one step algorithm could generate the city in such a way that if you changed the list of buildings a little then the city would change a little. That would mean we could have cities that naturally developed over time and changed architectural style as a civilisation evolves. I think the above piece of software makes me feel more positive that this is possible.

1 Like

So I finally had time to work on population growth mechanics, and I think I have the basics so far.

Without resource consideration, the formula would be
Pf=P0 e^rt where r is the growth rate (which depends on a species individual aspects), time (which from one computation to the next, would just be 1), and the initial population before the computation, P0

But that’s exponential, we need logistical;
dN/dt= r max N(K-N)/K, where N is number of individuals, K is carrying capacity, and r is similar to the above.
What I was thinking, so that it can be used for multiple species, is that the latter formula be used to define the amount of biomass available (food), and K being calculated as biomass produced locally + biomass imported (either from other cities or other planets), and r can be derived from the K and N values, but I haven’t nailed down exactly how as of yet.

I will continue working on the population models, and would not mind input.

I have some questions:

  1. where do this equations come from? are they from some existing model or are they made by you? give us some background about them.
  2. what is carying capacity? the amount of available biomass?
  3. what are you maximizing in the second equation?

I apologize if some or all of this questions are dumb :confused:

Not at all dumb, those are routine questions.

  1. the base formula is almost a copy-paste of an already derived mathematical formula for exponential population growth.
    the second formula is an elaboration on the first which takes into account the carrying capacity, so that a graph curve goes up exponentially, then upon reaching an inflection point (about halfway to the carrying capacity), it smooths out to meet with the carrying capacity.

  2. carrying capacity is, logistically, the number of individuals a given environment can support. The number is affected by things like predation, disease, availability of prey, and die-offs of food sources like famine or overpopulation. It’s more of a down-up model, where things that boost the base (like increased wheat production) boost the predators too (more wheat> more bread> less starvation). Similarly, things that harm the base (famine) harm the top (more starvation and deaths).
    Biomass is just a generic term that should be able to fit most species. If one species needs less biomass than another, they can have more people with the same food resources.

  3. its supposed to be r sub max, the max r rate. This being the growth rate, that is. Not sure exactly how I’ll do that as of yet, still hashing out what affects r and how. The computer doesn’t do annotations very well…

Did that answer your questions? If not I can elaborate more to clarify.

Oh ok i understand now i think.
r should probably not be derived from N and K (at least not directly), and instead should rely in biological and socio-economic factors (of which we’ll probably have tomes of information by the time we use population growth mechanics).
Also i dont know if this model can be applied to both cities and natural ecosystems, since the first ones tend to have a stable population (due to agriculture) and the second ones a cyclic population (prey gets more population which makes predators get more population which kills off the prey which reduces the predator population).

r is independent of N and K.
But r is multiplied by N, and limited by K, but r does not have N or K in the calculations (nor will it).

The second one is more for cities, and otherwise stable populations, and you’re right, it does become cyclical. But that’s how biology and evolution happen, so…

r will probably be based on birth rate when we figure out exactly how we cover that, life span change (longer life span increases population), which is based on medical tech, excess food to better feed people, movement of people, disease, etc. still figuring that out. (r is by far the most complex component of this model…)

i just remembered @Seregon made this.
http://thrivegame.wikidot.com/crash-course-in-population-dynamics-abridged
it might be relevant

actually yeah that does cover a lot of what the population modeling involves.

As you can tell by @Seregon’s post, the modelling takes in a LOT of factors, and trying to make a general formula that can include anything involves even more factors from reproduction type, to average size, to metabolism, to diseases and war, to average births per X…

I didn’t know that page existed, huh…

1 Like

Hey Rastro - it’s good to see someone working on this - let me know if you ever want to discuss any of it. I’m rather busy this month, but hoping to spend more time on Thrive from October.

1 Like

I’m aiming to make a formula that gets the population growth in the same ballpark as humans (1~2%), then just fine tuning from there based on how big of an impact each aspect would have.

The formula would be for the r max=growth rate.

K would depend more on the health of the planet in early stages, then rely more on agriculture (or equivalent) in later stages. I was just gonna use the arbitrary unit “biomass” until we flesh out creatures more

So I’m just trying to get r around .02 using various factors and coefficients and such.