In the beginning…

… there was a virus. Not the kind which makes you sneeze and cook eggs on your forehead, or turns your computer into a zombie, controlled with thousands of others by a Puppet Master, but virus just the same. One could argue everything should start with a word, but the word that cannot replicate itself, make itself heard, survive and evolve like a virus has life expectancy of a snowflake in hell.

As with all the viruses, it infects some part of your ecosystem and makes you, a host, multiply or spread itself. This particular specie originated in a book written by Robert T. Kiyosaki “Rich Dad Poor Dad”. It was my wife who read it and got infected by a chapter describing a rich, successful father playing Monopoly game with his son. This game helped the child to learn the value of money and assets making him money-wise in his future adult life. In our family, we have never heard of the Monopoly game before. However, when my wife saw this game in a shop window, the virus made itself heard for the first time and the game was purchased. It ended up in a stack of other board games under TV, never being opened for a few months, until the virus lost its patience and decided to act again.

It was January 2016, when our daughter, not quite 6 years old yet, pulled this game out of the pile seemingly at random and declared that she wants to play it with us. I went for a usual excuse (busy, not now, maybe later) but realized I don’t have one. Feeling defeated with no fight, I went down on the mat and started reading the rules. 40 minutes later we were playing our very first game. It was a pitiful attempt as the rules looked like they were translated to Chinese first and then back to English. A lot of things did not make any sense, but, surprisingly, the game was fun enough that we persisted. That evening I spent researching the proper rules. After grasping the essentials, I decided to find a computer version of the game to play with bots and learn basic strategies. The concept of trading and property price discovery was very difficult one without experience and I was sure there would be developers who have nailed it down for their monopoly bots. I tried a few (more on that in a separate post) different computer versions of the game, but found all of them being extremely easy to play against – virtually for me, with zero experience in Monopoly or knowledge of the game’s tactics, I could win 90% games with 3 bots on a highest difficulty, even though most of the developers employed “cheating” – bots would trade properties between themselves for much less money than they would with a human. That was ridiculous. One of the most successful board games in the world, definitely in the top 10 after the chess, and there was no artificial intelligence developed which could put up a decent fight against a noobie.

This was how the Monopoly virus got its grip on me. Our daughter became a Monopoly addict. She would talk about the games we played all the time. She went from not being able to get the sum of two dice to calculate the number of tiles to go with her chip to calculating in an instant the correct amount of change required for buying properties, paying rent in less than a month. By the age of 6, she could do calculations like 500 – 373 in her mind with no apparent effort. Naturally, when I told her that I might try to develop my own computer version of the game, one we can customize the way we like, improve the balance (more on that later) and set her up to play against her favorite dolls, she became very excited.

During my professional life, I have had only basic knowledge of mainstream programming languages. I studied Applied Mathematics and Computer Science, had my thesis written in Java, had a crack at some C, C++, Delphi  obscure projects 8-10 years ago. More recently though, I have been mainly focusing on database development, MS SQL, Oracle, Amazon Redshift/EMR etc, transactional systems as well as big batch data processing, ETL, AI development, predictive analytics and the like. By March 2016, more and more colleagues at work started using Python for processes orchestration as well as semi-complex data manipulation. I have never used or studied that language before, and I felt like I am missing out as pretty much everyone knew it from the time they were students. So, I decided to learn it by writing Monopoly game in Python, my very first attempt at having my own weekend project.

First version of the game became playable by June 2016. It used pygame where developer had to blit the picture on the screen 60 times a second to create illusion of moving objects, and work with application in a main loop. It was fun to develop, but I quickly realized pygame was not really suitable for any advanced graphics – even for a simple things it was too involved. Trying to make the chip to move smoothly over the board without cutting corners was challenging enough, but even that did not look real without chip jumping from tile to tile. The bots were not very complicated either, although even then they were 10 times better than the bots available elsewhere. Most importantly, I decided I will never use preferential trading to make the game more difficult for a human player which is just a quick hack to cover developer’s shortcomings in ability to develop smarter AI. On top of that, I decided my AIs would never try to gain or use any information not available to a player, nor they would ever distinguish a human player from another bot regardless of the difficulty level. Given those limitations, one can say I had very little room to make the game more or less challenging, or make different levels of difficulty as those rules worked both ways – not only AIs are not allowed to treat human worse than AIs, they are also not allowed to treat them any better than AIs on any difficulty levels. In a separate post, I will explain later how I turned those rules into opportunities for making AI smarter and AI’s levels more, rather than less, diverse.

I packaged the game up as an MSI file for Windows, and it did not work on any other platforms. But the Monopoly virus was not satisfied: it wanted to be released to much wider audience than Windows PC owners. Besides, how many people download and install games developed by independent devs for Windows PC? Anyone? I certainly had never downloaded, or even been looking at one. If I want a game for my PC, it would be something which requires PC performance, has good graphics and would generally weight a few GBs. Therefore, I needed to make this game work on multiple platforms, and most importantly, on 2 most widely used mobile platforms – Android and iOS. But here comes the problem – apparently, one has to develop app for Android in Java and for iOS in C. I had no intention of switching from Python – most of the AI logic I had would be a nightmare, both performance wise and number of lines of code wise, to implement in a language like Java. Fortunately, there was a solution – an open source project Kivy with great documentation and support: https://kivy.org

Kivy, Kivy, Kivy. Unfortunately for my app, switching to Kivy meant I had to rewrite my app from scratch. On the other hand, developing in Kivy was much, much easier. You also get a cross-platform support for free, as well as great variety of predefined widgets which you can choose, modify and mix to create your own. Switching from a main loop management in a pygame to Observer Pattern properties implementation was a very welcome improvement. I will write up a different post at some point about my experience learning and using Kivy. Here I just want to say that Kivy is AWESOME and learning it was a breeze – I have never had to contact anyone about anything, everything I needed was already available online or someone has already asked it and got the answer.

For a couple of months I was learning Kivy, experimenting with it, trying to make sure the platform would be up for a task. It was. It then took me a month to rewrite my Monopoly in Kivy, and then another few months to add design features – now I had to worry about stuff being visible and taking correct amount of space on a screen, any possible screen resolutions, etc. All this time AI kept playing against each other (and occasionally me) and became better and better at recognizing patterns, strategies, trading opportunities and evaluating properties.

So far, knowing all the tricks AIs can use I am winning only around 45-50% of the games playing with 3 Monopolist AIs with no preferential trading or any other “cheats”. Human will always have certain advantages over AI, and AI will never use any data, tricks or abilities not available to a human, regardless of the difficulty level. I also have a version of Champion AI level which is not going to be released to the public (not now, anyway) as winning that level would be way too hard for pretty much everybody. That level behaves like an emotionless Super Robot and playing against it (or rather losing to it most of the time) is little fun. It has little to no biases, allowed to refuse trades if he is not interested in them (even Monopolist always gives a counter offer even for something he does not need at all) and is focused on eliminating (or rather ignoring most of the trades) the opponent with highest NET first.

In the next post, I will talk about the game’s balance, pros and cons of the classic Monopoly as well as different options to improve it.

Leave a Reply

Your email address will not be published. Required fields are marked *