📜 ⬆️ ⬇️

A game for those learning to program: Colobot

Many years ago, a friend brought me to play one toy for those who are learning to program. Even then I programmed quite well, and I thought that the game was not for me, but I decided to try.

Colobot turned out to be a very exciting game, and I still consider it one of the most interesting games I've played.



Game plot


Earth sends an expedition to other planets to create a colony. You are an astronaut, commander of a group of robots, which must colonize and protect the planet from a dangerous invasion.
')
Each level begins with the landing of a spacecraft base on a new planet. You command robots and control the base and infrastructure for the colonization of the planet, performing assigned tasks.

Game process


Colobot is a real-time strategy game with a 3D engine. All units obey the astronaut. But, besides the fact that our hero is an astronaut, he is also a programmer and controls robots by programming. That is, you yourself write the scripts for which your subordinate robots work. Robots are of different types, from military and intelligence officers to researchers and repair robots.

Each robot has a set of scripts, and you can run any of these scripts at any time. We write the scripts ourselves, and with each mission and level in reserve, they become more and more.

The scripts are written in the CBOT language, which is similar in syntax to C ++, Java, C #. Description and features of the language can be found here .

Billing algorithm


Consider one of the algorithms on the example of a refueling bot. In the game, every bot and building has a battery. If it ends, the bot turns off, and the building stops working. To continue, the battery needs to be replaced. The replacement process can be automated by creating a refueling bot and writing an algorithm for it.

Algorithm for bot refueling:
  1. Come to the factory or warehouse of batteries and take the charged.
  2. Find a dead unit and drive up to it.
  3. Put a new battery next to it.
  4. Remove old.
  5. Take a new one (which was previously put).
  6. Install the battery in the unit.
  7. Take the old battery.
  8. Take it to the rechargeable battery building.
  9. Wait for the battery to charge.
  10. Take to the warehouse already charged battery.


What happens if a robot that charges and changes batteries runs out of charge?

Here is one of the options for writing the CBOT bot recharging algorithm.

extern void object::FieldRefuel() { object power=radar(PowerStation); object bot=radar(TrackedShooter); //only watches 1 bot errmode(0); //don't exit on errors while(true) //infinite loop { while(bot.energyCell.energyLevel < 0.26) //1/4 energy { goto(bot.position); wait(1); goto(bot.position); //movement correction drop(Behind); //switch cells grab(); turn(90); drop(); turn(-90); grab(Behind); drop(); turn(90); grab(); goto(power.position); //refuel wait(7); move(-5); } } } 


Current state of affairs


The game was released in 2001 by Epsitec, and at that time it was paid. Later it was transferred to TerranovaTeam, and now the game is actively being finalized and finished. This free, non-commercial version is the Colobot Gold Edition. Developers plan to start writing Colobot 2, ideas are discussed.

To see the finished working algorithms for bots, you can refer to the passing game, which is available in the game itself. In addition, some algorithms are on this site .
Colobot Gold is available for download on the official website for Windows and Linux.

CEEBOT


Colobot is a real-time strategy based on programming, but Epsitec has a game that is even more focused on programming, on the same engine - Ceebot. This game and its assignments are specially adapted for learning programming.
But for free download is available only part of the missions. There are versions of the game for different age categories from ten years.
The official site of the game .

Summary


First of all, the game will be interesting to novice programmers who only learn the basics of coding. But it can also interest and experienced developers.

Interesting graphics and fun gameplay will help to get into the game quickly enough and not regret the time spent on it. Program site .

The author of the article: teacher of the educational platform GeekBrains Dmitry Polyanin

Source: https://habr.com/ru/post/276091/


All Articles