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

Modelling voter happiness in a video game is… interesting but also horrendous

Its less than 2 weeks until the US election in 2020, and although it looks likely Joe Biden will win, nobody really knows, because modeling how people vote is really hard. I know this, because I’m struggling with it in Democracy 4. Over the previous variants of the game, the voting model has got better and better and more complex, but its still a nightmare.

Here is a very very basic, simple description of how the voting system works:

We collect all of the various inputs to a voter from voting groups and calculate their happiness. If its over 50%, they vote for the player, if its less, they vote for the opposition.

Thats fine, but way too simplistic. For one thing…who says they will vote at all? so we have extra mechanics to decide based partly on age, party membership, and how angry/happy they are… whether or not they even vote. Plus culturally every nation has a background level of ‘apathy’ which feeds into this. Then finally, there are extra multipliers based on how strong a ‘campaign’ each party runs, which help to ‘get out the vote’ by financial means (adverts) or activism (party activist boots on the ground).

Thats better… but not perfect because it assumes rational voters making purely policy-based decisions based on self interest. So I have to then adjust the happiness of the voter based on their ‘perceptions’ of the candidate, which are affected by both policies and ‘spin’ events in the media. I then adjust *that* effect depending how educated the voter is. Basically the poorly educated are swayed more by spin, the better educated less so. (FWIW you can toggle that mechanic off in the game).

That all sounds complex enough…but its not. There is also the matter of party loyalty. So for example, say you are a trade-unionist left winger in the late 1970s, and have voted labour in the UK all your life. Along comes Tony Blair as party leader, by any definition a centrist. You still keep voting Labour because…well you always have done right?

The party position drifts dramatically but for a good few years, maybe multiple elections, you still vote for the same party. You become someone in a centrist party, holding left wing views, but still voting for them. In short, your loyalty has trumped your analysis. To make the game more accurate, we model that too! you can even hover the mouse over a voter and see their loyalty and analyze them (and click-through to a detailed breakdown).

(To illustrate this, generally you see cluster or red, blue and green on this screen to show members of each party, but sometimes those colored dots seem to be further away from ‘the pack’. These are people like I mentioned above… members of a party, and voting for them, but actually holding different views).

This is all a big improvement, but its not *quite right* yet, because the problem is…we still have what seems to be fairly wild swings in voting behavior. This is because of ‘soft’ support for a party position. To put it simply, if 100% of the country have an opinion of you that is 49.9%, you will get 0 votes, and be wiped-out in an election. Shift them all towards you by 0.2%, and you will win a landslide.

This is correct political modelling, exactly accurate and how it should be…but somewhere, some of our numbers are not quite right, so we are not ending up with the real-world results we expect. I have not *yet* completed my analysis of exactly why, but I suspect its because peoples opinions sway too wildly, and because party membership and loyalty is not strong enough.

For example in the UK right now, a lot of polls would suggest everybody is very unhappy with the current government. In Democracy 4, they would be in a bad way, because so many of the electorate are angry…. but I suspect the Conservatives would win an election tommorow, because despite their anger, many people who voted conservative in the last election still prefer them to the alternative. In other words, their party may have changed, and performed badly…but they still have party loyalty, and its not been bad enough for long enough to drag them away from that…

This sort of stuff is a nightmare to balance of course, but not that hard to code. I think I likely already have most of the data and variables exposed for me to get it right. I hope people realize that this is what Early Access is all about, and hope people can see more of whats going on by looking at that scatter chart (these are new to democracy for d4).

The real challenge is explaining all this to the player. I can get a better UI than I currently have. it just takes a lot of time, and experimentation, and analysis. Hopefully people are patient about this during Early Access.

Democracy 4 is on Steam, GoG, itch and the humble store

Democracy 4 crowdsourced translations now on localizor

I was musing about how on earth to manage the people who are keen to help out translating Democracy 4 when I was pointed at this awesome website called localizor which seems to be set up to do exactly what I needed: Localizor

This is so cool. Its basically an online database for you to share the translation keys for your game, and optionally a single reference language (in my case obviously English) and anybody who wants to contribute can enter text for any of the languages you have listed. There is a cool progress bar and it also shows you which users have made the biggest contributions. Its basically awesome.

This has cool features like showing you the google translate version of any string, so I guess you can check that people are not typing in absolute nonsense (or worse, something offensive), and people can vote on each others contributions etc. I think you can ban people too, if they are being malicious. Its basically a reall well-thought out system for doing exactly what I need.

There is a free trial, and then it costs a monthly fee, but its cheap, and a no-brainer really. TBH the biggest hassle was writing the code to output all my translated data (which is in csv files, and some ini files) into the right format to be imported into their database. It works on the assumption of KEY = VALUE as opposed to some of my stuff which has KEY,VALUE1,VALUE2,VALUE3 etc, for a bunch of different columns of data.

All-in-all it took about 90 minutes to write code to dump out all my text, and then manually submit the whole lot to the website. I also need to import the nearly-done fan-made italian translation I have, and eventually write my code in reverse to slurp up whatever format the site exports to and pump those values back into my own format.

Democracy 4 is, by its very nature, a global game, and its really cool to be able to leverage all the work jeff did regarding unicode, and vector rendering and fonts so we can support some often less-supported languages. I’m especially excited at the thought of Democracy 4 in Korean :D

If anyone can do it, everyone will.

Every now and then I come across a story about how mid-tier youtubers are making an absolute pittance, or that indie bands on spotify earn less than minimum wage, or that writers (like my wife!) can expect to earn a really trivial amount for what they do.

This is totally and utterly expected, and its down to barriers of entry, of which there are a few.

Barriers to entry is an economics term that refers to all the stuff you need to have to produce a certain product in the market. Some industries naturally have small barriers to entry (busking only requires a guitar, for example) and some have huge barriers (spaceships, cars, silicon chip production). Generally speaking, barriers to entry are very bad, from an economics point-of-view, because high barriers-to-entry lead to ‘abnormal profits’ by people in that market, as its difficult for newcomers to enter the market and bid down the price of the product.

It might seem that this explains why indie game devs rarely make any money, because the barriers to entry for indie dev are tiny. You need an office chair, a laptop, an internet connection, and…a rudimentary skill in programming and game design. Thats a LOT of people, and its WAY more than it used to be, now you dont have to code your own engine and dev-tools are affordable.

SIDE-NOTE: YES amazingly cliff is aware that there are millions, if not billions of people who cannot afford a laptop and broadband. Well done! 10 internet points for you! But this blog post isn’t aimed at solving inequality. Not everything on the internet is aimed at everyone, or is a political statement!

Anyway… indie game dev does indeed have super-low barriers to entry and this should mean that nobody in that industry makes much profit, but hold on! some of them do! Jonathan Blow! Introversion! Me! The Factorio & RimWorld devs… how is this possible?

Barriers to entry can include personal ones as well, not just financial requirements. Sure, anybody can buy visual studio (my dev tool of choice, about $500), the same chair as me (aeron, about $1k) and a decent PC (maybe $1,500 tops?). They can then decide to make an indie game. This will not be profitable, as there are a LOT of people in this green segment below…

Some games are technically much easier to make a first-game in than others. Platform games come to mind, as do arcade games. If you are using unity or similar, maybe a primitive FPS. Some genres are harder. Strategy games are harder, as are RPGs, Simulation games can be really hard. By choosing one of the ‘harder’ genres, you are already putting up barriers to entry to prevent your market value being competed down. Of course your job just got harder, but thats to be expected. There are fewer people in the white segment below.

Where it gets more interesting is in leveraging barriers than cannot easily be broken down by any means. That comes down to what makes you…YOU. Leveraging that unique venn diagram of skills and interests that makes you capable of making the game that YOU can make, but its unlikely any other dev can.

In my case, studying economics at LSE, and the son of parents who were both trade union reps, someone who got taken on ‘fun trips’ to the Trades Union Congress and Labour Party conference as a child (yes really), plus an aptitude for maths and logic (and clearly being on the autism spectrum) means that my venn diagram screams MAKE COMPLEX POLITICS SIMULATIONS. There are a handful of people in the white segment below. maybe me and Brad Wardell and half a dozen others?

Now in theory, anybody could try to clone Democracy 4 and force down my profits, but in practice its hard because you have to REALLY be a politics geek to spend the time and effort to make that sort of game, and the coding challenge is sufficient that it still gives me headaches after 39 (yes really) years of doing programming. Plus I have a special super-power that allows me to be even better suited to that exact project:

I’m pretty much a centrist. Politically I’m slightly right leaning on economics and slightly left leaning on social issues, but generally speaking I’m a moderate. That means I can sit down and have a meal and a chat with a hardcore bernie sanders supporter OR a trump-supporter, and get along with both as people. That means I’m not trying to have a big political agenda with my politics game, which broadens its appeal. (I’m not going to attempt to add another circle to that diagram…)

Every extra circle you can add to your indie game dev venn diagram of uniqueness™ is going to boost the probability of you earning decent money. Of COURSE…. you still need to work hard and make a great game, and make it appeal to enough players and do the other 999 things. This system only helps you maximise the returns WHEN you have an idea, and execution that results in something people want, and buy. I still think its worth keeping in mind.

Democracy 4: The fixed income rewrite

About a week ago I had this mad idea that it would be cool to plot every single Democracy 4 voter’s wealth on a graph, so that you could see where they were clustering in a nice easy-to-understand way. Within an hour it worked, within a day, a new rewritten version that looked much nicer with blue dots on it was done, and I was tweeting, and people were saying ‘yay’, and then everything went fucking mad.

By hovering the mouse over one of those blue dots, you could see a breakdown of how that persons income was affected by every government policy or situation, indirectly, through their membership of voter groups. This data already existed in Democracy 3, it was easy, it was just GUI code, and done really quick… and that showed me what an absolute mess the simulation was…

Democracy 1,2,3 and 4 are all coded as a homebrew neural network. Every neuron has a value either capped from 0->1 or -1->+1. Everything in the game is a neuron, a voter, a voter group, a policy, a minister, an event…everything. Voters also have an ‘income’ neuron which tracks how much money those voters have. So…in supersimplistic terms if you want to know why Bobs income is 0.78, you look at the 21 weighted inputs from all the voter group income neurons, and you see all the +0.2, -0.1,+0.32 etc, that adds up to 0.78. If you want to go one stage further up the hierarchy you can track the origins of those effects to policies etc.

Thats worked for 3 games perfectly. But its a crap system.

The trouble is, peoples incomes are on a 0->1 scale. And all effects are percentages. So for example if free bus passess give retired people a 0.05 income boost, that increases the income of all retired people by 5%. Fine?

NO

Because working class ex-street sweeper mavis just got a bus pass worth $500, but retired hedge fund manager Boris just got a buss pass worth $15,000. WTF? why does democracy hate poor people? The problem is that we have only ever been able to use effects to apply percentages to incomes. That means EVERY benefit, or tax, or effect is proprotional to your income. That means lambourghini drivers pay more in car tax than skoda owners (maybe intentional), but means the state pension depends on how wealthy you already are.

Its fixed. it was hard.

Basically I have had to code an entirely new shadow system of fixed-income neurons that can cope with values beyond 1, and then (this is the hard bit) written code that stitches it all back together internally so that we can still use the same mechansims to move people between middle-income and poor etc, and still display everything in the UI as though nothing has changed.

This was hellish, because it also means restitching together lists of totally different UI items on the fly with different calculation methods to come up with a result that looks the same as it used to. Its taken a week of fixing edge cases, checking, altering UI, and writing lots and lots and lots of code which mostly will go underappreciated :D.

But thankfully it now works, and it means we can have effects in the game which are +10% income of retired people, and also effects that are +$10,000 income of retired people, as the designer or modder sees fit. This means helicopter money can actually be fixed for everyone, free school meals no longer serve foie gras to rich students, and so-on.

You wont notice it immediately but its a massive improvement in the underlying simulation code in the game. It stressed me and tired me out so much to do it that im forcing myself not to code today so I can recover.

Liberalism/Socialism tweaks

I’ve been looking at the political compass part of Democracy 4 while running the first few decent play-tests and it was clear that the compass was not accurately reflecting my policy choices. Some further digging suggested that the problem was that not enough of the choices the player made were affecting the underlying values for global ‘liberalism’ and ‘socialism’.

In the game, every player has a (more or less) random innate level of socialism or liberalism (there are a few voter group and country based adjusters). Initially, this determines the extent to which they identify as socialists/capitalists and liberals/conservatives. The game also models all the effects on the global values of socialism and liberalism and pre-calculates how this will have adjusted voters opinions before the game starts.

I also take those global values to indicate where the country currently lies on the political compass:

It was clear that I had missed out those effects from a whole ton of policies and simulation values, where I might be upsetting liberals, but that didn’t actually make them less liberal. Obviously these are different things.

Some policies in the game (or situations etc…) anger people with a certain view, which is often instantaneous, and some actually change peoples view over time. For example, if you legalize cannabis, then this is likely to upset conservatives and make liberals happy, almost immediately as the change in policy hits the news cycles. The longer term effect though, is likely to be increased liberalism, and people get used to the idea that cannabis is legal. This is a shift in nationwide attitudes.

This has happened a lot in my lifetime. Attitudes in the UK towards homosexuality have definitely changed dramatically since I was a teenager. The idea that a CONSERVATIVE government would be the one to legalize gay marriage would have been ridiculous in the 1980s, for example. Also there have been big changes in the attitudes towards a free press and deference to politicians. (Free press in a driver of liberalism in the game). By the way, gay marriage and also gender transition are policies in the game.

In many ways, what I’m trying to model here is shifts in the overton window, which is a concept that illustrates how political values shift over time:

The way this works in our simulation is that we are effectively moving voters around on the political compass as you change policies (in fact-oh-my-god as I type this I realize I could add a mode that plots them all on there…). The actual policies you implement have to stay within that virtual overton window in which the majority of the voters are contained. In fact, I can plot it as a sort of flexible overton splat :D

I think the last two days of fiddling with this stuff have gone well, and the game is more balanced, more accurate and more fun as a result. I wrote some extra debug mode code that let me dump out a nice list of all of the potential inputs to these values to a spreadsheet so I could check everything looked as it should. Doubtless there will be further tweaks over time, in response to player feedback, but its a step in the right direction.

Anyway, thats enough blogging, I’m going to go add tiny voter dots to the political compass :D