As a change from work, I've whipped up another small applet that deals with the simulation of complex processes. In this instance, I have tried to model the growth and spread of fantasy races over a world.
The display is split in two halves. The left displays the "Resources" value of the individual cell. "Resources" is a generic term for everything living, sapient beings require to survive and prosper - food, ores, and so on. The higher the Resources value, the higher the population the cell can support. The Resources value goes down when there is a high population to strain it, but up when few people live in that field. The right displays the individual population of the cell - the brighter the color, the more people live in it. Below that display is a field where you can enter a numeric value that allows you to adjust the general brightness of the display. In the beginning of each simulation, 1.0 is a good value, but later on you might wish to enter higher values.
This program models three distinct races:
Orcs (Red): Orcs multiply fast, are highly mobile, aggressive, and good at warfare. Unfortunately for them, they are lousy at resource and food management - they soon deplete any area where they hold sway.
Humans (Green): Humans have average-ish values at everything except warfare, where they are worse than the other races.
Dwarves (Blue): Dwarves are excellent at warfare and resource and food management, but they take a long time to grow in numbers and move around only slowly.
The "Reset" button returns the simulation to its starting point - four population centers are distributed randomly across the map for each race. When you click on the "Calculate" button, the simulation performs 10 calculation steps and then repaints the displays.
What usually happens is that the orcs rapidly multiply and overwhelm all small settlements of other races close to their starting points. But soon, their reserves are depleted, and once the humans have established larger settlements, the tide is turned and the humans slowly but surely dominate the map. The dwarvish settlements are terribly vulnerably early in the simulation, and the dwarves don't survive in all simulations. But once they have established a solid population base - either by being far away from any orcish starting points, or by being equally distant to both a human and an orcish settlement, they can prove to be almost impossible to dislodge.
I think this was pretty fun for a few hours of work, and I will probably try to expand it in some way in the future. Things I plan to do:
Add some more text fields where you can enter the individual values for the different races. This is trivial in terms of programming skill, but it would take more time than I wanted to spend at this stage.
Add some "relapse times" to the simulation - once a certain area has been depleted, I want to let it stay depleted and depopulated for a time. I think I will look at my old notes from my thesis project involving heart cell simulations (they had similar mechanisms), and reading up on predator-prey cycles in biology might be useful, too. This should add some real dynamics to the simulation, instead of the fairly "static" battle fronts...
Come up with some way to create distinctive "resources" terrain, like it can be found in the real world - and possibly different types of resources as well (grains versus ore versus wood...), which are good for different things (feeding the population, making more effective weapons to boost the ability to wage war...).
Come up with a way to graphically display more than just three races. Three races is easy - one for each primary color. With more, creating a simple color display gets much more difficult...
Rewriting the graphical display so that it updates continually - having to click on the "Calculate" button all the time gets boring, and I suspect there are faster way of displaying things than using the "fillRect" command twenty thousand times... I don't know enough of Java to know how to program this (this is only my third program, after all), but I will have to learn how to do this one day anyway...
Any other suggestions for expanding this simulation?
(Remember that, as I said, it will probably take me some time to reply this weekend...)
Comments
I'm glad I have those books.