This week is the Computer Science Education Week and in particular the “Hour of Code” event. This year, Hour of Code is extending the scope of its activities to intermediate and advanced lessons. At CodinGame, we’re supporting the movement and we’re providing an opportunity to discover a field that everybody is familiar with, but actually uneducated about: bot programming. Introducing programmers to Artificial Intelligence through fun challenges of bot programming in just one hour?
Let me guide you.
A matter of trust (5 mn)
I have the feeling you’re not convinced. And I understand, I’ve been there. I remember that feeling I had the first time I entered a bot programming game. “I can’t do it”. “This is too complicated”. “I have no chance against regular players”. With this state of mind, you won’t go far. Trust yourself and your capacity to learn. Everyone has been a beginner at some point. One thing at a time. Ready?
Warm-Up (5 mn)
In Computer Science, a bot is a program that reacts to its environment and is able to conduct autonomous actions. In concrete terms, writing a bot on CodinGame is writing a program that is able to take inputs into account and calculate an output. Doesn’t seem impossible after all.
Take a deep breath and relax, you’re going to have to win a pod race!
Getting started (15 mn)
Here’s the link to start coding: Coders Strike Back. The game is played on a 2D map with several checkpoints. A pod-racer should pass through all checkpoints in a definite order several times (3 laps). The program should control the direction and speed of the pod-racer depending on the inputs.
First you have to choose your programming language. A basic program is provided, you don’t have to code it all by yourself. But it has a bug…
Don’t panic! Take your time to have a look at the code. You are given 2 pairs of coordinates through the standard input: the position of the pod, and the position of the next checkpoint to pass. The program is expecting you to output the coordinates of the target you want your pod to reach as well as a thrust value to propel the pod. Look closely at what is sent through the standard output, I bet you can find the bug and finish the race.
Creating a first AI (20 mn)
Until there, it was quite simple, you were racing alone. Your bot is now ready to face other AIs. Don’t worry though, there is a league system which ensures that you’ll encounter bots of the same level. You’ll first race against the boss and maybe reach the wood leagues. What happens in a league is that your bot will take part in multiple races against other AIs. Your bot win rate will impact its rank.
In Wood 2, you are given new inputs, including the angle between the orientation of your pod and the direction of the next checkpoint. It doesn’t mean you have to do complex calculations though. You can first try to change the thrust value depending on this angle. Indeed your pod cannot turn too quickly so if it has to do a U-turn, it better slow down first.
Getting further (10 mn)
So far, it has not been too complicated. Your bot is already able to choose its direction and modify its speed according to input parameters. You have coded a bot. A simple one but still a bot.
Let’s discuss quickly what could be the next steps for this game.
- Boost option: in the next league, your pod gets a new power. It can use once per game the “boost” option which will greatly increase its speed for one turn. How to implement it? An idea could be to check if there is a long distance to the next checkpoint and if the pod orientation is aligned with the checkpoint.
- Checkpoint prediction: there are three laps in a game. So after the first lap, your bot can know where are all the checkpoints. Hence it could adapt its speed and direction when arriving at a checkpoint to be ready to race to the next one.
Possibilities are endless and this is what makes bot programming so entertaining. Each strategy you want to implement will make you learn new things. Start small, everything is possible!
There is more (5 mn)
We are super happy to announce that you won’t be alone to discover bot programming. Master Hellish, a youtube creator, will be streaming Coders Strike Back on Wednesday 7th of December at 5pm UTC on Twitch. Here’s the Facebook event.
Other programmers have already spent a lot of time on these bot programming games. There is a lot to learn from these regular competitors, so I advise you to check these helpful resources:
- Explanation of the strategy of the winner of the Coders Strike Back competition
- How to build a good AI on Coders Strike Back by Magus
- Manwe’s github project for programming competitions which includes a list of great tips.