October 1, 2018

Demographics V: Battle of the Bulge

I really should have added this to the last post, but I'm kinda locked into my 3-times-a-week posting schedule, and I'm running dry on content while I work out some of the terrain issues. So the 2 real people and the 40 bots that read my page will just have to suffer through this journalistic malpractice.

Anyway, I presented a logistic model to describe the age distribution of a city. In reality, not every place/race will have a bottom heavy pyramid, which is indicative of rapid growth. Low growth pyramids (like many countries today) have square shaped "pyramids," and negative growth shows a bulge.

I wanted to replicate this better. At first, I thought I could just multiply by a shape function to force the distribution to be like I wanted, but there were too many challenges. Eventually, I settled on using polynomials.

But not just any polynomials. To ensure smoothness, I want to use Bezier curves.

Only, Bezier curves are parametric, and I want a function such that $B(x) = y$. Hm. After some searching, I found a way to interpolate between given points as long as they're evenly spaced, using Bernstein polynomials:
\[B^n_k (x) = \sum_{k=0}^n {n \choose k} t^k (1 - t)^{n-k}\]
This polynomial is used to approximate the curve like so, given sets of points $\lbrace x_k, y_k\rbrace$:
\[y(x) = \sum_{k=0}^n y_k B^n_k \left({x - \textrm{min}(X) \over \textrm{max}(X) - \textrm{min}(X)}\right)\]
Easy!

For now, I'm using $n=5$, because I want 6 total points. This will allow 3 control nodes to restrict the shape of the curve.

High growth
Low growth

Decline


It's still not perfect. Nothing ever is. But it should give more realistic results. Given a growth rate regime, I can add some noise to the control points to generate gently varying curves. This takes a little more time to run through in Python than the level generation does, but that's ok. Most of this type of thing can be run on request when the party arrives in a town.

The players will never see it. But I'll know.

Also, I guess I shouldn't be surprised that no one else (that I've found) has worked on stuff like this for their games. Where are the designers? Or are they just worried about the art in their next Point A to Point B splat book adventure?

2 comments:

  1. >Where are the designers?

    Back in 2018 I simulated the population dynamics of a generation starship (a hypothetical type of interstellar ark starship that travels at sub-light speed).

    Since such a ship might take centuries to thousands of years to reach even nearby stars, the original occupants of a generation ship would grow old and die, leaving their descendants to continue traveling. Alas, I did not post the results nor the code in Internet.

    ReplyDelete
  2. By the way, what an interesting blog! Congrats! ;)

    ReplyDelete