In this challenge, you must design a species of single-celled organisms to fight to the death in the petri-dish arena. The arena is represented as a rectangular grid, where each cell occupies one space:
.....x.... ...x...o.. ...x.c..o. .......o..
Every cell has three attributes. When specifying your cell species at the start of the game, you allocate 12 points among these attributes.
- Hit Points (HP): If a cell's HP falls to zero, it dies. New cells have full HP.
- When a cell dies, it leaves behind a corpse which can be eaten by other cells for energy.
- A cell cannot regain lost HP, but it can create a new cell with full HP by dividing.
- Energy: Most actions a cell can take require energy. By actively resting, a cell can regain lost energy up to it species' maximum.
- A cell species with less than 5 energy is likely to fail, because it cannot divide to create new cells.
- A cell cannot regain energy beyond its species' maximum value.
- A newly created cell has an initial energy value copied from its parent (and a max value dictated by its species specification).
- Acidity: If a cell chooses to explode, the cell's acidity level is used in calculating damage to adjacent cells.
Each turn, every cell can take one action:
Move: The cell moves one space in any direction (N/S/E/W/NE/NW/SE/SW) at a cost of 1 energy.
- A cell cannot move onto a space occupied by another living cell.
- A cell cannot move off of the grid.
- Moving onto a cell corpse destroys the corpse.
Attack: A cell attacks an adjacent cell, dealing 1 to 3 damage, by expending 1 to 3 energy points.
- A cell can attack in any direction (N/S/E/W/NE/NW/SE/SW).
- It is legal to attack friendly cells.
Divide: The cell divides and creates a new cell on an adjacent space, at a cost of 5 energy.
- A cell can divide in any direction (N/S/E/W/NE/NW/SE/SW).
- The new cell has full HP according to your original cell specification.
- The new cell has as much energy as its parent cell does after subtracting division cost. (For example, a parent cell with an initial 8 energy points will be reduced to 3 energy and produce a child cell with 3 energy).
- A new cell cannot act until your next turn.
- A cell cannot divide into an space occupied by a living cell, but it can divide into a space occupied by a dead cell corpse (this destroys the corpse).
Eat: A cell eats an adjacent cell corpse, gaining 4 energy.
- A cell can eat in any direction (N/S/E/W/NE/NW/SE/SW).
Rest: A cell does nothing for one turn, regaining 2 energy.
Explode: When a cell has 3 or fewer HP and more energy than HP, it may choose to explode, dealing damage to all eight adjacent cells.
- Damage to each adjacent cell is
(exploding cell HP) + (explodng cell acidity)
- An exploded cell dies and leaves behind a corpse, as do any cells killed in the explosion.
- Damage to each adjacent cell is
Your program will run with the string
BEGIN provided on stdin. Your program must write to stdout a space-separated list of 3 non-negative integers, representing HP, energy, and acidity for your cell species: e.g.,
5 6 1. The numbers must sum to 12. Acidity may be
0, if you wish. (Other attributes may also be zero, but doing so functionally forfeits the game!)
You begin with one cell, in the northwest or southeast corner, one space away from either edge. The beginning cell has full HP and energy.
Every cells acts
Every turn, your program will be invoked once for every cell alive on your team (except cells just created this turn) so that cell can act. Your program is provided with data on stdin that includes the petri dish state and information about this particular cell:
10 4 .......... ..xx.c.... ...c...o.. ......o... 6 3 5 7
The first two numbers indicate arena width and height: here, there is a 10-by-4 arena.
ocells are yours; the
xcells are your enemies. (This is always true; each player always sees their own cells as
.spaces are empty.
cspaces represent edible cell corpses.
The numbers after the empty line represent info about this cell:
- The first two numbers are
x,ycoordinates, indexed from
0,0in the top left (so
6 3here refers to the south-most
- The third number is the cell's HP; the fourth number is the cell's energy.
Your program should output (to stdout) an action. In the examples below, we'll use
N as an example direction, but it can be any direction legal for that action (
SW). All program output is case-insensitive, but examples will use uppercase. Any output action that is invalid (either because it has invalid syntax or attempts an illegal action) is ignored and results in the cell
RESTing (and thus gaining 2 energy).
ATTACK N 2- the number represents the strength of the attack (1 - 3)
Your team's turn consists of all your cells being given an opportunity to act, one by one. All of your cells act before any of the opponent's cells act. Once all of your cells act, your turn ends, and your opponent's turn begins. Once all your opponent's cells act, your turn begins again. Within your turn, each cell is given priority to act based on its age: the oldest cells on your team act first before younger cells.
Here's how a program might behave. Input from stdin is denoted here with leading
> arrows (separated from actual input by a clarifying space) and output on stdout has
> BEGIN < 5 6 1
Then, the program is invoked again:
> 10 4 > .......... > .o........ > ........x. > .......... > > 1 1 5 6 < DIVIDE SE
After your opponent's turn (who decided to
DIVIDE W with the single starting cell), your program is invoked twice, once for each cell:
> 10 4 > .......... > .o........ > ..o....xx. > .......... > > 1 1 5 1 < MOVE E
For the second invocation on your turn:
> 10 4 > .......... > ..o....... > ..o....xx. > .......... > > 2 2 5 1 < MOVE SE
Note this second cell sees the updated board state based on the other cell's movement earlier in your turn. Also note this cell has been created with 1 energy, because the parent cell had 6 energy when it performed division last turn (so the original 6, minus the 5-energy cost of division, created a child cell with 1 energy).
Now your turn is over and your opponent's turn begins. The two opposing cells will be given a chance to act, and then your next turn begins.
You can win by either:
- Destroying all opposing cells, or
- Having more cells than your opponent after each player has completed 150 turns
Scoring will be based on number of wins in 100 games against each other submission. In half of the simulations, your program will be allowed to go first.
Tie games (i.e. exactly the same number of cells after 150 turns, or the only remaining cells are killed together in an explosion) are not counted in either player's win totals.
- Your program should not attempt to maintain state (beyond using the state of the Petri dish): monocellular organisms do not have a very good memory and react to the world moment by moment. In particular, writing to a file (or other data store), communicating with a remote server, or setting environment variables are explicitly disallowed.
- Submissions will be run/compiled on Ubuntu 12.04.4.
- The specifics of the 100 scoring games are not yet confirmed, but they will likely involve multiple arena sizes (for example, 50 runs on a small arena and 50 runs on a larger arena). For a larger arena, I may increase the max turn count to ensure that a proper battle can take place.
Here is the driver code that runs the simulation, written for Node.js, called by
node petri.js 'first program' 'second program'. For example, pitting a Python-written cell against a Java-written cell might look like
node petri.js 'python some_cell.py' 'java SomeCellClass'.
Additionally, I understand that reading and parsing multiple lines on stdin can be a huge pain, so I've drafted a few complete sample cells in different languages which you are free to build upon, completely overhaul, or ignore entirely.
Of course you are free to write a cell in a different language; these are simply three languages I decided to write boilerplate code for as a time-saving aid.
If you have any problems running the driver, feel free to ping me in the chat room I've created for this challenge. If you don't have sufficient reputation for chat, then just leave a comment.