⬆️ ⬇️

Boat in the anthill



Another game bot for Space Rangers HD ( 1C publisher) suggests interesting thoughts on how to develop artificial intelligence (AI).



Some lyrics



You can paraphrase an epigraph into a riddle:



Flies in a circle

Doesn't bother anyone,

With her take off,

And they are killed ...

')

(Rogeria)



Some theory



Machines are made to facilitate the work of man. And, moreover, to perform work that a person himself cannot do. For example, an ordinary person cannot lift a load of half a ton, but with the help of a system of blocks, he can. Computers — computers and software for them — serve the same purpose as other machines. For example, the task to sort several tens of thousands of words alphabetically will be tedious for a person, he will do it for a long time, and the probability of mistakes for an average performer with an average level of responsibility will be significant. A modern computer will perform this task without errors in a very short time for a person (a split second). All this is well known and said here only to define the AI. Without claiming originality in this definition, I note that there are a lot of definitions of AI, therefore, before talking about AI, we have to specify this term.



So, we propose the following definition : the AI ​​includes tasks that the computer solves noticeably worse than a person.



It is clear that if we compile a list of such tasks for today and a list for problems fifty years old, these lists will differ. However, the differences will not be as strong as the differences in the general computing capabilities of today's computers and computers, which were half a century ago. That is, the performance and memory volumes increase by many orders of magnitude, and almost all difficult tasks remain intractable. There is intentionally ambiguity. From the point of view of the theory of computational complexity, intractable problems are problems with an exponential theoretical estimate of the number of operations of the dimension of the problem in the worst case. While the main question of this theory is “P =? NP ”continues to remain open. In AI, there are tasks “simply” solved by a blunt brute force if such brute force were possible in time, for example, chess. However, many other AI tasks obviously do not require an exponential number of operations and at the same time look intractable not because of computational complexity, but because of the difficulty of constructing reliable and efficient algorithms to solve them. Obviously, such a second meaning of the term “difficult to solve” is qualitatively different from the first: in the theory of computational complexity, this term means a strictly provable exponential estimate, while in the second meaning, a strict mathematical proof of the difficulty of constructing reliable and efficient algorithms is extremely difficult. At the same time, we do not consider algorithmically unsolvable problems and assume that if a person copes with a task, then there is an algorithm for solving it.



At the present stage of development of AI, human skills look like the ideal to which one should strive, however, a person often makes mistakes. The level of these errors is different - from elementary errors caused by a lack of necessary knowledge of a particular person, his inattention, fatigue, to more complex ones such as illusions and cognitive distortions . From here follows an important question: is it possible to solve AI problems better than a person does, i.e. whether “super-intelligence” is possible, or a series of AI tasks in principle cannot always be solved correctly, i.e. Will there always be a nonzero probability of an erroneous decision? A few examples were in my previous publication , in particular:



A well-known example of difficult [for human] recognition is captcha, which you come across on the Internet at every turn. There are such scribbles that you have to press the captcha change button several times before you can “prove that a camel is not a robot.
Another important point mentioned in this publication is autonomy:

absolute autonomy is a harmful myth. At least for the coming decades. On his own and others' experience the author [David Mindell, “The Rise of the Machines is Canceled! Myths about robotization ”] shows in detail that these days the most successful are systems where human interaction with an automaton is fully realized, and not alienation of a person from the decision-making process. Personally, I was convinced of the correctness of this idea on my modest example of game bots for the KR2HD game: the bot for planetary battles, according to our co-author, should be completely autonomous, and now this project is stalled.
So, many definitions of AI have been proposed. In accordance with these definitions, there are various classifications of AI tasks. Without pretending to originality (as in the case with the definition), take the following classification. This is a classification by purpose.



The goal of a rational AI is to choose the level of autonomy, on which:



1) the program will be useful;

2) the program will not be mistaken too often, compared with a person;

3) the program will not be overly difficult to write, debug and maintain.



Another class in our classification is the “revolutionary” AI. His goal is to make the program as autonomous as possible. Such a program is usually of scientific and sporting interest, despite the fact that its practical value may be close to zero.



From the point of view of the above classification, the solution of the problem posed below is rational. Nothing particularly revolutionary is proposed here, but I express the hope that such a moderate approach, based on real possibilities and oriented towards practical use, is of particular interest to science.



I note that the definition does not specify the method of solution. A simple practical ideology follows from the proposed definition: if a problem is detected that a computer solves worse than a person, then this is an AI problem. And you can solve it as you please - just to decide: you can use neural networks and training, but you can not use it. It remains to hope that the proposed rational approach, as a result of the application of which an inevitable accumulation of experience in solving such problems will occur, will advance the AI. In general, this is what happens: too ambitious projects fail, and more modest ones slowly, but still promote AI to new frontiers.



It should also be said about the methods of research of AI. Of course, even a simple robot, assembled from standard parts of the designer of robots, is very spectacular, contributes to the popularization of AI ideas and well attracts not experienced in AI sponsors. Unfortunately, reproducing an experiment with such a robot will encounter obvious difficulties, and the scientific method requires reproducibility. Therefore, from a scientific point of view, a game bot for a fairly common game that is not specially written for this laboratory research is more interesting.



And, finally, moving from theory to practice, we note that, probably, it will not be possible to find a fundamental work on AI, where philosophical questions, closely related to AI, would not be mentioned. Without at all minimizing their significance, we note that the definitions proposed above make it possible not to delve into many of these issues in this work.



Task



The main goal of the game KP2HD is to score as many points as possible. Points game calculates the formula:



Points = Experience * Difficulty / 100 / max (7, Play Time / 365) ^ 1.3 ,



where Experience - is charged including for the destruction of enemies, in particular, for the destruction of pirates;

Difficulty - from 50% to 200% among other starting conditions is set by the player before the start of a new game;

Game time is the days in the game: each turn is one day.



The game begins with a game date of January 1, 3300, and can be developed along several storylines. However, experienced players know that the greatest number of points brings a long-term battle with pirates (more precisely, their beating) in the Tortugac star system. This is the culmination of the game: the previous part of the game is, in fact, the preparation for this battle, and the next part is very short and consists in finishing the game on the corresponding base chosen as quickly as possible in a few game days, as in the future the points will only go down . The sharp increase in the number of pirates destroyed by the player, accompanied by a sharp increase in points, is clearly visible on the charts of the top of the game records table : Robo Brain is in first place, SHERIFF is in second:









As you can see, the battle lasts several game years, but can last up to 20 years or more. When playing a record with a search of several options to achieve the maximum number of points (this gaming technique will be discussed below), the player can spend several real months and more on the Tortugac battle!



The Tortugac system becomes available to the player after completing a number of tasks, the description of which we will not dwell on. The system consists of two uninhabited planets and one pirate base called Rogeria, which, like the planets, rotates in a circular orbit around a star. The orbital diameters are different, so a collision is impossible. After performing several actions, arriving at Rogeria and taking off from it, the player gets the opportunity to destroy about 13 pirates each turn, who will take off daily from Rogeria's “nest”. There are different weapons in the game, but the so-called weapons of mass destruction (WMD) are most suitable for this battle: Vertix and IMHO-9000.







The figure in the lower left corner near the stylized cube shows the weight of the item. Thus, the vertix shown in the pictures weighs 190 units, and the IMHO-9000 weighs 113. The Gorand is a so-called micromodule, which when installed in an instrument increases its strength, as a result, the instrument wears less with each shot and with response shots of enemies. The installed micromodule cannot be removed from the implement. Wear is indicated by the “thermometer” at the top. An important feature of the weapons of mass destruction is the defeat not only of the enemy ship, which the weapon is aimed at, but of all enemy ships within the range of the weapon. At the same time, if the target of the next gun is so fragile that it will be destroyed from the previous shot, then the next gun will have nowhere to fire: within the course of the turn, the salvo does not occur simultaneously, and the guns fire in turns. Therefore, the player applies the following tactical method: launches several spaceships of robots, called tranclucators (or simply trunks), and shoots at them, then a significant part of the energy of the shot goes to the pirates.







Each player of this trunk target is equipped with a protective field generator (GZP) and a repair droid fixing the trunk trunk in advance. Due to this, the trunk can withstand multiple shots from one or several OMP player. All equipment used on ships gradually wears out, but wears at different speeds. The PPM practically does not wear out over many game years, while the repair droid wears out relatively quickly. To repair a droid and other equipment, other than OMP, there is an artifact of nanitoids (or just naniki, see fig.), When installed, a worn-out equipment can be repaired in a special slot of the ship in just a few moves (except the one mentioned above). , radar, capture and scanner). Each ship has a hold where unused equipment, armaments and trunks can be stored. In the hold, all these things almost never wear out. Therefore, in order to avoid premature wear of naniki, they should be immediately removed from the slot in the hold at the end of the repair.



As already mentioned, OMP nanishi not repaired, so after complete wear, the OMP has to be thrown into space, where it can be picked up and taken to Rogeriya using a trunk equipped with a grip. For the success of the Rogerie campaign, a very good equipment of the player’s ship is necessary - in this case even a few dozen pirates will not pose any threat to him, like ants to a bug.



During the battle, the player's ship to Rogeria should not sit down - as soon as he sits down, the battle will stop and the pirates will stop massing every day under the player’s guns. Therefore, the player takes with him as much as possible of the WMD. This number is limited by the player’s ship's capacity - the maximum allowable total weight of all things on the ship. However, even here there is a tactical device that allows you to take more weapons of mass destruction than the ship can hold. To do this, put the WMD in the trunks slot slots. Each trunk, like the player’s ship, has five gun slots (ships with a smaller number of slots for the Tortugac battle will be ineffective and usually will not be used). Loading weapons of mass destruction, like other things, into the trunk hold is meaningless, because when loading a trunk into the hold of a player’s ship, a trunk will automatically unload the entire contents of its hold into the ship’s hold. However, the tools installed in the trunk slots of the trunk, and the equipment installed in other trunk slots (usually the engine, fuel tank, repair droid, GZP, and sometimes seizure — you can read more about the equipment here ) does not unload the trunk. The weight of such equipment is not taken into account for loading the player’s ship. For example, the weight of a trunk in a picture will always be 49 units, even if an OMP with a total weight of 500 units is installed in its slots. Therefore, in addition to the target trunks, the player takes as many trunk trunks with spare sets of weapons of mass destruction as possible into Tortugac, and fights with pirates until all weapons of mass destruction become useless.



The following screen shot of the game shows a section of the screen with Rogerie on the right, the player’s ship and the target trunks. OMP icons for trunks indicate which player's weapons of mass destruction are aimed at them. The picture also contains numerous barrels of fuel that fall out of the pirate ships during destruction. In addition to the barrels, there are still minerals produced by the collision of meteorites with ships and the base. The green dotted line running from the player’s ship to the trunk shows the ship’s course, which he will follow next turn. In this case, the ship will follow the trunk.







To set the course, the player needs to hover the mouse over a point on the screen and click the left mouse button (“click on point”). If this point is located near the trunk, the ship will follow the trunk not to the point on the screen to which it was indicated, but where the trunk will fly. If the point is in the vicinity of Rogeria, then the ship will land on Rogeria and the battle will end early. To land did not happen, you need to double click on the point. All these features of the course should take into account the game bot.



As you can see, from the point of view of movement, the game space seems to be two-dimensional, however, it is worth considering the third coordinate axis perpendicular to the screen plane and directed towards the player, since the objects of the game world (ships, base, barrels, meteorites, etc.) are placed on different layers along this axis can overshadow each other.



To zero, the farthest from the player layer, should be attributed background. In the game settings, we turned off the background image, so the background became evenly black. On the next layer are the planets and Rogeria. On the next - barrels and meteorites. Thus, the figure shows that some barrels block part of Rogeria. Next on the next layer are trunks and pirate ships, then the WMD icons, then the player’s ship, the fire of shots, and finally, the information layer closest to the player: the messages and dialogs of the game close all other layers.



Using the keyboard function keys, you can save and load the game. So, when saving, a dialog with the name of the system appears on the screen - in our case there will be a “Tortugac System”. If such a save has already been made, the next number is added to the name of the save. The saved game will be recorded to a file with the same name and extension “.sav” in the internal encrypted game format. To activate the dialog, just press the Enter key on the keyboard.







A very important feature for the bot is the current game dump: by typing “MAKEDUMP” on the keyboard while holding down the Ctrl and Shift keys, we’ll see a dialog, just like when saving a game. However, by pressing the Enter key, we get not only a file with the extension “.sav”, but also a text file with the extension “.txt” under the same name. The file has a tree structure, written using nested brackets, which contains a lot of necessary information about the player’s ship and the trunks activated by it. Unfortunately, some necessary information is missing there. In particular, trunk trunk wear is not true to the game. The screen coordinates of each barrel are indicated, but there are no coordinates of Rogeria and active trunks. This information will have to get the bot using computer vision. We will talk about this below, but now, to finish the dump, we note a simple method with the file name: check whether there are any files in the game save folder with the names “System Tortugacdmp.sav” and / or “System Tortugacdmp.txt”, and if have it, then delete it. To the name of the dump we need, imitating keystrokes on the keyboard, will add “dmp” in the game dialog. Thus, the bot knows which file it needs to read, after the game has written it, for this the bot waits for access to the file. Note that the text of approximately 9 MB is written to disk from a human point of view very quickly, but not instantly from the point of view of the program, so in order to avoid bot malfunctions, all such conflicts should be foreseen.



It is also worth noting that the game provides for: a setting in which each move is saved in the TurnSave.sav file, and a hot key for quick saving, when clicked, the game file QuickSave.sav is recorded without any dialogs, and, accordingly, boot key quick save, for which the boot requires an affirmative answer to the "yes / no" dialogue. A number of other useful features for the bot will be noted below in its description. And here, to finish the conversation about the file system of the game, we note that playing with it the games take tangible waiting time for the bot. After downloading the file may be released, but the game will need additional time to process information to become active. During basic file operations, the game screen is replaced by a splash screen with a progress indicator (“thermometer”). Exceptions such as file write error may occur. Other failures are also likely to be caused by the game’s bugs. All this adds objective complexity and uncertainty to the work of the bot. It is obvious that if the game used any means of inter-program interaction, for example, COM, then these difficulties would not exist. Thus, the game does not have any devices for the boto-structure, and the bot from the side of the game should in fact undergo the reverse Turing test, i.e. be indistinguishable from a human player.



At first glance, the game described may not seem very interesting, however, judging by the above-mentioned table of records, which contains more than 200 records, you will have to admit that the game has some success. From the description it is clear that the game is not easy and requires patience, accuracy and attention from the player. Obviously, such a task is much more interesting for creating a bot than an artificial laboratory game that no one plays and which was created exclusively for research on AI. It should be noted that the purpose of this article does not include a discussion of the game - such a discussion was made earlier. Here only particular features are noted that influence the behavior of the bot in one of the phases of the game. Therefore, the brief description in no way can qualify for instructions on the game.



Problems and Solutions



Above, we have already noted a number of problems. In essence, it can already be concluded that a bot should use real-time program techniques, despite the fact that the game itself is a step-by-step strategy (we don’t talk about planetary and arcade battles) and that Windows is not a real-time system. In addition, a bot can receive some necessary information only through computer vision, recognizing information from the screenshots of the game. (We will not consider the alternative hacker way of accessing the memory of the game or saving files, for example, using ArtMoney and similar tools, as this is not only not sporty, but also uninteresting - it’s enough to write yourself any number of points and talk no more about than).



As noted above, Rogeria rotates around a star in a circular orbit, so the player’s ship must follow it so that the pirates taking off are in the zone of destruction of the ship’s weapons of mass destruction. There is a not very well-known tactical technique, called "landing on the wheel." The base has parts resembling wheels - why they are such a giant space device, it remains only to guess. If you “click the mouse” on the “wheel” and make a move, then the landing on Rozhdestriya does not occur, the ship sticks to the “wheel” and each next turn will follow the base.







Unlike the previous figure, here the cosmic background in the game settings is not removed.



The described method of landing on the wheel significantly saves the time of the game, however, some pirates taking off from Rogeria have time to get out of the player's WMD defeat zone. More experience and points can be obtained if each turn of the ship turns out to be above the geometric center of Rogeria (“above” - taking into account the above remark on the layers of the third dimension of the game world).



The strength of the hulls and the equipment of the pirates taking off from Rogeria vary from day to day in a random fashion. Champions of the game, it was found that changes takeoff pirates occur, if you "talk" with the trunk, i.e. pressing the "T" (talk), hover the mouse over the trunk and press the left mouse button.A modal dialog will open in which you can select the task for this trunk (“follow me”, “come back”, “start collecting things”, etc.) The composition of the soared pirates will be different. Another such empty conversation will again change the composition of the soared pirates. Thus, for maximum points you should try to spend one, two, three, etc. conversations with a trunk, each time returning to the previous turn, and choose a case in which it was possible to get the maximum experience determined from the dump of the game.



As already noted, there are no base coordinates and trunks in the dump, and you need to know them in order to get over the center of Rogeria and call the trunk. To find these coordinates in the bot, the OpenCV computer vision library functions are used..



The bot, imitating pressing the hot keys of the game, centers the image, as a result, the player’s ship is in the center of the screen, because we assume that during the previous moves the ship was not far from Rogeria. However, to avoid errors, the bot will work with a full-screen image for the time being. Next, the bot makes a quick save and removes the labels of the WMD from the screen. Rogeria, without turning around, flies around the star, the sprite is quite large, so it is well recognized by the template below. Barrels and minerals spin in place around their (seemingly arbitrary) axes. This debris is commensurate with the size of trunks and prevents their recognition. Therefore, the bot makes two screen shots at 4-second intervals using the game tools, loads them and finds them in the first template, Rogerie, and then adds them pixel-by-pixel.





(Size: 100 x 93)



Rotating debris is smeared. Further, all pixels in the RGB model, which differ in each color component from the reference image of Rogeria (without any garbage) by no more than 20 units (experimentally chosen value), will be blackened. Thus, Rogerie is removed from the resulting image, but there are objects of closer layers that could partially close it. Next, the bot cuts a 700 x 700 pixel square centered on the center of the screen, additionally blurs this image using the OpenCV cvSmooth function with CV_GAUSSIAN, 9, 9 parameters (selected experimentally) and proceeds to recognize trunks.



Unlike Rogeria, the trunk can be rotated by a multiple of 45 degrees, and the OpenCV recognition feature used by the cvMatchTemplate pattern is not invariant to rotate. Therefore, we consistently look for trunks according to eight possible patterns:







Unfortunately, at this stage the garbage can be confused with a trunk, therefore, in addition to each found object, a measure of similarity is determined. A similar pixel is a pixel that for each color component in the RGB model does not differ from the corresponding pixel of the template by more than 45 units and has a brightness of more than 18 units, thus eliminating gray garbage on which a recognized trunk can be superimposed. The measure of similarity is calculated as the ratio of the number of similar pixels to the number of all pixels of the template, multiplied by 100% and rounded to the whole number.



The following figure shows the image recognized in the described manner: the recognition area is enclosed in a large red square, objects recognized as trunks with a similarity criterion greater than 10% are enclosed in red rectangles (small squares mark the centers), objects found by the cvMatchTemplate function, but not passing through the criterion for the measure of similarity - in the blue rectangles. Numbers - a measure of similarity.







Unfortunately, tests show that with such a multi-stage recognition and subsequent refinement, errors occasionally occur. Therefore, the list of found objects that are presumably trunks is finally checked by the means of the game: each alleged trunk is invoked for a conversation. If this is indeed a trunk, then the following modal dialog appears in the upper right-hand corner of the game screen:







This dialog is confidently recognized by the pattern: in







the manner described with calculating the similarity measure at a threshold value of 80%. If the object is not a trunk (and not a pirate, see below), the dialog does not appear, but an inscription appears in the center at the top of the screen "Conversation is impossible." The inscription quickly disappears, and taking any actions to recognize it seems superfluous.



With a large amount of garbage there are situations in which none of these objects respond as a trunk. In this case, all found objects are painted black, and a new attempt is made to search for trunks. The experiment shows that in some cases it helps. And when it does not help, you can once again take two screenshots and repeat the entire recognition procedure. If this did not help, then the bot has to admit its impotence and ask for help from the player. Tests show that such situations occur quite rarely, much more often the bot stops due to the need for repair work on the ship and the trunks in the game.



The barrels of fuel interfere not only with the recognition of trunks, but also pose an immediate threat to the desired turn of the game party. When barrels accumulate a lot, one of them explodes from a shot, causing explosions near the barrels - a chain reaction occurs with an avalanche-like rise. As a result, the number of barrels decreases dramatically, but explosions can destroy a trunk and, with insufficient protection, cause damage to the player’s ship. It is impossible to accurately predict the course on which this will occur, so in case of loss of the trunk, the player has to return to save the game for a few days before the explosion and replay. In addition, when playing a bot, sometimes a barrel is captured by a player’s ship. Therefore, when the bot stops, the player should inspect the hold for the purpose of throwing barrels into space.



Sometimes during the game there is a pirate who threatens the player. In this case, a modal dialog opens, similar to a dialog with a trunk, but with a different text. Despite the fact that the text is different, the pattern of recognition of a dialog with a trunk is also suitable for this case, since the specified value of the measure of similarity is not too large. The bot at each turn checks the screen shot of the game for such a dialogue and, if it is detected, simulates pressing the Esc key to close the dialog. Otherwise, the further functioning of the bot will be impossible. Also, sometimes some pirate ships, when recognized by a bot, appear to be trunk-like. In this case, when sorting through options, a bot can call a pirate to talk, just like a trunk.



In some cases, it turns out that the imitation pressing the Esc key was unnecessary, which leads to the appearance of the main game menu (also a modal dialog) in the center of the screen. After each imitation of pressing the Esc key, the bot checks for such situations, recognizing the following pattern in the screenshot:







To close the main menu, the bot must repeat the simulation of pressing the Esc key.



Having made a trial move, the bot determines the coordinates of the center of the rectangle describing Rogeria, and, returning to move back, tries to plot a course at this point. However, a trunk or pirate may be close to this point, and then the player’s ship will fly after the trunk (or pirate), and not to the specified point, so the bot tries another option - to make a move at which the ship remains in the same place. After that, the bot compares these options and selects the one in which the distance from the center of the ship to the center of Rogeria is smaller.



Having set the goal to write a rational bot, we will limit its independence as follows: the bot will make moves, monitoring the equipment wear and safety of the trunks under observation. Will independently try options with 0, 1, 2, etc. conversations with trunks and choose the option with the maximum experience. Will monitor the wear of the WMD. However, the replacement of the weapons of mass destruction and the repair of the equipment will be provided to the player - the bot will stop when player intervention is required to change the weapons of mass destruction or install naniki in the slot or remove naniki from the slot in the hold. Also, the bot will stop in case of death of the monitored trunk in order for the player to choose the return day and take measures for additional protection of the trunk (for example,would install additional protective artifacts on a trunk or would not use this trunk as a target for several days). Technically, these operations could also be automated, however many situations with ambiguous decisions are possible and, in my opinion, you shouldn’t deprive the player of the pleasure of making these decisions on their own - otherwise the game will completely lose interest for the player and why the bot. Let the bot perform the most tedious and routine part of the game, and the player will have the most interesting and less burdensome part.You should not deprive the player of the pleasure of making these decisions on their own - otherwise the game will completely lose interest for the player and why then the bot. Let the bot perform the most tedious and routine part of the game, and the player will have the most interesting and less burdensome part.You should not deprive the player of the pleasure of making these decisions on their own - otherwise the game will completely lose interest for the player and why then the bot. Let the bot perform the most tedious and routine part of the game, and the player will have the most interesting and less burdensome part.



The task of tracking equipment for repair seems to be easy to program a bot, but what a bad luck: the equipment dump and artifacts installed in the slots of the ship and in its hold are not distinguishable in the game dump. Therefore, the bot will warn the player about the wear of the equipment being monitored, when the wear reaches a certain limit value, remember this equipment and inform the player if the wear of the memorized equipment drops to the value from which nanics will no longer repair the equipment. In the first case, the player must put the nanics from the hold into the slot of his ship or trunk, in the second case - to do the reverse operation.



GUI



The main tab of the bot window is shown in the following figure.







A bot can play in two modes: full-featured and accelerated with reduced functionality. The choice of mode is determined by the number of conversations with the trunk - the "Talks" field. If this number is greater than zero, the bot makes the first test move, then returns to the previous day, calls one of the active trunks to talk, closes the dialogue and makes a move, then returns to the previous day and speaks to the trunk again. And so many times, how many conversations are indicated in the "Talk" field. Of all the attempts made, the one that brought the maximum experience is selected.



To play in an accelerated mode, the player needs, as described above, to “stick” the ship to Rogeria by landing on the wheel. In this mode, the bot does not need to recognize the base and trunks, making screenshots on each turn, so the speed of passage increases markedly, and the number of errors decreases greatly. For even faster passing at a low level of wear of everything that is under observation, the bot can not dump the game every day: you can set the frequency of dumps in the "Analysis frequency" field. When wear becomes close to critical, the bot will switch to a daily dump analysis.



As already noted, for the correct functioning of the bot in the game must be made the appropriate settings. Therefore, when you first start the bot offers in the dialog to make the necessary changes to the game configuration file. If the player agrees, the bot copies the game's CFG.TXT configuration file to the CFG.BAK file and makes the necessary changes to the CFG.TXT file. To return to the previous configuration, the player must start the bot and click on the button “Return CFG file”. The bot will delete the CFG.TXT file and rename the CFG.BAK file to CFG.TXT. The next time you start the bot, it will not detect the CFG.BAK file and will suggest the necessary changes to the game configuration file.



Learning, self-study and self-knowledge



Great hopes in AI are placed on learning, and especially on self-study. In this regard, it is worth remembering well-known facts: what about the situation with the improvement of natural intelligence, first of all, with the education of children. It is universal since the time of the cavemen, even the hero Kipling Mowgli is taught to read a jungle book. Many masters and good specialists in various fields study all their lives, but still for a large number of adults, education is not considered as compulsory as it is considered mandatory for a child. In this regard, not minimizing the role of self-study, one still has to admit that, traditionally, all nations focus on training, and on rigid modal training like “do this.” So basically, parents, educators and school teachers teach and educate: “my hands before eating”, “don't bite your nails”, “don't hold a spoon in your fist”, “you should hold a soldering iron like a pencil”, “don't postpone for tomorrow what you can do today, ”“ you cannot work with a lathe in a tie — you can wind and choke ”,“ you should not do to others as you would not want them to do to you, ”etc. In this case, the justification is optional. Indeed, you can try to explain to the child why you need to wash your hands before eating, but it’s much harder to explain why you can’t keep your spoon in your fist - because it’s more convenient for her to hold it. Each student will understand that moving parts of the machine may wind a tie, but there are debaters who say that a tie can be short, that a long one can be pinned with a pin, etc. The standard line of conduct for teachers and instructors is to avoid such disputes: “these are safety requirements and they are not discussed.”



Self-education in children's education usually plays a secondary role. Of course, there are talented children, and there are many cases in which an interested schoolchild independently learns something that is not part of the school curriculum on books. However, such cases are usually considered as exceptions, albeit rather numerous, from the general rule. In this case, it is usually noted that the knowledge gained by a schoolchild as a result of such self-study is usually superficial and not systematic, and sometimes even erroneous if he could not figure it out or did not understand so. Obviously, for a sufficiently educated adult, self-study usually proceeds much more fruitfully.



Considering the above, the idea of ​​a fully self-learning AI program seems doubtful. At present, we know quite well only one system of principles of elementary education - the education of children. Therefore, we have no choice but to apply these principles to AI. And, in particular, the noted principle of modal teaching by the teacher with the non-obligation of self-learning. In fact, the modal learning “do this” is no different from programming the rules of behavior in the subject area. In the case of the bot described here, the above rules for solving problems arising during the game are stitched in the form of program code. During the tests of this code, the parameters, for example, the thresholds for the similarity measure, are specified.



Continuing the list of problems, we will talk about the problem of animation of shots: after clicking on the space, the game makes a move, another batch of pirate ships takes off from Rogeria, the player’s guns take a shot and then everything is in smoke, as in the below screenshot taken after 3.5 seconds. after the bot presses the space bar (make the move command).







Such a picture is not suitable for recognition - you need to wait for the smoke to disperse, and the objects will stop moving. To minimize this pause, use the tab “Rogeriya”:







After clicking on the button “Create a series” (the inscription on the button changes to “Cancel”) a message appears prompting the player to go to the game screen and press F10. The bot will make a series of screen photos (“screenshots”) with a delay corresponding to the parameters specified by the player. Next, the player browses this series and selects an acceptable pause. (In the figure, the Result field after the file name through the delimiter “=” contains the value of the pause in ms.)



In this connection, an interesting theoretical question arises: is it possible to call the described process learning? And if not, than the modal order of the educator to the child “my hands before eating” is essentially different from the order of the player to the bot “after the move to pause for 4 seconds. and only after it to take screenshots "?



The choice of the pause could be fully automated, for example, by the following self-learning scenario: at the beginning, the bot sets a clearly overestimated pause, and then reduces it until the recognition results deteriorate sharply. Perhaps such a decision will seem to someone more beautiful, however, in my opinion, this would be a useless embellishment. Pause installed only once, but it can be assumed that when changing the environment, for example, a video card, it will be necessary to change this parameter.



Above, we said that the requirements for a rational bot include utility. It is unlikely that a bot will be practically useful if it passes the game too slowly, so all pauses are minimized as much as possible.



It is also worth saying a few words about self-knowledge (introspection). His insurmountable difficulty is one of the clearest examples of the limitations of natural intelligence. The famous founder of the philosophy of intuitivism A. Bergson noted that although a person can raise his hand, he cannot explain how he does it. Later, while working on systems for the automatic proof of theorems, the researchers were confronted with a paradoxical fact: no mathematician can explain how he proves the theorems as completely as is necessary to implement these systems. The fact that people study at a conscious age and can tell you step by step how they studied mathematics does not help either. The situation with speech recognition and visual imagery seems even more complicated - no one can tell how he learned this. Thus, the limitation of natural intelligence is manifested in the difficulties of teaching AI to recognize speech, visual images, prove theorems, etc.



Handling rare and exceptional situations



Above, situations that occur relatively rarely were noted, for example, no trunk was found, a transition to the main menu, etc. Such situations should be distinguished from exceptional situations. The exception is a rather strict concept, according to Wikipedia, defined as



run-time errors and other possible problems [...] that may arise during the execution of the program and lead to the impossibility (meaninglessness) of further refinement by the program of its basic algorithm.
The exception handling mechanism is embedded in the computing environment. It is also worth noting that the frequency of exceptions is not specified, and in principle exceptions may not be rare at all.



Rare situations are not so strict, rather a heuristic concept, entirely dependent on the subject area and modeling environment (in our case, on the game). As you can see from the examples above, not all rare situations lead to the impossibility or meaninglessness of further working out the program of its basic algorithm. For example, capturing a barrel ship does not require any immediate bot response. In the proposed solution, the release from accidentally captured barrels is assigned to the player and, as a rule, they can be made at a convenient time, i.e. at the next stop of the bot for repair, replacement of OMP, etc. If a player marks all the barrels to capture, then on the next turn his ship may be overloaded, however, in a real bot game, this situation seems unlikely.



In general, one has to admit that even the most thorough analysis of a non-trivial task does not guarantee the identification of rare situations, and one may not encounter some of these situations when learning. These considerations add doubts about the full autonomy mentioned above. With a rational approach, rare situations are handled by man. Recently, a great resonance caused a message about a robot cop drowning in the fountain of a supermarket. I suppose that the reason for this "suicide" was a rare situation that was not taken into account.



Implementation, empirical approach



In 1976, Newell (A. Newell) and Simon (HA Simon) at the Turing award gave a lecture on the topic "Computer Science - Experimental Science". Following them, J.F. Luger stated:

Each AI program should be considered as an experiment: it is a question for nature, and the answer to it is the result of the program. The response of nature to the underlying design and program principles forms our understanding of formalism, patterns and the very essence of thinking.



(J.F. Luger, Artificial Intelligence: Strategies and Methods for Solving Complex Problems. 4th Edition. M: Williams, 2003, p. 780) .
Above we have repeatedly noted not only an experimental approach to determining parameters, but also to the choice of methods - for example, an experiment showed the need to use a measure of similarity. Actually programming and catching the main bugs took me very little time (about 10% of the total time spent), in many respects also because the bot was based on a reworked program of the bot I had previously made to generate the hulls of the ships in KR2HD. The main time was spent on the passage of the real party and the adjustment of the bot during this passage. Although, as in any lengthy task that does not require the constant participation of the operator, if you count the real time costs, they are small - as long as the bot plays the game on one computer, you can do other things on another computer nearby. When you stop the bot will beep. For greater convenience of the player when using the bot, it is possible to specify in the bot configuration a program that he will launch when stopped. For example, it could be a phone call program to a player, in case the player is in another room. In addition, there is an option to turn off the computer: when you stop the bot will save the game and turn off the computer.



The game and my previous bots are written in Delphi-7, in order to reuse the code, the same medium was chosen for this bot. In addition to the already mentioned OpenCV, Delphi-OpenCV (Laentir Valetov, Mikhail Grigorev), TntWare Delphi Unicode Controls (Troy Wolbrink) libraries and the Inno Setup (Jordan Russell) installation program are used. The bot was tested under Windows XP SP3, Windows 8.1 and Windows 10. Game versions KP2HD 2.1.2155 and 2.1.2170. Tests in a real game took about 12 game years, which exceeds the duration of the Rogerian battle in the aforementioned records, but, of course, you can find games in the table of records where this battle lasted longer. According to impressions from these tests, the bot was a success. It was possible to achieve the goal of rational AI (see above) - “choose the level of autonomy at which”:



1) "The program will be useful" - felt the benefit, instead of stupid beating pirates for several months, was engaged in much more interesting things, at the same time felt a constant presence in the game, occasionally making interesting game decisions that the bot did not trust.



2) “The program will not err too often compared to a person” - indeed, the error rate was reduced to an acceptable, in my opinion, level: once an hour, and sometimes longer. At the same time, I admit that with longer and more thorough debugging, the duration of error-free operation of the program can be increased.



3) “The program will not be overly complex for writing, debugging and maintenance” - it did not encounter any particular difficulties. In any case, do not compare the planetary battles (PB-bot) mentioned above. Although he showed some success, but no one, including myself, has been able to promote it yet.



Conclusion



Game programming is traditionally considered one of the most important areas of development of AI. In this direction, we can distinguish the sub-direction of programming bots for games: shove a bot-beetle in the anthill of the game in order to see what happens. To answer the question “why this is necessary”, it is worth considering modern natural sciences and humanities (for example, art films and literature) from the point of view of a model approach. Scientific theory, the movie, the game - the essence of the model, allowing to explore some general principles. In particular, for example, from the model-bot proposed here, the principles of a rational choice of the degree of autonomy follow, which, in my opinion, can be useful for, for example, preventing suicides in the fountains of such non-tricky products as the above-mentioned robot-policeman.



It may seem that a more complex model, for example, a more complex game or a more complex task of this game would bring more interesting results. However, the principle “the more complicated the better” is not always justified in such studies — over-complicated models based on a large number of rules with a large number of parameters often lead to a situation where there is no forest behind the trees. Thus, the mentioned PB-bot, focused on a more complex task, did not allow to make such interesting observations.



In conclusion, I consider it my pleasant duty to thank Svyatoslav for discussing the tactics of the game, the ideas of the bot and for preliminary testing the starting versions of the bot, as well as Robo Brain for discussing the tactics of the game. Thanks to vconst for processing the TP graphs.

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



All Articles