📜 ⬆️ ⬇️

Google AI Challenge - quick start

As you may know, the Google AI Challenge began yesterday. In this topic, I want to briefly tell you where to start, describe in more or less detail the rules of the game and the subtleties of the API, which are difficult or impossible to find in the official documentation. Before you are welcome to Habrakat, I strongly recommend that you, if you haven’t already done that, read about the Google AI Challenge. This can be done, for example, in a recent habratopik .

1. We delve into the essence

1.1. Gameplay in terms of bot

To begin with, I’ll tell you how the interaction between bots and the checker system (checker) is arranged. The tournament organizers decided that the best way to arrange this interaction is to declare each robot a separate process, and communicate with it using standard input and output. Let's not talk about whether this is a good decision or not, but just take it for granted. The game, unlike what it may seem, is turn-based. On each move, the bot on stdin is given a description of the current state of the game. It includes:
  1. Description of all the planets on the map; for each planet the following is known:
    • Unique ID of the planet
    • Her Cartesian coordinates
    • Planet owner ID ( NB: if the planet is neutral, then ID is zero , if it belongs to a player, then ID is one )
    • The number of ships on the planet
    • The rate of increase of ships
  2. Description of all fleets in flight:
    • Fleet owner ID
    • The number of ships in the fleet
    • ID of the planet from which the fleet flies
    • ID of the planet to which the fleet is flying
    • How many more moves to the fleet to fly ( NB: The number of moves the fleet will spend moving from planet A to planet B is equal to the upward-rounded Euclidean distance between A and B )

In response, the bot writes a sequence of commands to stdout, and then says that it has finished its turn. There is only one team: send X ships from planet A to planet B. Please note that if Planet A does not belong to you, or Planet A or B does not exist, or there are fewer ships on Planet A than X , or X is less than zero, then you will be disqualified from the match.

1.2. How is rated

Generally speaking, the rating is considered somehow bad. According to the developers , he is considered to be in a system similar to the one used in professional chess tournaments. In fact, it looks like this: as soon as a player loads a new version of the bot, his rating is reset (or maybe not, I have not fully understood this), according to some algorithm, the robot battles with other participants. The algorithm is intricate and completely unobvious. For example, after I poured a new bot (which, according to my tests, on 97 maps out of a hundred, tore past), my rating dropped. It seems to me that this is connected precisely with the glitchiness or imperfection of the algorithm for choosing rivals: for some reason, I constantly fight against those who are lower than me, but I do not fight against those who have it higher. However, the rating is not particularly important, because the final result does not depend on it (I apologize, I cannot find the link link), and the time is even more than two months.

2. Getting down to business

2.1. check in

There is nothing much to say here, except that you cannot have multiple accounts and that you cannot change them either, even the password. If you want to play in a team, you need to specify it in the biography immediately.

2.2. We realize starter package

For the convenience of participants, the organizers have made special starter packages for the main languages. These packages include a checker, a replay viewer, a few simplest bot examples and a template for creating your own bot. Download the starter kit for your favorite from the presented language here . I love java, and therefore I will continue to talk on the example of this language. To the joy of those who do not share my attachments, for other languages ​​everything differs little.

After you download the .zip archive and unpack it to your place, you will see the following folder structure:

java_starter_package/ |-- example_bots/ |-- maps/ |-- tools/ |-- Fleet.java |-- MyBot.java |-- Planet.java |-- PlanetWars.java 

In the example_bots folder, as you can guess, there are simple bot examples along with the source codes, and in the maps folder, as someone suggests, there are maps. The tools folder is already more interesting (by the way, its contents are the same for starting kits in all languages): there are two jar-files there, without source codes. The first one is PlayGame.jar, which is a checker. You need to use them like this:
 java -jar tools/PlayGame.jar maps/map1.txt 1000 1000 log.txt "java -jar my_bots/trunk/MyBot.jar" "java -jar example_bots/ProspectorBot.jar" 

Just in case, I will explain: the first argument is the path to the map, the second argument is the maximum stroke length in milliseconds ( yes, the course is limited in time : if one of the bots thinks too long, it will automatically lose ), the third argument is the maximum number of moves. Next in the arguments is the name of the file for the logs, the command to be executed to start the first bot, and the command for the second. In principle, the engine also supports a larger number of players; you can also specify them on the command line. However, in a tournament, all matches are held in private.

The second file in the tools folder is ShowGame.jar, which visualizes the match, the description of which it needs to submit to the standard input. This is done specifically so that you can transfer the checker output directly to the visualizer:

 java -jar tools/PlayGame.jar params | java -jar tools/ShowGame.jar 

Next are the root files * .java. Appointments Fleet.java and Planet.java are obvious - they contain classes that describe the fleet and the planet, respectively. The PlanetWars class is already more meaningful: it can parse what the checker feeds the bot to stdin and present the result in a more or less user-friendly form. The interface (which, however, is not clearly marked) is something like this:

 public interface IPlanetWars { int NumPlanets(); Planet GetPlanet(int planetID); int NumFleets(); Fleet GetFleet(int fleetID); List<Planet> Planets(); List<Fleet> Fleets(); int Distance(int sourcePlanet, int destinationPlanet); void IssueOrder(int sourcePlanet, int destinationPlanet, int numShips); void FinishTurn(); } 

I said “about” because I brought only the main part of the interface, which is necessary for understanding the interaction mechanism; several more methods are actually available, but they are already mostly for convenience. By the way, considering how little the code corresponds to the Java Coding Conventions, it is likely that it was semi-automatically translated from language to language, and therefore does not differ between them at all.

All files that have been reviewed previously, do not have to leave. Feel free to change them (by the way, I highly recommend: they are written in terms of user convenience, or even deleted). But you cannot delete the file MyBot.java, and you must also have the main method in it, because it will be called by the checker. All the logic in the example is in the DoTurn method, which has as its input an instance of the class PlanetWars.

The code in the starter package is more or less well commented, so you will not be hard to understand how to use it and write your first simple bot. I just want to say that it is not allowed to create streams and write to a file.

2.3. We send the solution

To send a solution, you need to take all (all!) Source (!) Files that are needed for your bot to compile, package them into a zip-archive, and download them via this link . Note that the size of the archive should not exceed two megabytes. Although you, of course, are unlikely to write as much code;). After some time you will receive a letter in the mail in which the Compilation Script will share with you the result of your work. If everything goes well, the text will be something like this:

Google AI Challenge has successfully compiled. Here is the output of the compile script, in case you're curious:

Found entry.zip. Attempting to unpack.
 unzip -u entry.zip > /dev/null 2> /dev/null 

Found MyBot.java. Compiling this entry as Java
 javac Bot.java Fleet.java MyBot.java Planet.java PlanetWars.java SimpleBot.java jar cfe MyBot.jar MyBot Bot.class PlanetWars.class Planet.class Fleet.class MyBot.class SimpleBot$1.class SimpleBot.class 

The compile script

After some time after this, a record appears in your personal account that you sent the bot:

And after some time, your child will begin to valiantly fight with the other bots:

Each such battle can be viewed by clicking on the “View Game” link on the right. You can view your rating either in the Current Rankings section or in your profile.

I also want to add that you should not send bots right away, it is much advisable to first test it on your own on different maps. To do this, the local craftsmen (including your humble servant) started a script that automatically runs the bot on all the cards and all the bots from the examples (and other your bots, if any) and gives out statistics on victories. You can get this script here .

That's all. I will be glad questions, clarifications and corrections.

Bloody battles you and sweet dreams! ©

UPD: It's sad, but the competition site is down. For sufferers posted in this comment links to scripts for testing bots. Starter package for Java can be downloaded from this link . If someone shares links to starter kits for other languages, it will be cool! ;)

UPD2: Raised, but so far partially. They promise to fix everything by the end of the weekend. By the way, now the contest has become completely open source !

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

All Articles