OkayAndrew

Monopoly

[Download Monopoly in Excel here]

Here’s the project that got me to start this site.

For the past few years at work I’ve been doing some programming in Excel using Visual Basic for Applications (VBA). I find it convenient for certain projects because it’s a relatively easy language and practically everyone in my line of work has Excel, which is nice when you’re trying to share your work. It’s not the most powerful language out there and I’ve found myself having to work around certain limitations, but I find it to be a very handy tool.

About a month ago I was playing Monopoly with my wife and a friend. Afterwards I got to thinking about different strategies for playing. It seemed that the properties between “Jail” and “Go to Jail” would get more traffic than the other half of the board and would therefore be the best to pursue and build on. Even as a kid I was skeptical of the utilities, wondering if they were worth purchasing. I decided the best way to investigate different aspects of the game (and ultimately come up with an unbeatable strategy) would be to create a Monopoly simulator.

After about 12 to 14 hours of work I completed a four player game of Monopoly in Excel using VBA. Below I get into some of the features, interesting development issues, and future work. While I might go back at some point and put in some additional features I’m content with the project where it is right now. Feel free to look at the code (Alt + F11) to see what I did and let me know if you have any questions. Also, in the interest of not breaking any copyrights I suggest you not actually play this game in Excel and instead buy it at a store.

Here are some of the features:

  • Player names can be overwritten to whatever you want
  • Display to easily tell how much money and property each player has
  • Automatically calculates the 10% income tax and pays that or $200, whichever is less
  • Properly determines rent when landing on utilities, railroads, or properties
  • Allows players to build houses and hotels
  • All Chance and Community Chest cards included
  • Able to make trades for money, property, and “Get out of Jail Free” cards
  • Forces the player to mortgage property when out of money, but they can be unmortgaged later
  • Apparently everyone but me grew up playing that the money spent on taxes, Chance, or Community Chest went into the middle of the board instead of the bank, and if you landed on Free Parking you got that money, along with an initial $500. I put a toggle button to turn that on or off

Here are some things that came up during the development that I thought were interesting:

  • You can make most of the icons that you’d want to put on the board using wingdings and webdings (Trains on the railroads, a diamond ring on Luxury Tax, etc.)
  • I never thought about how many rules and options there are to this game until I had to translate them into code
  • Making the player icons move across the spaces instead of “teleporting” caused a headache until I found the “DoEvents” command
  • I reused some code from a blackjack program I wrote to handle shuffling and dealing the Chance and Community Chest cards

Here are some things that I would still like to do

  • Property names are unfortunately hardcoded. I would like to make this editable, so the user could personalize the game
  • Adding all the icons and letting players select their own would be nice
  • I’d like to make some of the players computer opponents, each with their own risk factor to determine when they would buy, build, and propose / accept / reject trades
  • Using the computer players I could automate games using different strategies to try and optimize the way I play the game
  1. emztrollinc reblogged this from okayandrew
  2. gavin-maher reblogged this from okayandrew
  3. okayandrew posted this