Problem A
Planetoids
While analyzing strange artifacts discovered in the far reaches of the galaxy, your ship has strayed into a perilous asteroid field. But these hunks of rock are like none you’ve ever seen before. It’s almost like they stick to one another! Your task is to design an AI for your ship’s computer to navigate these unknown regions of space and protect yourself from these asteroids along with any other beings that might wish you harm. This AI will be scored based on points that can be earned in a variety of ways outlined below.
Rules
Overview
-
Your AI will play three separate games at 2x simulation speed and your final score will be the sum of your runs. Each game will last for a maximum of 30 in-game seconds. The game will end when time runs out.
-
You start with 5000 points each run. If your ship is damaged, you lose points.
-
Entities that cross over the edge of the map will appear on the opposite side. The map is fixed size (see constants table below).
-
When determining your place on the scoreboard, ties are broken by whoever has the earlier submission.
Asteroids
-
Asteroids come in three size categories, small, medium, and large.
-
In addition to being able to damage your ship on contact, if any two asteroids of the same size come into contact with one another, they will reform into an asteroid of the next size up.
-
Breaking up these asteroids and finishing off smaller ones with your ship’s cannons will add points to your final score. Secondary asteroids (formed from a split) are worth half points.
UFOs
-
UFOs might also appear and can be destroyed with your cannons for points as well. But be warned, as these spacefaring entities also wish you harm.
-
Small UFOs will fire their own cannons at you while large UFOs will fire their cannons in a circle around them.
-
UFO bullets will not destroy or split asteroids for you.
Artifacts
-
You may attempt to continue your original mission and collect valuable artifacts floating in these far reaches of space. Artifacts are gathered simply by touching them.
-
These valuable objects float in space and there is one present at a time. When touched they move to a random location on the field of play.
-
While not necessary, picking up these artifacts will earn you a considerable number of points as well.
Input
Over STDIN you will receive a plaintext JSON describing the
simulation state of the game. You only receive simulation
frames when you submit a command over STDOUT (see Output section). We have given asteroids,
bullets, and UFOs each a unique ID so you can identify how
these entities move from frame to frame. Here is an example
JSON:
{ "artfPos": [ -3286.76806640625, -284.64599609375 ], "astIds": [ 3 ], "astNum": 1, "astPos": [ [ 2936.709716796875, -1737.310546875 ] ], "astSizes": [ 49 ], "bulIds": [ 5 ], "bulNum": 1, "bulPos": [ [ 2.0, 0.0 ] ], "bulSrc": [ 48 ], "currentRound": 1, "currentScore": 0, "currentTime": 4.182635307312012, "gameOver": false, "lives": 3, "shipPos": [ -2344.286376953125, -122.93001556396484 ], "shipR": 183.00173950195312, "ufoIds": [ 4 ], "ufoNum": 1, "ufoPos": [ [ 0.0, 0.0 ] ], "ufoSizes": [ 49 ] }
-
Player Ship information: shipPos, shipR (degrees, counterclockwise from X-axis)
-
Artifact information: artfPos
-
Game information: currentScore, currentTime (seconds), currentRound, lives
-
Asteroid information: astNum, astPos, astIds, astSizes
-
UFO information: ufoNum, ufoPos, ufoIds, ufoSizes
-
Bullet information: bulNum, bulPos, bulIds, bulSrc
Notes
-
Asteroid, Bullet, and UFO lists are correlated by index. For example, the first entry in the bulIds list gives the ID for the bullet whose position is given by the first entry in the bulPos list.
-
UFO and Asteroid sizes are encoded as the characters: ‘0’ for small, ‘1’ for medium, and ‘2’ for large (decimal 48 for small, 49 for medium, and 50 for large if interpreted as ints).
-
bulSrc is likewise a char that represents an int. This indicates whether you shot the bullet or an enemy shot the bullet. If an enemy shot the bullet, it is denoted with the char ‘0’. The player’s is denoted with the char ’1’. Note this is separate from bullet IDs. A bullet ID is a unique identifier for the bullet, whereas bullet source denotes which team (enemy or player) shot the bullet.
-
We are generally not providing source code for parsing JSON. We do provide one for C++, and others (like Python) have a JSON parser built-in.
-
Please ignore: currentRound, lives
-
Use ’gameOver’ to know when to terminate your main loop. If your app doesn’t terminate properly it may get rejected.
Output
To control the ship you will output a 6-character ASCII string to STDOUT followed by a single ‘\n’ (newline) character. This will contain information on what you want your space ship to be doing. The characters encode the following information:
Position |
’0’ |
’1’ |
0 |
Thrust Off |
Thrust On |
1 |
Clockwise Rotation Off |
Apply Clockwise Rotation |
2 |
Counterclockwise Rotation Off |
Apply Counterclockwise Rotation |
3 |
N/A |
Fire Bullet |
4 |
N/A |
Activate Hyperspace |
5 |
Request Input Frame (Ship State Ignored) |
Change Ship State |
IMPORTANT: The game runs in lockstep with your submission, so you must send commands and receive frames as fast as possible (within 16ms) one after another. If you don’t have any updated state for your ship you can send a no-op (all zeros) so that the frame will process and be returned to you.
Notes
-
Engaging your thrusters will accelerate your ship forward, and disengaging them will cause your ship to naturally decelerate.
-
Activating Hyperspace will teleport your ship to a random position on the map. There is a 5-second cooldown before you can enter hyperspace again.
-
Firing a Bullet will cause your ship to fire a shot. There is a 3-second cooldown until the next one will fire.
-
You will only receive the state of the game if you give the game input. Thus, we have provided a way for you to send a no-op (000000) that lets you simply request the state of the game.
-
Sending any other characters will result in your submission being rejected. Your commands must be of the form “000000\n” (six characters of 0 or 1 followed by a newline).
Below is an example output (thrusters on, rotate clockwise,
fire bullet, change ship state):
110101
Simulation Constants
Name |
Value |
Units |
General Simulation Constants |
||
(WorldWidth, WorldHeight) |
(7600, 4200) |
units |
Scoring Constants |
||
Destroy UFO |
1500 |
points |
Collect Artifact |
2000 |
points |
Player Ship Damaged |
-350 |
points |
Destroy Asteroid (Small) |
150 |
points |
Destroy Asteroid (Medium) |
300 |
points |
Destroy Asteroid (Large) |
300 |
points |
Asteroid Constants |
||
Asteroid Radius (Small) |
50 |
units |
Asteroid Radius (Medium) |
100 |
units |
Asteroid Radius (Large) |
200 |
units |
UFO Constants |
||
UFO Radius (Small) |
40 |
units |
UFO Radius (Large) |
80 |
units |