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

On the visualization of voter approval distribution in Democracy 4

My politics game, Democracy 4, has a user-experience issue. Its not critical, and its less prevalent in Democracy 4 than any of the other games in the series, and I am working on fixing it, but it remains an issue nonetheless. the fact that this issue is based on real world phenomena does not make it any less frustrating for a player who experiences it.

Some background: The game is a ‘run the country simulation’, that models an entire country, and the electorate are represented by 2,000 simulated AI voters. Those voters go through a very complex web of calculations to decide what they think in the years that you are in power, and at election day, they cast their vote either for the player, or for one of the opposition parties. In a two party system, the decision is quite simple, as players who have a . 50% ‘approval’# of the government vote for the player, and the rest vote for the opposition.

During the game, the player can regularly check on how they are doing regarding polling, by checking out a screen that shows two graph lines. One of these is voting intention, and the other is average approval. This is a NEW thing for Democracy 4, because previously we would only show voter intention. The difference between the two is incredibly, incredibly important. Let me explain why.

An individual voter has a fluid measurement of their approval, in that it ranges from 0% (Hardline hatred of the government) to 100% (fanatical dedication and loyalty to the government). However, for most people they likely hover closer to the center. Not many people would sacrifice their lives for, or against a government in a western democracy. So people’s opinions float around. For many, that float is always above 50%, or always under 50%, but depending on how the government is doing, a lot of people might float below and above that line, and pollsters call these people ‘floating voters’.

Here is the problem: Although approval is fluid, voting is binary. On election day, assuming you vote, you vote for the government, or you do not. You don’t vote ‘more’ or ‘less’ for the government. You either ticked the box or did not. Thus, its important to realize the distinction between the two systems of measurement. The graph above illustrates the difference. Voting intentions in blue are basically a binary poll of yes/no on the government. The green line is the aggregate of asking everyone to rate the government on a 1 to 100 scale. These are MASSIVELY different.

Take an extreme example, where everyone in the country thinks alike. The government has been…ok, but a bit corrupt, a bit untrustworthy, but the economy is doing well. On balance, the consensus opinion is that the government rates as 49 out of 100. When everyone is asked in a survey, they give the same answer, so average approval is 49%. Not bad. However, if forced to vote now, everyone would naturally vote for the opposition, so the election result would be 0% votes. Absolute defeat.

Then the next turn (3 months in game time), a surprise event happens. Scientists make a breakthrough in quantum computing, thanks to a science budget you raised 2 years previously. This good news bolsters the stock market, some voters feel a bit more wealthy, and this boosts GDP just a tiny fraction, pushing wages up just a tiny fraction. Everyone in the country is just a tiny bit more satisfied with the government, hardly noticeable. Maybe 2% difference?

Now its election day, and again, if answering a survey people give very similar results to before, but just slightly better. Average approval has nudge upwards just a fraction to 51%. Barely noticeable on the green line. However, the election is again binary, so given their new scores, every single voter in the country votes for the government. An overwhelming landslide of historic proportions. Total electoral dominance. The blue line shoots to the top of the graph!

This is why the two-lines are introduced into Democracy 4, because in theory, this could really happen. A slight change in voter happiness can yield a massive electoral win…or unexpected crushing defeat. And when I have paragraphs of text to explain how it works…this makes sense. The trouble is, I’m not there to give post-election analysis to every player who thinks the game is broken because of a sudden reversal of fortunes…

In practice, this problem is not overwhelming, because the voters in the game are very sophisticated AI models of widely varying people. Voters might be in 10 different voting groups, each at different levels of membership, and are being pulled in many directions at once, as you can see in the focus group screen:

…so in most cases, for most players, at most elections, this does not occur that wildly. But nevertheless, its possible, and a good game would never surprise the player with what seems like an unfair loss, or an unfair win. They have to be able to see immediately what is going on.

Funnily enough, all the information the player needs to understand this is already in the game, its just not necessarily in the right place. For example, I present to you the parties screen:

This represents approval as the Y axis (chart on the right btw…) and plots every single AI voter. Depending how distributed they are, the effect we describe may vary. In my nightmare 49/51% example, every voter is on the same horizontal line just moving up and down. In this case, the voters ARE very clumped, and just below the point of approval where they would vote for me, as this is a 3 party country, and they are tempted by the middle party. Right now, this is dreadful news for me, and awesome news for the middle (blue) party, but given the voters are so similar, if I can shift my policy positions closer to those the voter’s prefer, I should get an overwhelming avalanche of voters tilt my way!

This is also something you can see if selecting the ‘happiness distribution’ button on the ‘Everyone’ voter group. This time its represented on an X axis, where the left is 0 (angry) and the right is 100% (happy):

This is the same game, with the same voter distribution, and as you can see, in this case (start of game for the UK), its pretty clumpy. BTW the color of each dot represents happiness. Those green voters are happy, but they need to be super-green to vote for me, as there are 3 party options.

So all the information is kinda there, but people still don’t understand those wild swings in voting outcomes. As a result I have decided to try and represent it another way, in another position. I think that in general, players are expecting to get all their polling information from that earlier polling screen, so if I am going to represent voter approval distribution I need to do it there. PLUS, ideally I need to show it changing over time, not just a snapshot in time which is how its shown on these two graphs. Here is my current solution:

Same chart as before, but the background is now filled out with some extra information in the form of green blobs. These are presenting the voter approval distribution at each point in the game. The larger the blob, the more voters it represents. Over time, the blobs both move and change size, as the opinions of the electorate change.

The ideal situation for the player is to have substantial big green blobs way above the line, so they represent committed voters who are unlikely to suddenly drop below the line. If you have the green and blue lines above the threshold…BUT… there are large green blobs right on the line… then this represents fickle voters whose opinions might easily shift against you.

In code terms, each turn I’m asking each voter what their approval is, and sticking them in to one of 20 vertical ‘buckets’ of popularity. Each of these is a blob. Then in the chart I’m showing the number of people in each of those buckets by the size of the circle. Its more complex than it sounds because you need to work with circle areas, not radius, and also do some pre-processing to detect the largest blob, so you can then scale everything so the blobs are as large as possible (for legibility) while also being in proportion to each other and thus accurate.

The HUGE challenge is, as ever, not technical but UI/UX related. Does this help? does this make sense? and given that players often do not read tutorials, guides or walls of text, is it conveyed clearly enough just by the phrase ‘approval distribution’? Does the red approval line need its own key to explain what it is? (I think maybe so).

As always I’m interested to hear what people think. There is a complexity cost in adding this (it complicates this graph, potentially distressing newer and more casual players), and I need to be confident that the increased visual complexity is offset by the greater insight for the player into what is happening out there in opinion poll land…

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.