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

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…

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?

New Democracy 4 policies: Workers dividends and Ban on crypto

I’m working on adding two new policies to the next update for Democracy 4 today. By popular demand (deduced from in-game player voting during Early Access) I have decided that these two policies are worker dividends (profit sharing) and a ban on all cryptocurrency. I’d like to talk through what these policies represent from a game design and real world point of view, and show how they have been implemented.

First up is workers dividends. Like all Democracy 4 policies, these are not as specific as they sound, but represent a whole ‘area’ of legislation, in this case legislating on how workers must be compensated. In the overwhelming majority of countries, such legislation basically amounts to laying out a minimum wage (if one applies), and perhaps some rules about grounds the company may have to withhold such payments, or perhaps rules surrounding what kind of deductions from wages can legally be made.

In other words, in general, as long as a company pays you minimum wage, thats all you are entitled to. If you notice you earn $40/year and the company CEO earns $50million a year, and its all your effort that enabled this…then basically your option is to just quit and work somewhere else…

Some people take the view that this is unfair. Others take the view that this is capitalism working as intended. A clever company will reward employees fairly, or risk losing them to cleverer companies who spot their potential. This is the ‘perfect market’ school of thought.

Others might suggest that this is fine when we are talking about headhunting people with phds, but when it comes to warehouse workers, or other minimum wage staff, things don’t work that well. A company like amazon may earn billions in profit, but see no reason at all to pay its warehouse staff above minimum wage. If you are of a socialist mind, this is unfair, and exploitation and needs fixing.

Generally in my lifetime this has been a non issue where I live, until the last UK general election, the left-wing Labour Party did propose something akin to this new Democracy 4 policy:

https://www.bbc.co.uk/news/business-50508369

In this policy, the party suggested that 1% of the shares of private companies be taken from them each year for 10 years (total 10%) and placed into an ‘ownership fund’ whose share of the profits would be paid to the workers. In a Marxist sense, this would be described as ‘seizing the means of production’, although in this case only seizing 10%. The idea was to share the profits of big companies with the staff, and was probably one of the most pure socialist policies proposed at the election.

In the end, the party lost (quite badly) so we do not get to see how the policy worked in practice, but it was popular with its supporters (and VERY unpopular with its opponents).

I need to include policies like this in Democracy 4, because as socialist players have pointed out, the game does not go to any particular extremes on the left economically. We have policies for minimum wage, retirement age, worker safety and even mandatory union representatives on company boards, but no direct pure wealth-redistribution from owners to employees. This policy fills that gap. The slider can be thought of as intensity, showing a range of measures from the ‘incentives for bonus schemes’ all the way up to ‘mandatory allocation of 90% of shares among the workers’.

My first thoughts are that this policy pleases socialists, and union members, angers capitalists and small businesses (effectively entrepreneurs), boost the chances of a corporate exodus, reduces foreign investment, but has a side effect of making all strikes less likely. (Why strike when you will feel the pain as profits drop?).

The second new policy I’m adding is a cryptocurrency ban. Sometimes people ask why such ‘ban’ policies even need a slider, but a ‘ban’ can mean everything from ‘some currency mining is banned if using certain power sources’ all the way up to ‘holding, mining or trading cryptocurrency of any kind is punishable by imprisonment’.

In this case the motivation is a combination of loss of government control (and thus tax revenue) and concerns for the environment. Liberals hate banning anything (because…freedom), and obviously any ban would have a vastly negative effect on the usage of cryptocurrency.

How Bitcoin's vast energy use could burst its bubble - BBC News

For background reading on the environmental costs of cryptocurrencies (specifically proof of work), just use google. Its pretty shocking. I have strong views on all crypto, including proof of stake, which although environmentally better, has the perverse effect of making the rich get richer. Perhaps someone will do an in-depth D4 mod that represents different types of crypto and their effects on socialists and capitalists!

And that reminds me… I must check that crypto’s CO2 impact is modeled in the game…

Improving Democracy 4 events balance by using a LOT of data

I’ve been doing some number crunching to check that I am moving in the right direction regarding balance on Democracy 4.

The game has a series of ‘events’ which are triggered by various inputs. Some of these events are pretty ‘informational’, in that they mark changes the player has made and their impacts, other affect the games difficulty by stopping the player racing too far ahead or too far behind. Others are there as a random curve-ball that the game throws to the player to shake things up. There are about 120 of them.

Because they are not triggered purely randomly, the frequency with which each event shows up is determined by the complexity of the neural network that forms the basis of the games simulation. This means that some events may end up triggering much more than others, if the inputs to those events are not balanced correctly.

In an ideal world, the whole game would be a truly self-balancing neural network, but I don’t trust the systems enough to unleash anything like that, so I collect statistical data on which events trigger in each game version, and then change some of the inputs each update so that things balance out for the better.

In an ideal world, every player gets to see 100% of the content in the game, so they are effectively getting what they paid for, and not being constrained to a tiny subset of the content because of poor balance. In other words, if I have an event called ‘school shooting’ and its triggering one tenth as often as ‘scientific breakthrough’, then the balance may be off, in that the inputs to the first event are too strong, and the second too weak.

Note that I am talking in grand statistical terms over thousands and thousands of players. An *individual* player may never see school shooting, or scientific breakthrough, depending on the countries they choose and their play style and skill, but I need to check I’m not adding content to the game that hardly anybody sees!

By collecting all this data, I can build up tables for each game version showing the total events triggered for players of that version, AND the number of times each event triggered. Like this:

1.27
Event Namecount
shareiposuccess7790
shareipocancelled7112
hugehurricane4515
dubiousrolemodel4190
resourcesobsolete3913
multinationalcompanyheadquarters3810
militarycontractscandal3780

..and so on. Because I am looking at 120 events, I can work out that for version 1.27, if every event was equal, they would all trigger 1,406 times given the number of version 1.27 games played. I can then store the difference between the ACTUAL number of triggers, minus the target, and express this as a deviation in percentage terms from the target:

1.27
Event Namecountpercentage deviation
shareiposuccess7790453.78%
shareipocancelled7112405.58%
hugehurricane4515220.96%
dubiousrolemodel4190197.86%
resourcesobsolete3913178.17%
multinationalcompanyheadquarters3810170.85%
militarycontractscandal3780168.71%

So you can see that back in version 1.27, the top event (Share IPO success) is triggering 4.5 times as often as I would like.

I can then add up all of those percentage deviations and get a final number representing the total percentage deviation (in absolute terms) over all events. That gives me this:

VersionAbsolute Deviation
1.276426.89%
1.285717.38%
1.296128.34%

In an ideal world, this number trends down over time as each version comes out.

Another way I looked at things was to just look at the absolute value of the top 10, and bottom 10 events, to see if I am effectively ‘squashing’ the trigger probabilities to prevent extremes. This is a major goal, because players will not notice and event triggering 5% more than another, but if one triggers EVERY game, or NEVER, then that does get noticed. When I look at this data I get these values

VersionAbsolute DeviationExtremes Deviation
1.276426.89%2941.48%
1.285717.38%2239.64%
1.296128.34%2433.29%

By doing this for a whole bunch of different game versions, I can end up with a chart showing my progress!

More helpfully, I can quantify that the uneven-ness of the event triggering has improved by 14.73% since version 1.27. The extremes have been reduced more, by 30.29%

This probably sounds stupidly maths-y and the system is full of issues, such as events that only trigger in a few countries, and therefore SHOULD be seen less… but there are limits to which a single coder/designer/bizdev/marketer person like me can spend time crunching all this.

TBH its just a big relief that the numbers DO seem to be trending in the right direction, especially as I keep adding new countries and complex simulation elements (meaning that the simulation is in flux, and thus just remaining the same would be a balance-win of sorts.

It might be bizarre but I really enjoy this kind of analysis :D Now go tell your friends how well balanced Democracy 4 is :D

Democracy 4: Resizable GUI

For the last week or two I have been working on what seemed like it might not be too bad…but actually turns into a lot of work. This is a resizable GUI for Democracy 4. The current version of the game has fixed size UI elements everywhere which works fine for the old school screen res from maybe 1280×768 up to 1920×1080, but starts to get a bit annoyingly small text at 2560 plus, and frankly the UI can be a bit too big and blocky at the lower res too. I finally got around to fixing this.

The first day or so was wasted trying to find an automated solution. Democracy 4 uses SDL2 and OpenGL, and I was hoping some of SDLs scaling functions would handle this simply. I could easily implement a scaling slider in the game, and then SDL could just handle a final stretching up or down at blit/flip time of a fixed resolution image.

This failed to work. partly because of some messy implementation at my end perhaps, but also because screen aspect ratios can change. Even if it DID work, it would basically mean throwing away the core UI upgrade of Democracy 4 over 3, which is super-smooth fonts and pixel-perfect vector-based icon and UI element rendering. If the player set the render scalar to anything but 100%, any sort of stretching would give a slightly blocky look. I couldn’t live with that.

In the end, I did implement all this as a simple percentage slider on the games options screen. Changing this requires a reboot to see the effect:

In order to get all this to work I just had to make a LOT of small code changes. Probably every UI file in the project got changed in the last week. What I needed to do is get rid of what coders called ‘magic numbers’ and replace them with values that could be scaled up or down based on this slider. For example code that said this:

int iconleft = Area.left + 120;

Would be changed to something like this

int iconleft = Area.left + WIDE_SIDE_PADDING;

The all-caps value could then be coded as defaulting to 120, but be scaled up or down by a global value for RenderScaling, which is decided when the game starts. This way I could reuse that value anywhere in the game and know it would always be the right value. Because I’m not entirely useless, luckily I HAD actually defined and used a lot of named values already like this:

int iconleft = Area.left + STYLEGUIDE_BLOCKPAD;

So in that case no code change was needed, and that value (10 as a default) could be easily scaled at app startup. The problem was… I had not stuck to this, and actually used a LOT of magic numbers (ie: actual numeric values) many, many places in the code. I ended up just having most of the common ones defined as pixel constants:

int iconleft = Area.left + STYLEGUIDE_PAD50;

For example. A bit kludgy, but some values really are used in random places and giving them stupid names like STYLEGUIDE_MINISTER_)SCREEN_TOP_WINDOW_HEIGHT would be overkill if you ask me. In any case, after a LOT of typing and also a LOT of testing, I am very close to declaring this done, and letting users play with it. Its not perfect, because a lot of combos don’t work. If you are playing at a small res like 1280×768 and set the slider >100%, things will overlap and look rubbish. But I’m hoping people are sensible. This is a FIX for people who dislike the default layout for high or low resolutions. Its assumed 95% of players will not touch the slider.

Anyway here is the game in the current (unscaled) view in 2560 resolution and default 100% scaling:

(Its reduced by 50% for here). Check out how small the text is for the finances, and how much space I waste on the timeline at the top. Now here is the exact same screen resolution, but with a 133% slider:

To me this looks WAY better, but you are only REALLY going to appreciate the change if you have a high DPI but smallish monitor, or an insanely high res monitor and poor eyesight. At first glance, you might not be able to tell the difference, but then check out that timeline at the top to see just how things are re-arranged. or check on the far left near the top, the ‘POPULARITY’ text.

Anyway this is coming to the next update for the game. it took a while, but it really needed doing!