Finished #21 in CodeCombat’s Greed tournament


I’ve been very busy during the last months. I’ve had lots of stuff to do in school, done lots of programming on my new travel app (will make a post about this soon) and I’ve also started working as a summer intern at a company called Besedo. And I’ve been to Malta. But this post is about Greed, an online multiplayer programming competition game.

Basically you had to write JavaScript code to control your workers in the game. The objective was to collect gold as fast as possible, build soldiers and destroy the enemy base.


As I mentioned in the title of this blog post, I finished #21 in the tournament. I only spent maybe 10 hours coding this, and this was in the beginning of the tournament. So I’m pretty happy with the results. During the last week I didn’t even code any new strategy, I only ported my code from the Ogre side to the Human side.

And what did I get for my participation in this tournament?

I actually won 3 things:

  • Webstorm private license.
  • O’Reilly ebook of my choice.
  • Amazon Web Services credits – $50.

Which is pretty nice! Webstorm is a good IDE for web development, which I actually wanted to buy anyways. A free ebook from O’Reilly is also nice, considering they have many interesting books about programming. And $50 credit for Amazon Web Services is perfect too, since I host the backend for my soon-to-be-announced travel app there.

My strategy

My strategy in the game was pretty simple. My strategy for collecting coins was simply to calculate the value of each coin divided by the distance from each worker. Each worker would then simply run towards the coin with the highest value per meter, unless that coin was targeted by an enemy worker which was closer to the coin than my worker. One optimization I also did was to split the map into 4 zones, and have my 4 workers take one zone each. This greatly increased the number of coins I managed to collect faster than the enemy.

My fighting strategy was not very advanced, and I could’ve improved it a lot. Here I simply waited until the enemy started hitting my base, and then I built as many soldiers as possible to fight back his attack. This usually then managed to overrun the enemy and win the game. If the enemy was too slow, or never attacked me, I waited until I had collected 300 gold, after which I simply did an all-out attack with as many soldiers as I could build. This also usually won the game.

The code

You can find the code I wrote for the tournament in my public repository here: human.js. The code is not very optimized or well commented, because it was just a quick implementation. But it did its job.

Actual game

Here is an actual game from the tournament: Foosvald vs Orson Peters. (Press the link to see a replay!)

In the game you see how my team, bottom left, reaches 300 gold and then stages an all-out attack and wins. Very nice.

Foosvald vs Orson Peters

You can still participate in the tournament, and submit code. You can’t win any prizes anymore though. But try it out, it’s fun.

See you in the next post!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>