Post Format

Programming an Economy

Today I started working on the code for the first major project I’m doing just for myself in Python. Well, not just for myself. This is a program I promised to write for my brother, as a birthday present.

See, he likes to play this amazingly complex game, Crusoe’s Planet. The economy in this game is very sophisticated, and the game has a market stage that takes a lot of time. Everything stops as you sit down and do a bunch of calculations for buying, selling, and trading commodities in the market. So I offered to write him a program to take care of those calculations.

Image of computer screens and notepad

– Writing the code: Market rules written out in steps on the left, starter code on the right. –
– (Yes, I know I need to do some serious cable control. I’ll get to that … eventually.) –

This will be nothing new to anyone who has programmed, well, anything, but I’m constantly surprised at the complexity with which humans think. Anything—anything—that we do in our heads takes so many more steps once you start breaking it down into a program. The notes I wrote out on my yellow pad are a careful list of steps that were described in paragraph form in the game instructions … and even my notes are simplified compared to the program.

But once I got started, the structure started to fall into place. Here’s where I am now:

  • I have a class for game-level information: the commodities, the money available for producers of a certain commodity, the players in the game.
  • I have a class for player-level information: a player’s money, a player’s commodities (either produced or bought).
  • I have methods for getting at and changing the game/player information, which will be used as players buy, sell, and trade commodities.
  • I have a method for checking which players are sitting next to each other, which is important because players can only trade with the people sitting next to them. I’m not sure if I will keep this method, though … it may become redundant, but I haven’t thought out the entire trading step yet.

I may have to modify some of these classes and methods as I get further into programming the game play itself, but I feel like I have a pretty solid foundation for moving forward. I’ll be sure to give updates on my progress!


Posted by

Happiness Engineer for Automattic, the company behind Linguaphile and Translator. Tester.