How we merged the IT Planet programming final

We are not bad, but there are many bugs. Development of artificial intelligence for the game “Hockey” in ~ 7 hours.



Initially, the article was planned about the strategies of the participants, about what they managed to do in the competition time and whether they were happy with the work done, but, after interviewing eight finalists, it became clear that nothing would come of it and an urgent need to change direction.



The fact is that we received a maximum of 6 words for questions of interest to us, and then immediately heard discontent about the bugs that the participants encountered. Only one person wrote:

I do not want to write anything negative, I think this is incorrect, and the organizers themselves should be sad. Therefore, I will say that the idea of ​​the assignment is quite interesting, although I personally do not really like this format of competitions (Anna Prozorova).


From the title of the article it’s clear that we won nothing. And yes, it is “we.” Over the days of the competition, I made many good friends, including Anna ( odrus ), who is the co-author of this article. Also at the last moment we talked with Leo ( zadamantiy ) and with his permission we described participation in the final.



Personally, I am a member of the “A Complaint Free World” movement, but I will hang my bracelet on the other hand and will complain, albeit in a comic form, because, on the other hand, these are the conditions of the competition and you need to be a good specialist to win and to cope with the shortcomings! We have no complaints, on the contrary - thank you very much!



Under the cut, in addition to describing the rules of the game, the rules of the competition and the bugs found, we will share with you our jambs, what we personally encountered and how we solved this or that problem, how we prepared for the competition. Perhaps somewhere you recognize yourself if you participated in such competitions.



The purpose of the article is to collect the contest fails from both the participants and the organizers, to chop them on your nose and never step on the same rake again. We hope that the article will increase the level of the next contest.











Introduction



A few words about us



Ilya



The annual participant of the Russian AI Cup and Mini AI Cup since 2017. I also follow Codingame and Halite. I don’t have any special achievements, but I learned a lot from others. For me, the main thing is not participation, not victory, but to give my 100% and finally say: “I did everything I could, realized everything I wanted, applied everything I knew.” I do not know the Java programming language. For me, this is already a common practice from the competition to the competition to fully study the new technology stack.



Anna



A simple student with little experience in solving algorithmic problems, but without much experience participating in olympiads and similar contests. Specifically, in the IT Planet, I decided to participate in order to test my knowledge and abilities, gain experience, communicate with interesting people. She studied the Java programming language at the university, but had no practical experience with it for a long time.



a lion



He participated in all kinds of ICPC selections, hackathons like “Build University 20.35” and “Digital Breakthrough”. Well, the little things in some university olympiads.

Accordingly, our university usually sent many participants to the contest for sql, but this year it was not. I was offered to participate in Java, I had to deal with a new language for myself in a fairly short time in parallel with the session. In It-planet did not participate before.



Competition Description



General position



IT-Planet is a competition for students and young professionals from the IT field, whose goal is to identify and support capable guys. Held annually since 2007. Participation in it is a chance to prove oneself.



The “Java Programming” nomination helps to find practical application of the knowledge gained in the learning process.



The first qualifying stage was in absentia and was an online test for students of registered educational institutions. The questions were quite complicated and interesting, but to be honest, the majority contained code that could be re-read and run.



The second qualifying stage, like the first, was in absentia. It is aimed at solving sports programming problems. Two days were given to solve 10 problems, which made it possible to thoroughly prepare for solving a specific problem, to study the algorithm / approach. However, no one coped with all the tasks. The condition of some tasks changed during the contest. There were schools in the tests.



Full-time international final. It was necessary to write an AI for the game “Ice Hockey”. It was given ~ 7 hours. Approximation due to the lack of a “go-ahead” of the start and incomprehensibility with lunch. The time was rubber and the audience did not close, but more on that below.



The task



The task was developed by specialists of SimbirSoft LLC. Below is the contents of the .pdf file (with minimal revisions for the article) that each participant received.



The task
Task description



Somewhere in a mysterious country, all of whose inhabitants are small robots, there were 2 teams for playing hockey. Both teams have their own personal robot coach, who constantly monitors the game and tells all the players where they need to go. Everything would be fine, but robotic players understand only such simple actions as going, hitting the puck, going to the point set by the coach.



You have to become a coach for the red team of players. A blue team will play against you, which is controlled by an algorithm that already successfully defeats other teams. 2 teams play on the field at the same time. The team consists of 4 players: striker, 2 defenders and goalkeeper.



Your task is to write an algorithm for managing red bots. To control the characters you will have 3 methods, which are described below. There is also a method that receives information about all the players on the field and the puck coordinates.



Game limitations



The goalkeeper can only reach the middle of the field from the goal. Defenders and attackers can ride all over the field, except for the goalkeeper area (red semicircle near the goal).



Description of the application structure



The application is presented as a client and server. The server will be packed into a jar file, and launched in the background. The server contains all the basic logic of the movement of characters and the puck, storing information about all the characters, the puck, time and score.



When the application starts, the client establishes a connection with the server, and, with a given frequency, receives data from the server. He is also responsible for rendering all the characters, the goal and the puck on the hockey field.



All program code must be written in the Algoritm class in the algoritm folder in the client application (all changes in other files will not be taken into account).



The following methods are present in this class:



  • move (playerType, x, y) - A method for moving a player to a specified point on the map.
  • kick (playerType) - Method for hitting the puck by a specific player.
  • turn (playerType, angle) - A method for turning a specific player.
  • getInfo () - Get information about all players and pucks on the map.


There is also a static variable level, which is responsible for the level of complexity of the algorithm. The following levels will be available for participants in the Olympiad:



  1. the blue team is standing;
  2. the blue team walks randomly across the field;
  3. the blue team plays according to the “weak algorithm”;
  4. the blue team plays according to an advanced algorithm (for internal testing).


All methods that accept playerType only work for red team players.

The playerType variable is an instance of the PlayerType class, and contains

values ​​such as goalkeeper, defender1, defender2, striker.



The Playground class contains constant values ​​of the game (for example, midfield, goalkeeper zone, etc.).



The getInfo () method returns an object of the GameInfo class.



Refinements



  • If you send the move method several times, then the endpoint where the character needs to reach will change (therefore, if you need to reach the endpoint, you must wait until the character reaches it before sending it to another point).
  • The kick method can only be used for a player who owns the puck.
  • The turn method takes an angle, while for the lower side of the field, the angle takes values ​​from 0 (looks towards the enemy’s goal) to 180 (looks towards its own goal), and for the upper semicircle, the angle takes values ​​from 0 to -180.








Criteria for evaluation



Also taken from a .pdf file. Only code from the Algoritm class will be used. The algorithm of each participant will be run against all difficulty levels in turn. Based on the results of the run, points will be set for the results of the match, and points for the implemented opportunities in the algorithm will also be awarded.



List of criteria
  1. Attacks on goal must be carried out from different angles. For example: right in front of a player, an enemy goalkeeper - an attack on goal must be carried out at an angle.
  2. The player passes the ball to a free hockey player to carry out an attack on the goal.
  3. A pass should be given only in cases where the player cannot make an attack himself (all angles for attacking the goal are closed).
  4. A pass should only be given to a player who is free to pass. Hockey players with a goal open for attack are in priority.
  5. If an attack is impossible, the team must retreat and regroup.
  6. Add. Points if they depart by means of transfers.
  7. Add. Points if you use the goalkeeper for regrouping.
  8. In defense, the ability to pass to another player of the opponent should be blocked.
  9. The player’s team adheres to strategies. For example: 1 defender always always keeps a little further, in case of an enemy counterattack.
  10. The algorithm takes into account the scoreboard. For example: plays more aggressively in case of a loss and vice versa is more careful in a winning situation; with a draw increases aggression towards the end of the match.


Penalty points will be awarded for:



  1. The player scores goals in his own goal.
  2. Hockey players block each other. (do not let each other pass).
  3. Intentionally blocking the game. For example: push the puck against the puck until the end of the game.




Main part



Preparation for the competition



Ilya



Initially, they wrote that in the final there will be “Industrial development”. I expected the usual work with the base, the development of the GUI. An application for accounting something, for example. With grief in half, I agreed to the final, because I was not very happy with what I had to do. However, on September 17, a letter arrives with the rules for holding the finals, and the following is reported there: “There is a computer 2D game“ Hockey ”in which computer bots play according to some algorithm. It is necessary to implement an algorithm in the Java programming language according to which the characters of the participants will act “(it was written on the site that the task could be changed). I immediately remembered the 2014 Russian AI Cup in my head. I was delighted and realized that it was not in vain that I agreed to take part.



The first thing I went to once again read the winner’s article . In general, I remembered what was there, but not all the moments were clear. Then I went to the contest website and read the rules. I stopped at this, because any amendment to the rules can completely change the whole game. I did not know how many physicists would be in their game, I did not know how the punch and puck selection, etc. The game could be greatly simplified, that even the corners would not be needed. So I started to wait ...



Waited and waited! In the afternoon of September 27 comes a letter about the webinar! September 28 at 19:00. It was a perfect day and time for me. However ... However, 4 hours before the scheduled launch, another letter arrived with a transfer to 17:00! The transfer letter came an hour before the start ... I flew as best I could and was late for about 15 minutes (I did not expect that Flash Player would still have to be installed).



At the webinar he asked questions and got a general picture about the game. There was enough data, even to write your own and thoroughly prepare. However, until the last it was not clear how the blow occurs, the developers did not disclose some points, and in some places they themselves have not yet decided to the end.



Having written down all the most valuable, I went to talk with the familiar active members of RAIC. Hi and thanks m0rtido , DragoonXen , oreshn1k . Having outlined the situation, it became clear that it is necessary to hardcode ifa and cannot talk about any simulations of the world during such a time. oreshn1k shared the bombing book “Programming Game AI by Example”, the fourth chapter of which talked about the design of AI for football. I liked the book so much that I decided to paint for myself the whole strategy that I was going to write at the competition, and completely forgot about the time limit. What I was going to write was not suitable for this contest ...



My done useless preparation is available on quire (neatly, there are already 168 tasks there. In some places with a description). Useless for this competition, but in general it is an excellent systematization of the knowledge gained from the book. I also thought about simulating the puck to find out its location after a while, finding the right angle for the shot on goal, the logic of transferring the puck between the players and a bunch of interesting things.



I already wrote above that without a clue how to write in Java, therefore, in addition to the strategy, I began to study the syntax of the language. This was helped by an excellent site that I have been using for more than the first time - Learn X in Y minutes . Having entered IntelliJ IDEA, I realized that writing on it is exactly the same as writing on C #.



With such preparation, I went to Moscow.



Anna



When I learned about the theme of the finale, the first thing I decided to repeat was the geoma. And so that all this would be fun, I would do it all with Processing : I looked at examples from the developers related to movement, calculating angles, speed and acceleration, and then practiced on my small sketches.



I decided not to waste time on refreshing some subtleties of Java, because the task, as it seemed to me, suggested skills in writing strategies and some knowledge of mathematics. So I decided to read the article of the winner of RAIC 2014 . The article was interesting, but not particularly useful specifically for this contest, because physics could differ radically, and much less time would be given.



The webinar from the developers was interesting and useful, gave an overall picture of the game. But, unfortunately, I could not watch it completely, because the broadcast was carried out using Flash and my laptop at that very moment decided to play with the blue screen of death.



As a result, just before the final, I had no strategy worked out in advance: it was difficult to plan something when the details of the physics of the game were not disclosed. There were thoughts about what it is worth paying attention to first of all, what auxiliary methods to write immediately, but no more. I decided that the main thing before the finale was to relax, get enough sleep and come there in a good mood.



a lion



[Prepared] About 16-20 hours. Accordingly, I considered geometry, with which, unfortunately, I am not very at odds. Prepared formulas and calculations in advance, tested everything. He evaluated the area from which you can score according to the conditions given by the organizers at the webinar, then wrote an emulator of some actions and got what the area would look like when directly simulating shots from different points and the optimal goalkeeper strategy. As a result, almost nothing came in handy and I had to write crutches on crutches.







Time distribution



Ilya



I always had problems with the distribution of time at competitions and olympiads. I stepped on a rake for the third time. After the first he said that he would never allow this. Once again, he sat down on one task, for a long time did not switch to another.



Spent a lot of time, the entire first part of the competition before lunch, on the implementation of all kinds of wrappers for team players, state classes, messages between them, internal roles. In general, I went on the tasks that I had formed before the competition completely forgetting the advice of experienced participants about hardcode ifs and auxiliary methods. He simply wrote without thinking about time.



I came to my senses at dinner. I understood that half of the competition was over, and I have work for another 10 hours so that at least something starts to move. It was decided to leave everything that is and start from the very beginning. These were the fascinating last hours of the contest, when I stopped feeling sad and giggled with the behavior of my bots. Very quickly began to switch from task to task. He doesn’t go there - he switched to another, then he returned. There was only one desire - to score at least somehow, at least something. Therefore, it was completely forgotten about the purity of the code and OOP, interesting comments were left in places.



Anna



First, I decided to figure out how the basic methods in the game generally work: the movement of hockey players, the capture of the puck, turns and passes. I spent about an hour on this. I also studied the data and methods that the hockey players and the puck had. Then I decided that it would be nice to learn how to find the angle between two objects (in particular, between a hockey player and a puck). I had great difficulties with this: at first I figured out the Math.atan2 method for a long time, and then I tried to convert the received data into a system of developers' angles. With all this, I was tormented before dinner and was very upset that I spent a lot of time on one small task, although during the same time I could write a strategy for at least the first level.



After lunch, I decided to allocate time more rationally. I quickly completed the method with determining the angle, then wrote a strategy for the first level. Then she smoothly switched to a strategy for the second level, which she applied in the end for the third. Actually, this and sticking into the way my hockey players behave strangely, I did until the end of the final. The code turned out to be terrible, unreadable, with a bunch of ifs and copy-paste, but it more or less coped with its task: my hockey players scored goals.



a lion



For the given time (7 hours, which is insanely small for such a competition), he made a simple algorithm that was able to consistently win 1-2 levels with a crushing score. And then, depending on random events with a 3rd level, the algorithm issued a score from 0-2 to 6-0. Unfortunately, it was not possible to look at the fourth level. At the same time, I’m sure that during this time you can write a much better option, but for this you need to understand how some kind of turnaround works, but here the organizers shrugged, saying that we don’t understand why this is so.



Most of the time it took to figure out how and what works in the project was especially infuriated by the not working .equals () and two fields .TypeOfPlayer and .PlayerType, which returned completely different things. Well, there are some strange behaviors of players that the organizers really could not explain (and we don’t know why your character is riding here with his back for the only given team, and the already mentioned turns :)). Then, at some point, it turns out that the project has constants for the sizes of different game objects and their positions, which, it would seem, should have been in the reference material initially, but no, in the end, it killed time to count them manually.



Our jambs



Ilya





Anna





a lion





Organizer Shoals





Conclusion



Output



In general, if you stop taking the finale too seriously, it was fun, interesting and very sticky. Yes, I had to spend time not on writing a strategy, but to deal with the bugs of developers. But when you adapt and start playing by their rules, you even begin to get some pleasure from the process. Of course, I would like for the developers to take a more responsible approach to this task and bring the matter to the end without providing the final participants with raw and unfinished material.



It is also worth noting that the winners of this finale are great fellows: in such difficult and unexpected conditions, they were able to get together, figure everything out and issue a high-quality solution. Respect to such boys.



Acknowledgments



First of all, I would like to thank the participants who helped in writing the article and kindly agreed to answer our questions. Unfortunately, due to the change of direction, a lot of material was not necessary.



Thanks to Anna ( odrus ), Leo ( zadamantiy ), Alexander ( boba-alex ), Maxim ( maxzxwd ), Ivan, Roman, Anna, Donat, Alexander.



I would also like to thank the organizers of the IT Planet contest itself, the organizers of the final for the Programming: Java contest SimbirSoft, and in particular the developer Eduard, who was present at the finals and helped participants with build problems, could clarify the unobvious moments in the logic of the game.



Thank you for the fact that the competition did not kick at all, as they did with the sisharp (Alexander).
The idea of ​​the finale was good, qualifying rounds too (Ivan).


PS



While writing an article, photos from the contest and protocols arrived, which means that now we can announce our places!



Ilya crowed the most - 28-32 out of 33

Anna - 16

Leo - 14



Thank you for reading right up to here!



All Articles