(Invitation to a joint open source project)Why do people write game bots? - There are many possible reasons, one of them, of course, is purely academic interest in solving the complex problem AI. In the literature on the philosophy of CS and the philosophy of mathematics, programming has been repeatedly compared with mountaineering. It is difficult to say who made the first comparison. In our opinion, it is very suitable for our case, therefore, at the risk of appearing not original, we still make a statement: writing a non-trivial bot for a programmer is the same challenge as conquering a peak for a climber. The more inaccessible the peak is, the stronger is the desire to conquer it. Therefore, first of all, you need to choose a really decent peak in an interesting mountain range. One of these arrays with a multitude of complex, yet uncrowded peaks, is the game
Space Rangers 2 HD: Revolution (KR2) - a continuation of the series of games
Space Rangers (KR).
Connoisseurs of the gaming industry do not need to present games of this series, since this is one of the rather rare cases of computer games-long-livers: the
first game of the series , developed by the Russian studio Elemental Games, was published by 1C in 2002. The interesting history of the development of this game series is well reflected in the
Wikipedia articles devoted to these games, so we will not repeat here. We only note that now
SNK-Games studio is engaged in the development, support and improvement of KP2.
It was not by chance (and certainly not for empty advertising) that we mentioned the developer, since the success of choosing an object for bot-building depends on his attitude. Many developers have a very negative attitude not only to bots, but even to third-party modifications (mods) of their games, distancing themselves from user-players, reducing support to purely formal answers to a narrow circle of frequently asked questions, such as "I do not start the game." Moreover, the answers to the hotline are usually given by specially employed operators not highly qualified, who are not engaged in the development of the game and do not know it from the inside. As for the updates, if they come out, then with purely cosmetic changes. Feedback "user-developer" almost does not work. Radical ideas such as improving the balance of the game in such cases are usually ignored. In the case of CR2, the picture is completely opposite. The game is periodically updated, with each update contains major improvements. The main developers support the
forum , where anyone can get a first-hand answer on the device of the game (in particular, on the algorithms used) and express their opinion. At this forum you can find and download a lot of third-party mods, and the developers develop interfaces that facilitate modding, post free-access documentation on these interfaces, and answer questions raised by modbuilders. The same benevolent attitude is visible to the developers and to the botbuilding. Thanks largely to this, two simple bots that are highly popular with users have already been made: a bot to generate starting galactic maps and dump analysis of the current course of the game
SRHDDumpReader (by
Burning Daylight ) and a bot to generate the spaceships of the
SR2HDShipbuilder spacecraft , made by the
author of this article . We are currently (in conjunction with
tactic ) working on another
SR2HDPascalBot bot designed for the passage of planetary battles (robot battles). We will go further about this bot and tell you more, but first we will say a few words about the subject area, that is, about the planetary battles.
')

Planetary battles (PBs) are separate small tasks in the main game, which, however, can be selected from the list without going through the main game. Tasks are performed in real time with the possibility of pauses, but without the possibility of intermediate saves. Each task has its own map of the game world, which is an arena (for example, an island with mountain and flat landscapes), where a battle of player robots and robots of one or three enemy sides takes place (they also fight with each other). The goal is to destroy all enemy robots. Usually each side (including the player) has a base on which, with a sufficient amount of resources, it is possible to build one or several robots from modules. The range of modules includes various types of weapons (rocket launcher, machine gun, flamethrower, etc.), movement devices (wheeled chassis, tracked chassis, air cushion, etc.), as well as various robotic bodies, which allow to install different number of weapon systems, and some other modules. For the production of different modules requires a different amount of resources. The resources include: titanium, electronic chips, energy sources and plasma. Resources are produced by plants. In order to seize an object (plant or base), you need to bring your robot into contact with a special platform at this object. The number of bases and factories that the party owns depends on the maximum number of robots that can be built at the moment. There are still many rules that we have omitted in this short description, since they seem insignificant for an understanding of the general principle.
The task of the game bot SR2HDPascalBot is the automatic maintenance of PB in order to win. To accomplish this task, on the selected PB map, it is necessary to describe the map parameters and bot actions in a special script - for each map there is a script. So One of the components of our bot is the script interpreter. Another obvious part is the pattern recognition system, which allows the bot to get information about the momentary situation in the game world from a screen shot. And the third standard part for gaming bots is an imitation of user commands, i.e. keyboard and mouse emulation. As an interpreter, we used the freely distributed
Pascal P5 interpreter, which is a modification of the Virtue Pascal P4. Pascal P5 is written in Pascal and, in principle, should have the property of self-compilability, but we are not faced with the task of promoting Pascal from scratch, so we translated the source code of the interpreter into OO Pascal Delphi-7, making an uncomplicated IDE with a GUI and using the standard Windows API. Special functions for scripts (for example, the function of simulating the pressing of the left mouse button) are described in the interpreter as predefined, similarly to the standard ones (for example, writeln, odd). The project is at the initial stage, and we managed to get preliminary results from only two PB cards. Our bot passes the first most simple (training) card, always winning, and sometimes it wins the second more complex map. Interestingly, the first bot card passes in less than five minutes, while the author of this article spends 6-10 minutes to complete it. The best result for the second card was the result of 5 wins from 10 attempts. Unfortunately, it is not reproduced. The bot spends up to an hour on the second map, so instead of spending time on more extensive tests to get a reproducible result, we decided to focus on improving both the script for this map and the bot itself. As expected, writing a bot in draft form turned out to be much easier than good scripts for it.

So, there is a large amount of work ahead, including purely experimental, research in the field of AI, and with such small forces as they are now - just two people - it is unlikely that it will be successfully completed. There are quite a few professional programmers among the fans of the KR2 game, and in the hope of them we have already placed an invitation to take part in this project. In this article, we are addressing specialists who may not have heard about this game, but would like to participate in solving a really difficult task for the game bot. In our opinion, the KR2 is such a successful and interesting model of a certain virtual universe that it is worth spending time to get acquainted with this model in detail. But we do not aim to promote this game. A complex and interesting bot can be made for anyone suitable for this game, without particularly delving into the game itself. We have mentioned above the reasons why, in our opinion, KR2 is better suited for this than many other games.
Source code