I remember the first CodinGame bot programming contest I participated in. That was not so long ago, as I only discovered this platform quite recently. It was Mean Max. Very chaotic, incredibly fun, but at the beginning I was more like:

“Oh my god, my bot must control several vehicles, each having its own specific use… And there is no braking!! I’m not sure I’ll be able to do that.”

As I read the chat, I saw some CodinGamers talking about very complex terms – heuristic, simulation, evaluation function, deep learning and so on – like it was all very obvious to them. At some point, I wondered if I had any business being in this contest, because I didn’t understand any of this. The only things I knew were “if”, “else” and boring variables. Plus the logic that makes me a developer.

Guess what? It was more than enough to have fun in the contest and reach a modest but satisfying rank! (I finished 504th out of 2512 participants, in the Silver League). Today, with the same “weapons”, I generally manage to end up in the Gold league.

So, if you think you’re not good enough to participate in a contest or if you have a hard time reaching the Bronze or Silver league, this article is meant for you! I will give you some advice and methods to rapidly reach the Bronze league (where the fun actually begins) and get the most out of simple if/else algorithms. And you will quickly get better at this, I promise! (I did.)

Prepare for Battle!

Answer the Call

Some see a coding contest only as a competition. You win or you don’t. So what’s the point of getting in if you know you won’t win it?

Well, what is incredible in contests is the impact that the competition has on both your motivation and state of mind. Participating in a contest is like running for a race: before the race, you prepare for it, both physically and mentally. You’re excited about it; you can’t wait for it to begin. And when it finally kicks off, you get this rush of adrenaline that makes you give the best of yourself.

If, at the end of a contest, you’ve managed to learn something, developed pride in your bot or simply had fun, then you’ll have won.

So, don’t hesitate. Check the dates of the next contest, ensure you’ll be able to spend time on it, and register!

Assemble Your Team

You can participate in a contest by yourself, alone at your desk or from your couch. I’ve done it and, honestly, it’s quite fun. But the experience becomes much more enjoyable when you share it with others! Even with just one person, a friend or a colleague at work.

You will discuss strategies together, confront your bots, share your ideas for improvements, advise each other when you notice something wrong in someone’s code. And you will brag that your bot defeated the other’s bot, just before getting crushed in the next battle…

Choose people with whom you get on well: it gives a huge boost of creativity and motivation. It’s called emulation.

I want you

Find a colleague or a friend who will register and participate with you in the contest!

If you don’t find someone, there are still CodingHubs! Personally, I didn’t get the chance to attend one, because there are none where I live. But it could be a place to find teammates…

Grab Your Gear

You will need a computer, of course. For beginners, the coding environment provided by CodinGame will be enough. For those among you who are already trained developers, you can start a project in your favorite IDE.

But whatever your experience as a developer, I advise you to use another simple tool: a VCS (Version Control System). It will allow you to keep track of every version of your code, to easily check out a previous version or to take note of the rank reached with each version, so you can submit the best one at the end. Let’s say Git, for example: you can quickly create an account on Github or GitLab, add a new project and start versioning your code. It’s a matter of minutes. And it’s really more comfortable than copy-pasting a backup file or having to remember everything you did since the last time you submitted…

Identify Your Target

You have to set realistic objectives for yourself. You probably won’t reach the Legend league in your first attempt.

League levels: from Wood to Legend

It is important to choose a reachable but challenging target. For example, “Reach the Silver league”. I think it’s a good start because it’s not that hard, and Bronze is the first league where your bot plays with all the rules. So, if you reach Silver, it means that you managed to beat the Bronze boss using all of the game rules.

At the end of the contest, if you have reached your objective, whether your code is ugly or doesn’t manage all wanted cases doesn’t matter much. If you enjoyed the game and you want to perfect your bot, you will be able to do it when the game is published as a multiplayer game, and you are no longer limited on time.

So, what do you think you can achieve for a first try?

Work Out a Bit…

If you want to perfect your preparation for the upcoming contest, I recommend trying to solve CodinGame practice puzzles, as training.

You can practice distances calculation and trigonometry, as many games involve x/y coordinates.

You can try guessing basic rules from the contest artwork, once revealed.

Xmas Rush coding contest artwork

Artwork of the coding challenge “Xmas Rush”

For example, in the case of Xmas Rush, one can clearly see a maze on the back of the artwork. So, there are a few chances that you will have to code something to help your bot find its way through a maze… You could therefore practice on “path-finding” puzzles. Personally, I solved The Labyrinth as training. The worst that can happen is that the contest actually involves no path-finding: I would just have learned something (which is always useful).

Legends of Code & Magic clearly involves a card game: practice permutations!

Legends of Code and Magic artwork

Artwork of the coding challenge “Legends of Code & Magic”

Use your imagination. Given the picture, what kind of game could it be? And which puzzle could contain similar mechanisms?

Don’t panic if you can’t reach a score of 100% on a puzzle! Especially if it is a difficult one. As long as you thought about it, maybe solved some test cases, your brain will keep thinking about it until the contest starts. It’s a head start.

Ready? Fight!

Ok, the contest has begun. It is time to code your bot! You’re discovering the rules of the first league. But where to begin? The game seems so complicated to handle fully…

Well, first things first! How do you eat an elephant?

One bite at a time.

In this part, I will use concrete examples from Mean Max. In a nutshell, the game involves a circular map representing a patch of desert where water tanks wander. The goal is to destroy the tanks and collect water. That’s it! To achieve that, you control three vehicles: one destroys tanks, creating water ponds on the ground; one pumps the water from the ground; and the last is just there to give you abilities and disturb your opponents.

Collect and Store Inputs

The first thing I advise you to do is to properly collect and store the game inputs. Don’t try to process it at first, just store it. When you get used to this kind of game, you will be able to process it partially as you read it, saving a few lines of code and increasing performance. But for now, do this in two steps so you don’t get lost. Anyway, performance is not your main concern during your first contest.

Spend some time thinking about how you’re going to store the data. In Mean Max, you will need to access at least the positions of your vehicles, the water tanks and the water ponds. Maybe the opponents’ vehicles positions as well. Code the data collection and display it as debug output in the CodinGame IDE. Right now, you don’t really care about the output of your code: just put something that doesn’t crash the game.

Once you correctly visualize the data of the game in debug output, you can safely move on to the next step.

Keep It Simple, Keep It Working

In bot-programming games, you will have many ideas to improve your bot and will be tempted to implement them all at once. Don’t fall for it! It’s too much work, and unless you have gigantic amounts of both energy and free time, the contest will be over or you will have given up before creating the dream bot.

Remember, a contest is like a running race. You don’t win a race with just your legs, but also with your head: morale and confidence are key!

So, keep it simple at first; implement your ideas one by one, starting with the simplest. In Mean Max, you could start by moving your one and only vehicle to the first water pond of your dataset, no matter where it is or how much water it contains, and submit to see the result. That shouldn’t take too long. It won’t be very efficient*, but it will allow you to quickly see the results of your work.

Then, you can improve your code a bit by moving the vehicle to the closest water pond instead. And so on, until you’re promoted to the next league (which will happen far sooner than you think). Then, you will have more rules to manage, so you will be busy.

* You would be surprised to see that a very simple feature on a working bot can earn you many places in the ranking – even a league promotion sometimes! Personally, my bots never manage all the rules before the Silver league. I don’t try to; I simply focus on the most important rules at first.

The important things to keep in mind:

  • Improve your bot by small steps! And always validate the effect of your improvements by submitting your code.
  • Keep your bot in a working state at all times to avoid morale loss.
  • Don’t forget to keep track of each step in your VCS (basically, each time you submit, at least). In case an improvement actually decreases the performance of your bot, you will be glad to be able to go back to a previous state.

If you have time, read the article Legend of the Lazy by Bob, in which he defines keys to laziness and shows how he applied them during a former contest.

Get Your Ideas in Order of Battle

If you have too many ideas and can’t decide where to begin, here is a simple but efficient method:

  1. List your ideas
  2. For each idea, evaluate the positive effect you think this improvement will have on your bot’s performance, and give it a score from 1 to 10
  3. For each idea, evaluate the time you think you will need to spend on this improvement before it works, and give it a score from 1 to 10
  4. For each idea, divide the “positive effect” score by the “time spent” score: this gives you the theoretical profitability of your idea
  5. Start with the idea with the highest profitability!

Watch Battles

The final result of your code is your ranking in the leaderboard. But the ranking does not tell you what is wrong with your bot (believe me, there is probably something wrong ^^’). The replays of your previous battles do!

last battles of Mean Max

Watching battles allows you to see how your bot behaves in real conditions.

Once in a while, you will see something weird and think: “Why is my bot behaving like this?! That’s not right”. This is an opportunity to improve it. Send the battle parameters to the IDE and add debug information to understand why your bot misbehaves. The problem is often something silly, like a specific situation that you didn’t think of. Once you know what is wrong, fix your code, check if your bot behaves better at the same game, and then move on to the next replay.

At some point during the contest, you’ll most likely reach the end of your ideas list. This is a good time to spend some time watching replays – and don’t forget to take notes!

If you can’t find more ideas watching your own battles, spend some time watching battles of the top players in the leaderboard. You might discover inspiring strategies or behaviors… If you managed to find a friend to participate with you, you can also challenge his bot and watch the replay together.

May the Force Be with You

Thank you for reading this long article to the end. I hope it will help you overcome the fear of participating in a contest. Let me know! And come back to share in the comments how it went. 🙂

I’ll see you during Xmas Rush!


Join "Xmas Rush" challenge