Aineopintojen harjoitustyö: AI Odyssey 2012 : Challenge III
Challenge III: Space War - deadline Monday Dec 10th 10:00 am
Update: The challenge is over. The results and replays can be viewed at http://www.cs.helsinki.fi/u/sysikask/ai2012/sw.html.
During your space odyssey somewhere in outer space, your ship computer HAL 9001 has went rampant and started destroying your starships. The computer has taken control of one of the nearby planet and creates starships there and sends them to conquer other planets. The only way to stop HAL 9001 from causing further havoc is to create an AI that controls your remaining forces to take out the enemy.
Your task is to create an AI that plays a two player game where the goal is to destroy all enemy units. The game area contains planets in 3D space. Each planet is controlled by either one of the players or is neutral. The image below shows a screenshot of the game.
The blue planets are owner by one player, and the red planet by the other player. The Grey planets are neutral. The numbers on the planets represent the number of spacecrafts there. The number of spacecrafts on the planets owner by the player gradually increases.
Players may send spacecrafts from planets to other planets, either to conquer them or to defend their own planets agains attacks of the enemy. In the picture above the red and blue cubes are spacecrafts heading to some planets.
Game rules
At the start of the game, the server tells both bots details of nearby planets. After that the game starts running, and players may send crafts from the planets they own to some other planets.
Each planet contains some number of spacecrafts. When a single spacecraft arrives to some, planet, one of tree things might occur:
- If the planet is owned by the same player as the spacecrafts, the crafts are added to the planet's crafts.
- If the planet contains no spaceships previously, the craft conquers the planet. The owner of the spacecraft becomes the owner of the planet and the craft count of the planet becomes 1.
- Otherwise, a battle occurs, and both the arriving spacecraft and one of the spacecrafts of the planets get destroyed. If the craft count of the planet becomes 0, the planet becomes a neutral planet.
The spacecrafts travel constant speed of 18 units per second in space. After a spacecraft has been sent from one planet to other one, it is impossible to control its course before it arrives to the destination planet.
On each planet owned by either player, a new spacecraft is created every 1/s seconds, where s is the size of the planet. New spacecrafts are only created on planets owned by one of the players, not on neutral planets.
The game ends when one of the following conditions becomes true:
- All spacecrafts of one of the players are destroyed. The remaining player gets 100 points and the other player 0 points.
- The game has run for 30 seconds. Players get points depending on how many spacecrafts they have. If the first player has x spacecrafts and the second player y spacecrafts, the first player gets score 100*x/(x+y) and the second player 100*y/(x+y), rounded to integers.
Technical details
The game works in real time. That is, there are no turns and players may make their moves at any time. There is no limit on how much CPU time you use, but you may want to make your bot relatively fast to quickly react to changing game situations.
Your bot communicates with the game server via standard input and standard output (eg. System.in and System.out). The server refers to the players by ID numbers: both bots may assume that their own ID is 1, the ID of the enemy is 2 and the neutral planets are owned by player ID 0. At the start of the game, the server writes the description of the planets. The description has format:
<number of planets n>
<description of planet 0>
<description of planet 1>
...
<description of planet n-1>
Each planet is described by a line containing 7 numbers: x y z size population owner.
- (x,y,z) is the position of the planet.
- size is the radius of the planet.
- population of the number of spacecrafts on the planet.
- owner is a number 1-2 depending on which player owns the planet or 0 if the planet is neutral.
After the server has written the planet description to both players, the game is immedialy started. During the game, the bot may communicate with the server by writing one of the following commands (followed by a line break) to the standard output:
STATUS
- Asks current game status from the server. The server replies with a line of the format: PLANETS <planet 0 population> <planet 0 owner> ... <planet n-1 population> <planet n-1 owner>
- The populations are given as floating point values. The integer part is the actual number of spacecrafts, and the fractional part tells how ready a spacecraft is to completion. Eg. number 7.9 means that the planet contains 7 spacecrafts and the 8th craft is 90% complete.
SEND <from> <to> <count>
- Sends count crafts from planet number to to planet from.
- If the number count is greater than the number of spacecrafts on the planet from, all crafts on the planet from are sent.
- Planet numbers from and to are 0-indexed indices of the planets.
- As a reply, server send to both players message of the form: SEND <sender> <from> <to> <count>
- sender is the ID of the sending player. Other parameters are the same as in the original message, except that count may have been fixed if it was too big.
- Trying to send crafts from a planet not owner by the player results in the message being silently ignored. This might happen if enemy is attacking your planet at the same time you try to send crafts away from there.
- If count<=0 or the source planet doesn't have any spacecrafts then the message is also ignored.
Completing the challenge
Your bot will play for three rounds against three bots of the organizers and the bots submitted by all other students. To pass your solution must get total score at least 800 agains the three organizers' bots. The bots are called sample, attack and expand in the judge system.
Sample code and testing your solution
There is a github project for the judge system of the challenge. You may checkout the project by issuing the command
git clone https://github.com/sisu/spacewar.git
This creates directory spacewar containing the judge code. Subdirectory sample contains sample solutions in Java and C++.
Compile the judge program by running command make in spacewar directory. After that you may start game by executing (after compiling your code and having run.sh-script that starts the program):
./play <program1 location>/run.sh <program2 location>/run.sh
The judge program opens a window and displays a visualization of the game there.
The program generates a replay file game.replay. You may view replays by executing:
./play -r replayfile.replay
Submitting solutions
The format is the same as in the previous challenge. That is, a zip archive containing the source code, compile.sh and run.sh at the root. Make sure that the scripts compile.sh and run.sh use unix newlines \n (not \r\n).
Send your submissions to http://t-avihavai.users.cs.helsinki.fi/ai-challenges-new/
You may view the current game that is being played on this page (requires webgl support). Note that the current game can only be viewed from the intranet of the department because you can't access the judge server from the outside. The judge system also includes the ability to view replays of your games in browser.
As usual, also send a brief report of your work to sysikask@cs.helsinki.fi.
References
This game is based on Galcon. There is a flash version that you might want to try to see how the game works out.