For some reason, I've wanted to do a project where a whole world of nations battle each-other until one victor stands alone, ruler of the whole world. This post will explain the four steps within this project - 1) setting up the map, 2) starting the nations, 3) letting the nations battle, and 4) finding out which will win.Step one is to get a good world map off Google and then create a 2-D array storing which pixels are sea and which are land. You should thus look out for those very sparse maps with just two colours and no text or PNG artifacts. In my case, I wanted to do a hexagonal grid, which is a bit of an issue when the world maps are not using hexagonal pixels. I just offset every second row of pixels, which does sometimes create strange, spiky coastlines, though this is more apparent in the image exports than in-game where the spikes are only half a tile big.Step two is to set up a new array which stores the owner of each tile. My program then picks a couple thousand random tiles each frame, then runs a script for each. If the tile is unowned (as they all are at the beginning), first we try to find a nearby tile that is owned, so that this one can be gobbled up. If there is no nearby owned tile, there is a chance to instead spawn a new civilisation, which will then gobble up nearby unowned tiles in the next steps.This is what we see in the above animation - just random nations taking up random territories. This creates quite interesting shapes, and since some nations are spawned before others, we also get widely different sizes that feel pretty natural. And then, the world ends as all unowned tiles have found an owner.Step three is wars and politics. At default, all nations are at peace. All nations also have relations with all other nations. Whenever a border tile is picked in the above script, the relationship between the two nations worsens. If it gets bad enough, the superior nation might declare war on the inferior nation.Step four is to find out who wins in a fight. Whenever a border tile is picked in the above script, and the two nations are at war, the tile will be taken over by the opponent. But working like this, wars would, on average, be in a stalemate with only random chance to put one nation as victor. We need a skewed chance, so that it is most likely for the superior nation to take land off the inferior than vice versa.It would seem obvious just to have the nations compare their size. However, this would mean that larger nations always win. This might be logical and realistic, sort of. But also boring.Let's talk about wealth.While a nation is at peace, it builds up wealth proportional to its size. Larger nations will accumulate more wealth than smaller nations. While at war, nations will lose wealth as they struggle for dominance. The nation with more wealth will win each battle 90% of the time. But winning a battle does not mean winning the war. Winning territory costs more than losing it, so eventually, the at richer nation will have less wealth than the other, and so the tables turn. This will happen up to several times in a single war, and at the end, unless a nation is wiped out completely, both will end at less than 0 wealth and sign a truce. Still, usually the superior nation takes territory from the inferior one.Let's talk about aggressive expansion.As territory changes hands, one nation gains territory and the other loses it. The game keeps track of this and can tell how much aggressive expansion a given nation has accrued. Recent territorial expansions do not add more wealth during peace-time. They also worsen relations with all neighbours. This leads to quite interesting scenarios.So you have nation A attack nation B. Both nations lose most of their wealth, but nation A started out with more and thus accrues both territory and aggressive expansion. As nation A now is poor and has lots of aggressive expansion, its neighbours might declare war on it. Now A fights a three-pronged war, losing resources even faster, both wealth and territory. Perhaps B even takes back some of its lost territory. Perhaps nation A goes into debt and eventually collapses.This is what is shown in the timelapse above. It leads to the rise of empires that then are taken out by coalitions of several smaller nations. It leads to a system where larger nations tend to do better than smaller ones, but nothing is certain.Still, the game is quite simplistic, and the whole relationship system could do with a makeover. But I am quite happy with finding a balance between "biggest nation wins" and "size don't matter."