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:
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:
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
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:
- the blue team is standing;
- the blue team walks randomly across the field;
- the blue team plays according to the “weak algorithm”;
- 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
Penalty points will be awarded for:
- 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.
- The player passes the ball to a free hockey player to carry out an attack on the goal.
- A pass should be given only in cases where the player cannot make an attack himself (all angles for attacking the goal are closed).
- 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.
- If an attack is impossible, the team must retreat and regroup.
- Add. Points if they depart by means of transfers.
- Add. Points if you use the goalkeeper for regrouping.
- In defense, the ability to pass to another player of the opponent should be blocked.
- The player’s team adheres to strategies. For example: 1 defender always always keeps a little further, in case of an enemy counterattack.
- 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:
- The player scores goals in his own goal.
- Hockey players block each other. (do not let each other pass).
- 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
- My main cant in the terrible distribution of time and the futile writing of superfluous abstractions. When you have 7 hours, write a bad, unsupported code if you want to win.
- Rofl with geoma. I still don’t know which angle to add and how the server processes it, so there’s% 360 here. Maybe 90+, maybe 180, maybe all 270. I didn’t think about it at all and just put it on any chance ...
double res = 180 / Math.PI * Math.acos((pp.x - tp.x) / pp.dist(tp)); return (90 + (int) res) % 360;
- About 40 minutes before the end of the competition, I decided to figure out the game, which took place in search of the closest player to the puck. The thing turned out to be that my squareDist method of the Paint class had the sign -, instead of + between the squares of the difference of coordinates (by the way, in task on quire too -). And with such a bug, I considered absolutely all distances for several hours ...
- At the very beginning of the competition, I kept in my head the realization of getting the puck position in the future. This requires its speed. As it turned out, nothing useful can be obtained from the state of the world at all (I think it’s a jamb of organizers, relying on what other contests of the same formats provide). Therefore, the same puck speed had to be obtained, based on its position at different points in the game. I spent a lot of time debugging and did not understand why the data comes so rarely (promised every 5ms). In general, I was not able to finish the miscalculation then, but ~ an hour before the end of the competition I noticed an interesting piece of code in my strategy left by the organizers:
try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); }
Setting the value to 10, I received a very frequent update of the data, uncommented the part of the code responsible for obtaining the speed, and it worked! About 20 minutes later, I heard a question from the participant to the organizers about this piece of code, and he explained to him that this was done especially for us, so that it would be easier to develop. At that moment I smiled, realizing that I was not the only one who realized this so late.
Anna
- Like Ilya, I did not manage to correctly allocate my time at the very beginning: I spent a lot of time on one small, albeit useful, task, but I had to teach hockey players to score goals.
- I killed a lot of time because I forgot the signature of the Math.atan2 method: first comes y, and then x. I did the opposite.
- When writing a method that determines if there are any enemy hockey players on a certain stretch of the path, I made a couple of mistakes, because of which hockey players sometimes refused to move anywhere.
- On the whole, the competition was not taken seriously enough. One could prepare more thoroughly and be more diligent and attentive at the very end.
a lion
- The first two hours in the logs iterated randomly both times at the command of the allies, instead of the second time at the command of the bots.
Organizer Shoals
- Little data for comfortable writing strong strategies. All that we were given are four methods for controlling and positioning players on the field. Yes, the puck also had its owner. Of the constants, the center of the field, the goalkeeper and goal areas were accessible. Thank you for this, but it seems to us that the following list of values was simply necessary. We just crutched them!
- Players speed (each role had its own speed), pucks;
- Information about slowing down the puck;
- Starting positions of players;
- Sizes of players, pucks;
- At the webinar, the developers said plainly that there would be no way to get the source code of the server. About some packers, it was said that .exe would slip. The word “obfuscation” did not flash, but hinted. In fact, we got a .jar, which decompiles in a couple of seconds and not only the constants and logic with the physics of the game, which were missing for the participants, but also their source code of the bot of the 3rd level playing against us, become available. Unfortunately, I noticed this myself upon arrival home, and heard about decompilation after the contest from the participants. They told how someone used it during the finale. If this is true, it is very unpleasant. At such moments, you begin to regret that the right one is all.
But in that case it’s not very honest (Alexander Polishchuk boba-alex ).
Well, well done that they used it, since there was no ban in the rules, but they decided not to go through the obfuscator, so it was part of the Olympiad (Maxim Pyankov maxzxwd ).
- Hockey players could disappear at a random time from the field and not appear until the end of the game. You can shove the player into the goalkeeper area.
- When calling the move () method, the hockey player could have turned in the wrong direction. Because of this, it could be something like a “moonwalk”.
Video
- The turn () method deploys the players noticeably slower than the move () method to a certain point (there is an automatic turn in the right direction). This happens, as a rule, in a collision with another hockey player. Comparison of two methods:
- The angle of reflection is poor. Huge speed after bouncing off the sides (video slowed down 4 times). Washers do not need, even though she was in the goal.
For comparison, an example of a pass at a right angle, in which everything is good with speed and slowdown is.
Video
- The attacker of the enemy team stood closer to the center of the field and immediately intercepted the puck at the beginning of the round (the puck not in the center of the field texture is also normal).
- The restriction “the goalkeeper can only reach the middle of the field from the goal” applies only to our team, there is no such rule for enemies.
- In order for hockey players to be able to perform any actions, you must first apply the move () method to any of them;
- The organizers in the strategy code left a timeout, affecting the frequency of receiving new data. If you just delete this code, everything freezes. Many did not understand its purpose, and no explanation was received from the organizers. In the rules, too, this part of the code did not appear. Many on this sat in a puddle.
- A large number of participants had problems with assembling and changing the level of the strategy (as it turned out, not many were able to work with maven'om).
- At the webinar, the organizers said that Java will use version 8, but in the end, the project needed a minimum of Java 11.
- Anna: after I sat down at a working computer, there were problems with the build due to extra spaces in the code that broke the variable name. Not critical, but not very nice.
- On some computers, initially there were no task files or the Internet, and dependencies were loaded for a long time.
- There were more participants than expected. It happened because of some kind of extras. Therefore, the person ~ 13 had hitches with the search for computers (some took out their laptops) and started the project from scratch.
- Lunch was not strictly regulated. They did not give a certain time for a meal, they did not close the audience. Starving people got an extra hour to sell.
- Above, in the description of the contest, there is a subheading with evaluation criteria. Their problem is what it says about the points, but it is not written how much and for what. As a result, we got opacity and a general lack of understanding of what to do in order to win.
It would probably be difficult to compare participants close in level, since there were no clear assignments of points for features, there was just a list. Participants could implement different features, but from all the same it was necessary to somehow compare (Roman).
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!