Game Design, Programming and running a one-man games business…

An update on balancing Democracy 4 for longer games

I’ve blogged about this a few times in the past, but basically I use a lot of staring at data and charts to evaluate how well balanced my game Democracy 4 is. Its a ludicrously complex game, and balancing it perfectly, so it plays like chess, is actually pretty much impossible (maybe something for deep mind to tackle next), but its always worthwhile chasing that goal as a more balanced game will mean more replayability, and more player satisfaction, so here we go again :D

The last time I collected stats on the games late game balance was in January and some of the headline numbers are here:

Its pretty clear that there is a problem in that everything gets solved as things go on, and things are too easy in the late game (3 terms on…) so lets look at the data for the current shipped version:

A pretty trivial improvement to be honest. Sure, popularity in term 3 is a BIT harder, but health and education are still pretty much solved problems, and crime is still relatively under control. Unemployment is *not* solved, but this doesn’t seem to be holding people back in either economic or popularity terms :(. Stronger, or more creative measures are called for… But first lets compare the other stats. Old:

and new:

Again, not much change to talk about here. In fact equality has got better! Lets look at the voting stats. Old:

New:

‘Winning’ is an internal hidden measure I use that scales some difficulty-related measures, so the increase there is a *good sign* and shows that some internal hidden difficulty-adjusting systems are working more strongly now./ This seems to have resulted in a bit of a drop in votes in later terms, which is a good thing. Winning with 72% of the votes is still not ‘fun’ but its more fun than winning with 75%. Still… I am being too meek about this.

One statistic of interest is complacency. Its modeled in game based on the happiness of each voter group. If they are massively happy, then complacency creeps in. They take the policy decisions you made for them for granted, and start to expect more. The trouble is, a canny player can keep all the voter groups happy… but not too happy, resulting in an electorate that keep voting for you, because they prefer you to the opposition, without any complacency having an impact…

In the real world, there is definitely a phenomena where people get just ‘sick of’ politicians and political parties. Eventually, the long list of dumb things a specific politician has said, or crisis that happened on their watch, becomes so long that the electorate becomes tired of them, and starts to want change. Here is some data from UK elections:

What I find interesting is that we don’t have many cases where a party wins one term, then gets kicked out. Its almost like once you win an election, the next win is pretty guaranteed, and then it gets a bit harder from then on. The 92 conservative win was pretty narrow, for example.

Obviously there are ‘events’ which influence each election outcome, but it does look like British politics is basically a sine wave, oscillating between center left and center right governments fairly regularly. The US picture is fairly similar:

Basically a regular swing from red to blue and back again, with actually pretty small swings. It really does feel that there is this big block of ‘swing voters’ who are very susceptible to a ‘I am tired of this team, lets back the other team’ mentality.

I guess this could be coded into the game by a steady increase in complacency of the ‘everyone’ group, but that feels a bit hacky. I also think that doing so would really just be papering over the problem, which is more simulation-model based, rather than political. In other words: The player keeps winning, not because the voters are not sufficiently cynical, but because things are actually going really well for them.

In the real world, this is not the case. The US/Germany/UK/Italy have not all collectively solved healthcare, or solved education, or eliminated crime. What has happened is that either the goalposts have moved, or the causes of the problems have mutated, but they are definitely still there.

For example: Mental Health. This is a much bigger deal in 2020 than in 1940, but are we pretending that there were not mental health issues in 1940? of course! but other problems were so bad, we didn’t pay much attention. Gender dysmorphia is not a new phenomena, nor is anorexia, nor is depression, or related conditions, but there is a much stronger focus on these issues now, probably *because* so many other health issues have been improved upon.

The game frankly does not model this. We model education just as badly. Its a 0->1 scale, that never changes, and if you improve education to 1.0, you are done! but the real world is different. The world has become more complex. The understanding of modern economics, modern electronics, modern physics involves a lot more stuff now than in 1950. Go back to when I was at university, and economics was simply macro/micro. Then along comes behavioral economics and we all have to go back to school.

Medicine is another area where the goalposts are in constant motion. As our lifespan increases, and technology advances, the demands on healthcare race upwards too. People who in 1950 would already have died, are now living relatively healthy independent lives….but at a great cost in terms of pharmaceuticals and technology.

I really need to improve my modeling here. Right now, the game *does* have some of this, because for example, technology does boost healthcare demand (by up to 22%), but maybe this needs to be on a curve, and more pronounced. Lifespan also boosts demand, but again, not by much. Maybe this needs looking at, and a review of other similar effects. The only design dilemma is how to represent this. Currently the entire game is coded around a system where voters look at the current state of affairs, and judge it against an arbitrary value like this:

“Healthcare is at 60% so I am 60% happy. When it was 62%, I was 62% happy”

Whereas in reality people probably think:

“Healthcare has fallen 2%. Things are getting worse. I’m voting for the opposition, they might be better?”

I REALLY do not want to change any core mechanics of the game, especially now we are no longer in early access, but I am continuing to think of ways in which to accommodate this phenomena into the way the game already works…

side note: I use WordPress (An absolute trainwreck piece of software btw), and as of the last update, the font it shows in post editing mode is totally different to the one the actual blog uses, with seemingly no way to change or fix this. presumably this is just some stupid new bug introduced by a pointless update I never asked for. Is it too much to ask for software developers at big megacorps to give a damn about quality? The almost weekly complete redesigns of their UI apparently do not trash their users productivity enough, so introducing dumb-ass bugs like this has apparently now become a priority. Absolutely useless…

Democracy 4 Leaves Early Access tomorrow! (a look back…)

So… on 13th January 2021 at 10am GMT, barring critical illness on my part or a meteor hitting the earth, my political strategy game ‘Democracy 4’ will be released from Early Access into the arms of the wider gaming world! Its as good a time as any to reflect on the games history and development.

Firstly…obviously this is not the first in the series of Democracy games. Imaginatively, I named the first one simply ‘Democracy’, and according to wikipedia it came out in 2005. It was GameTunnel’s 2005 sim game of year! go me! The game was the same basic structure as it is now, but with a horrendously worse UI and much, much lower budget, with me basically doing everything. Feast your eyes on this screenshot:

Democracy 1. Yikes

Like Democracy 2 and 3, it had the voter groups as a big chunk in the middle, but I had not realised all those sim values at the top could be placed in with the policies. Also… the bottom of the screen is kind of a disaster of poor UI decisions and incredibly rubbish stock icons. Still… the basic gameplay mechanics were pretty much all there, and I definitely sold quite a few copies. There were even retail versions in some countries as I recall.

Fast forward to the futuristic sci-fi future of 2007 and we released the much more polished Democracy 2, which we still have a website for, complete with amazingly improved screenshots and UI! This time there was an actual proper paid artist with a proper budget, and it starts to look a bit more professional. This version of the game, unsurprisingly sold much better. Feast on this improved UI!

Democracy 2. meh

We still have all the voter groups in the middle, but I worked out I could interleave the sim value icons with situations and policies, and stick all the menu-stuff in one consistent place at the top (although weirdly I still have your popularity under the voter groups). This game was definitely a relative success, although thats only in 2007 terms. Steam greenlight didn’t happen until 2013, it was 2005 that steam started very very very slowly adding 3rd party games. Online games sales were trivially small by modern terms.

I took a break from indie games at some point around here because I worked at Elixir and then Lionhead, but eventually, after having surprising success with Gratuitous Space Battles, I eventually decided to return to making political strategy games with Democracy 3 in 2013. And that when the game really took off and went bananas, especially on steam, where so far its now sold 780,000 units. There was also humble bundles, and retail sales, and ports to IOS, and a total of 4 expansion packs (social engineering, extremism, clones & drones and electioneering). This game had a proper marketing and development budget and looks like this:

Democracy 3: woo!

Hurrah! We now have a UI thats pretty close to the latest version, although voter groups are still in the middle, political capital is top left, and all of the icons and the icon group zones are the same size. This proved to be quite a limitation for modders, and also made it harder to find stuff (there was no text based search capability either).

Democracy 3 did REALLY WELL, and is my top selling game ever, combining with its DLC it beats even Gratuitous Space Battles and Production Line. Its the game that most people know me for, and got me invites to give talks at places like GDC. It also paid for me to develop a love of fast electric cars, which was nice.

There was then a LONG GAP, where I made other games, most noticeably Production Line, and I also became a games publisher, publishing redshirt, political animals, big pharma and shadowhand. Eventually I turned my attention back to the Democracy series to make a better, ultimate amazeballs version of the game, which is Democracy 4, and is being released tomorrow. Yay! Here is a relevant screenshot:

Democracy 4. Woohoo!

This is WAY better. The important icons are larger (configurable), everything is vector based, so looks crisp regardless of screen res. The voter groups are on the side, which makes them a sortable list, and the icons can all resize smoothly in different game modes. We also now have dark mode and palette support, unicode text support built in, and a ton of other design changes.

Some people are very cynical about game sequels, suggesting its all a cash grab etc, but I defy you to look at these 4 screenshots and think 4 is not an improvement on 1. It took 3 sequels to get there, but any coder or designer will tell you that they can make a MUCH improved version of the game they just finished if they get the chance to do it again.

Democracy 4 is released tomorrow, but its not the end of it. I am determined to improve the game balance, and have some more ideas of stuff to add. I am also obsessed with making mod support easier, and steam workshop support in this version is dramatically better than before. Sales in Early Access have been very good, but its hard to know how to compare it because Democracy 3 never had an early access release, and the entire concept did not exist for earlier versions of the game.

I suspect Democracy 4 will stay relevant for quite a long time. Politics is an evergreen topic, and I’m pleased with the fact that its UI is very adaptable to bigger monitors, and also supports unicode so we have decent language support in Japanese, Russian South Korean etc. This should ensure the game finds a decent sized audience over time.

Personally… I have found that this game leaves Early Access at a time where I really need to force myself to take some time off. For me that just means not working (at all!) on weekends, and maybe building up to being able to step away from work one day during the week too. Because I am a workaholic, I already have another company I run alongside this, which builds solar farms, so I am unlikely to not be busy. And I should play the guitar more too…

A big thanks to everyone who has supported the Democracy games over the years, I really do appreciate it.

Still balancing Democracy 4 with data

My current game: Democracy 4, currently has very good steam current reviews and all reviews scores. As I check right now it sits at 90% positive recent, 85% positive all reviews. However, 90% is not 95%, and any improvements to the game are bound to translate into higher scores, longer play times and better sales, and as balancing the game requires a huge amount of data analysis and thought, and is therefore what I consider fun…lets do some more!

Because it is a ludicrously complicated game, the only possible way to ‘balance’; the game is statistical analysis. There is no way I could hire a team of QA people to give me feedback on where the game is unbalanced, because the number of play styles and strategies, and political opinions, and then the different countries, difficulty settings and other options would mean even if I had 100 people analyzing 20 games a day, its still ludicrously trivial compared to the actual ‘problem space’ that the game represents.

Thankfully, the game sells well, and if I pick yesterday as an example, we clocked up a total of 3,754 games played by players in one day. These are proper paying customers whose stats don’t lie, so analyzing the data from these playthroughs is invaluable. I do not collect ALL possible data (that would strain even my dedicated server, whose current database size is 14 GB), but I do collect some interesting snippets (anonymously).

I rely on my own intuition and feedback in reviews (good and bad) combined with forum posts to give me a feel for areas where the game needs improvement. A topic that seems to come up a lot (with justification) is that the first term of a game is pretty well balanced, but if you ‘survive’ to a second term, things get easier and easier and the game loses its challenge. To check if this was really true, and look at some possible causes, I collected stats by each term and got this:

T1 Wins = 54.19 %    T2 Wins = 79.23 %    T3 Wins = 83.97 %   

Thats term 1,2 and 3+ win rate for game version 1.45. Its pretty clear that the intuition is correct. The game gets easier the further you go. The big question though is exactly WHY does this happen. In order to collect relevant stats I needed to think about what factors could make governing a country too easy. Maybe GDP gets high and stays there? Crime gets solved for good? Technology gets ahead and stays there? Unemployment solved for good? I collected player stats at the time of each election and plotted them over 1,2 and 3+ terms to get these stats:

and also…

So it seems that the stats do not lie. Multiple things seem to get good and… stay good. Education seems a bit easy to raise after 2nd term, but maybe thats because a booming economy allows for infinite spending on state provision? Sadly I do not have data for that, but its clear that GDP has an inexorable rise. Its also interesting to see that crime steadily declines, especially violent crime.

Stats like these are invaluable. Democracy 4 has a bunch of self-balancing mechanisms that are not artificial game constructs but based on what appear to be real-world auto-balance phenomena. It does seem to be the case that skyrocketing GDP in the real world can drive massive inequality (relative poverty…. even if actual absolute poverty declines). This rise in inequality can give rise to higher rates of crime, and also to political dissatisfaction.

Higher GDP and Technology can be a sign of increased industrial automation, which should really cause big spikes in unemployment, and thus also ineuqlait6y, but these do not seem apparent. Luckily, I have control of every equation in the game, so after reviewing all these stats I could make a bunch of adjustments and hope to see a budge in the direction of a more balanced (ie: more challenging) late game. Lets look at the new stats for build 1.46:

T1 Wins = 54.54 %    T2 Wins = 76.46 %    T3 Wins = 83.06 %   

Ok… so slightly better T2 (a bit harder…. 76% win vs 79%) and very marginal improvement from term3 and beyond. How did my actual core stats change:

If anything WORSE for GDP, although I did make unemployment worse, and a slight term 2 boost to crime, but fairly trivial. second row:

Ok… so equality IS now harder to raise in later terms, which is a slight improvement, but basically I have been way too meek in my adjustments and need to ramp those changes up. I also started tracking some additional stats:

This is new data for build 1.46 without prior data to compare to, but I felt it important to start measuring. Winning is the value of a special hidden variable I use in the game to adjust difficulty. That percentage DOES go up over time, which makes sense, although its clearly not hitting the upper 90s, so I could simply take into account consecutive election wins as some input into calculating its value?

Turnout is more of a curiosity, but vote percentage is much more interesting. In the *ideal* game of Democracy 4, the player scrapes narrowly through on each election, excited to view the results, and relieved to know they won another turn. 52 and 58% feel about right, but averaging 74$% is pretty worrying. Perhaps cynicism is not a strong enough effect here, especially given that it clearly drops between terms 2 and 3! (in the real world show me a president who people did actually become less cynical about over time…).

So the main thing is that I have useful stats and a system to compare them and check I am heading in the right direction. The game clearly got a bit more balanced between games 1.45 and 1.46, so here is hoping that being able to spend more time post-release on balancing versus features will allow me to improve that even more…

Speeding up Democracy 4 simulation processing (atof is slow)

I just made a major speedup to the loading/next turn/new game code in Democracy 4, and thought I may as well share the gains with readers of this blog :D. It kind of makes me look a bit like an idiot to admit this is a big speedup (I should have known), but anyway, knowledge sharing (especially on optimization) is always good.

Fundamentally, the code in Democracy 4 is structured like a neural network. Without going into tons of details, every object in the game (policy, dilemma option, voter, voter group, situation…) is modeled as a neuron, which is basically just a named object connected by a ton of inputs and outputs to other neurons. You can run through the inputs and outputs, process the values and get a current value for a neuron at any time, which is done for every one of them, every turn.

Also… when we start a new game, I need ‘historical’ data for each value, so the game pre-processes the whole simulation about 30 times before you start to give us meaningful background data, and to ensure the current simulation sits as a reasonable equilibrium.

Those connections to neurons should probably be called dendrites or whatever, but I call them SIM_NeuralEffect. They contain basically the names of a host and a target (resolved to actual C++ pointers to objects), and an equation explaining the connection, and some other housekeeping stuff.

At the heart of it all, is an equation processor which lets you write this:

OilPrice,0+(0.22*x)*GDP

And actually turn it into a value for that effect, given the current situation. The Equation processor runs each turn, on every neural effect, and there are LOTS of them. Thus, if the equation processor is slow, its all slow.

I just installed a new version of the free vtune profiler from intel. Its not recognizing my ultra-amazing new chip, so only doing usermode sampling, but nonetheless it draws pretty flame charts like this:

Before I optimised

This is showing the code inside that 30-turn pre-game processing called PreCalcCoreSimulation. Lots of stuff goes on, but what I immediately noticed was all this atof stuff. Omgz. Thats a low level c runtime function, not one of mine, and it seems to be slowing down everything. This is a HUGE chunk of the whole equation processing code. How is this possible?

Now, you may think ‘dude, atof is pretty standard. No way are you are going to be able to make that code faster’, to which I reply ‘dude, obviously not. But the fastest code is code that never runs.’.

All those calls to atof are absolute nonsense.

Looking back at the equation above (OilPrice,0+(0.22*x)*GDP) there is obviously some stuff in there which is volatile. I do not know what the current value of x or GDP is, so I will need to grab their pointers and query them when I process the equation, but the rest of that stuff is static. That * is going to remain * and that 0 and 0.22 will remain fixed too. This is the key to a roughly 33% speedup of the whole processing in the game.

I actually did know to look into this, and I do not do manual text parsing of the equation each time. I parse them equation on startup, and stick the various values into buckets, so I am not wasting time each turn. But one thing I had not done is store the atof() outcomes. I was still storing variables[0] as ‘0’ instead of just 0.

Now you may think atof is fast. Its fast enough for most cases, but its WAY slower than just accessing the value of a floating point number thats already in RAM, and cached happily in the equation processor itself. Here is the new diagram:

Faster!

The difference is, (on my superfast PC), for the whole precalc simulation function: 0.85 vs 1.50 seconds. This probably makes me sound pedantic as hell, but I’m rocking some stupidly new and pricey PC, so there are likely people playing D4 on laptops a fifth the speed. I might be knocking a whole 3 seconds off the new game time for some players!

Also, and worth remembering, I just saved doing a ton of processing, which means a ton of CPU time, power and heat. If you can make your game run more quietly, more coolly, and faster on players PCs, you absolutely should do it.

Protest votes in Democracy 4. Final piece of the puzzle?

Democracy 4 is a game, but its also my attempt at a fairly accurate political simulator, given the limitations that are to be expected when you do not delve into the individual mechanics of voting systems, and constituencies and different systems such as primaries, mid terms etc.

One of the things that may feel unrealistic to you if you play the game and get good at it, is that sometimes you will win with a laughably high share of the vote. 80%, maybe 85% maybe even higher. In the real world, in true trustworthy and secure democracies, this is super rare. Why is this? and how can I fix it in Democracy 4?

The most obvious answer is probably that ‘differing views on politics exist…duh!’ meaning that no party is ever going to win over everybody. This is obviously true, but there is definitely a phenomena where political debate shifts focus over time, and either takes the electorate with it, or is dragged BY the electorate towards it, depending on your POV. This is often called the ‘overton window‘ and is the space in a theoretical political compass that contains the ‘theoretically electable possibilities’.

For example right now in the USA, segregation of the races is most definitely not inside the overton window. No serious party would suggest setting up apartheid in the US. Similarly, the forced seizure of wealthy peoples second homes by the state is not considered. This is also clearly outside the overton window. But there are policies that move in and out of that window over time. Is socialized medicine now in the US window? perhaps obamacare suggests it is, but thats a fairly recent inclusion.

The point I am making is that mainstream political opinion can shift over time, so in theory, if a government does a really good job, it could shift a LOT of people towards supporting it. There may remain 5% hardcore racists and 5% hardcore communist, but its *feasible* that a centrist party could get 90% of the vote, based on policies.

So why does this not happen, ever, and why does it feel weird if it happens in Democracy 4?

The trouble with letting a computer programmer like me design a voting simulation is that we act like classical economists, who have a concept of a rational consumer. Rational consumers have a price at which they buy product A. If the price is too high, we don’t buy, if its low, we buy. Thats classical economics. The problem is, it turns out that classical economics is horseshit.

Read up on ‘behavioral economics’ and you will find its a crazy world out there. It turns out that ‘free’ is a magical price that behaves totally different from $0.01. It turns out that sometimes we will buy more if the price goes up. Sometimes we will value a product at a higher price than we paid for it…for no reason at all other than psychological feelings of ownership. It turns out that we get confused between $2.99 and $3.01 and think the first price is WAY cheaper. If we buy a product for $9,500 and we see an option to add biscuits worth $5 to the price as an add on, we happily pay $20 for the biscuits. In other words, we are dumb, irrational chimps!

The same is true of voting. We do not look at all of the impacts of the various policies proposed by the various manifestos and then make a rational choice. We vote for dumb reasons, in dumb ways, for animalistic and pyschological and completely irrational reasons.

Democracy 4 models some of this as best as it can. Voters are individuals that have a sense of elasticity of opinion, based on age. In other words old people stick to their views and loyalties, young people chop and change. Actual chance of voting depends partly on party membership, partly on strength of feeling, partly on the campaign effectiveness by the likely party we normally vote for, partly on their innate tendency to do things like vote (randomized at birth).

Once a voter actually votes, we base their choice partly on rational policy evaluation, partly on their perceptions of the leader (strong/compassionate/trustworthy?), partly on how fed up with the ruling party they are due to its time in office (inverse political honeymoon), partly on the appeal of the ruling party’s ministers, and the amount that party spends. And a lot of this is mitigated based on how educated the voters are. Poorly-educated are more manipulated by this, and less by policy.

And ultimately this super-complex bunch of code spits out a decision by each voter… and sometimes 90% vote for you.

I just today realized what I’m missing. Tactical voting and protest voting. Basically people actually supporting you, but voting for someone else.

This is a big thing, especially in ‘safe seats’ or ‘non-swing states’ for US readers. If you live in a state where the democrats get 75% of the vote every election, and you are hard left…why vote for the democrats? You can safely vote for a third party harder-left candidate safe in the knowledge that the message will be received…but there is no risk of you letting a republican in. And the same vice versa.

LOTS of people clearly do this… but the game does not yet handle it. Not only that but the *chance* of someone voting is probably also influenced by this. I know 100% that where I live, our next MP will be the same Tory MP we have had here for decades. Its a super safe conservative party stronghold. So in theory, if I was a natural Tory voter, I could safely ‘use’ my vote to send a message to him that he should not be complacent…OR I could just stay at home that day, safe in the knowledge that he doesn’t need my vote and will win anyway.

I need to include this in Democracy 4, and I am just working out a way. Clearly some people are likely to vote tactically and some are not. I could simply give it a percentage and say 10% of the electorate are susceptible to these thought processes, then assign some other thresholds. For example if the polls show >70% approval for the ruling party, then scale in a chance I don’t bother to vote if I support them anyway, or scale in a chance I vote for the closest party to the ruling party that is *not* them (could be one of two opposition parties…).

I need to code this, and test it, but also hopefully find a way to represent this in the game. One way might be to make up a bunch of small protest-vote parties with fringe views, and represent them as another column of ‘smaller parties’ on election day. This could effectively be the ‘protest vote’ column… Still thinking about it, but I think it does need to go in…

Could this work?