###Rules

In this game you control a small armada of spaceships, mining the rare mineral “kore” from the depths of space and teleporting it back to your homeworld. But it turns out you aren’t the only civilization with this goal – in each game 2 players will compete to collect the most kore from the board. Whoever collects the most kore by the end of 400 turns, or eliminates all of their opponents from the board before that, will be the winner!

###Game Setup

![](https://i.imgur.com/idqedNQ.png)

At the start of the game, each player is assigned a random quadrant (and associated color) on the game board. Each player starts with 1 shipyard and 500 kore.

The game board is 21x21 cells large and wraps around on both the north/south and east/west borders. The southwest (bottom-left) corner of the board is designated (0,0) and the northeast (top-right) corner of the board is designated (20,20). 

*Strategy Tip: Due to the board wrapping, fleets sent out from the shipyard straight in any direction will return to that shipyard.*

The map is covered with a random distribution of kore. This distribution is symmetric both vertically and horizontally. In total, the game board starts with 2,750 kore on it. In the visualizer, the size of the kore icon is proportional to the amount of kore on that square.

###Summary

- The player with the most kore at the end of the game wins.
- You start the game with 1 shipyard and 500 kore.
- Creating a ship at a shipyard costs 10 kore.
- Fleets are launched with 1 or more ships.
- Converting a fleet of ships to a shipyard consumes 50 ships.
- Each turn you can issue a command to each of your shipyards to spawn more ships or launch a new fleet of ships with a flight plan.
- Each turn a fleet reads its flight plan. 
-- If it starts with one of NESW, it turns the fleet in that direction and the fleet moves
-- If it starts with an integer, decrement the integer and the fleet moves in its current direction
-- If it starts with a C, the fleet attempts to create a new shipyard at the given location.
-- If there are no characters remaining in the flight plan, the fleet will continue in its current direction
- As a fleet moves across the board, it mines kore underneath its current position. Mined kore is stored on the ship, and there is no maximum to how much kore a ship can hold.
- Kore in fleets cannot be spent to buy ships until deposited at a shipyard. At the end of the game - Players need to move their fleets over shipyards to deposit the kore and teleport it back to their homeworlds to count for the final kore total.
- Fleets that move onto the same square collide. First, allied fleets are absorbed into the largest fleet (most ships, or, if equal, the fleet with the most kore). The largest fleet (that is, the one with most ships) survives and all other fleets will be destroyed. The remaining fleet loses ships equal to the ship count of the second largest fleet. The largest fleet steals all of the kore from other fleets it collides with. If two or more fleets tie for the largest number of ships, they are both destroyed and their kore is left on the square. 
![](https://i.imgur.com/m81KdOX.gif)
- After fleet collision, a check then is performed for a fleet-shipyard collision. If the colliding enemy fleet has more ships than the shipyard, then the shipyard owner will change possession


###Turn Order

Each game of Kore lasts for 400 turns or until all but one player has been eliminated. Each turn, each agent will be given a copy of the board state (the “observation”) with complete information about every aspect of the game (including how much kore each player has, the position of all fleets (and ship_count, kore carried and flight_plan) and how much kore is on every cell of the board). Each agent will then need to return a list of actions for their shipyards to take within a set amount of time.

If your agent does not return actions in time or encounters an error, it will be marked as errored and will immediately have all its fleets and shipyards removed from the game. 

Each turn each shipyard can take one of the following actions:

**Spawn Ship**
Actions: SPAWN_X
Cost: 10 kore per ship (10 * X)

This action will add X ships to the shipyard ship count. Initially, a shipyard can only spawn 1 ship at a time but the longer you control the shipyard the more you can spawn (up to 10). Shipyard turns_controlled is used to track how long a player has controlled a shipyard. Assuming a shipyard currently can spawn Y ships, after controlling it for Y^2 + 1 turns it can now produce Y+1 ships. See the following table:

| Turns Controlled | Spawn Maximum |
| --- | --- | 
| 0 | 1 |
| 2 | 2 |
| 7 | 3 |
| 17 | 4 |
| 34 | 5 |
| 60 | 6 |
| 97 | 7 |
| 147 | 8 |
| 212 | 9 |
| 294 | 10 |

**Launch**
Actions: LAUNCH\_X\_<FLIGHT_PLAN\>
Cost: 0 kore

This action will launch a fleet with X ships, which follows the given flight plan. Given the flight plan a fleet will either continue in its current direction, turn and move, or convert into a shipyard. To create a shipyard there must be at least 50 ships.

**Flight Plans**
Flight plans determine the path charted by the launching fleet. Their maximum length is determined by the size of the fleet with the following formula: `floor(2 * ln(num_ships)) + 1`. Length is measured by simple string length `len(flight_plan)`. Once launched flight plans are visible to all enemies and cannot be changed other than the once a turn update.

*Strategy Tip: Notice that the minimum number of ships for a fleet that can complete a circle (eg “N5E5S5W”) is 21. Consider how the fleet coalescence mechanics might allow for collection with smaller fleets.*

**Converting**

When converting into a shipyard, any kore on the cell underneath the new shipyard will be destroyed. Any kore carried by the fleet converting itself will be deposited instantly and the fleet will lose 50 ships. Any remaining ships are added to the shipyard’s ship count. 

If the fleet does not have at least 50 ships when it gets to this instruction (after a collision with an enemy for example) it will skip the convert instruction and will continue in its current direction and process following commands as normal. 

*Example: if a fleet with size 40 has the flight plan `NCW` it will act as though it has a flight plan of `NW` (skipping over the C to the next valid instruction).*

###Turn Resolution
After both players have submitted their actions for the turn, the system will automatically resolve the turn and update the board state. All player turns are resolved simultaneously across the following phases:

**1. Spawning and Launching**

All shipyards that ordered a spawn action are resolved with new ships being added to their ship_count. All shipyards that ordered a launch action have ships deducted from their ship count to create the new fleet and the new fleet is created. Note, after this the fleet will occupy the same square as the shipyard.

**2. Fleets Update Flight Plan**

All fleets process the next part of their flight plan (if present). This could result in a fleet updating its direction, or attempting to convert into a shipyard.
| Current Flight Plan | Fleet Affect | Next Flight Plan | 
| --- | --- | --- |
| "N" | Fleet direction set to North | "" | 
| "N5E" | Fleet direction set to North | "5E" | 
| "5E" | - | "4E" | 
| "C" | Fleet attempts to convert to shipyard | - | 
| "10E" | - | "9E" | 

Fleets then move 1 forward in their current direction.

**3. Fleets Convert to Shipyard**

When converting into a shipyard, any kore on the cell underneath the new shipyard will be destroyed. Any kore carried by the fleet converting itself will be deposited instantly and the fleet will lose 50 ships. Any remaining ships are added to the new shipyard’s ship count.

**4. Fleets Move**

All fleets move forward one square in their current direction.

**5. Allied Fleets Coalesce**

Any allied fleets that currently occupy the same space are added to the largest allied fleet in that location. Ship size, current kore, and finally direction (NESW) are used to determine the largest fleet.

**6. Fleet Collisions**

Fleet collision is resolved, reducing the number of fleets in every cell on the board to one or less. In each collision the largest fleet is the survivor, with all others destroyed. The largest fleet loses ships equal to the ships in the seconds to largest fleet. The largest fleet is defined as the ship with the most ships. If multiple ships tie for having the most ships, all the fleets in the collision are destroyed and their carried kore is deposited onto the square. The surviving fleet loses ships equal to the size of the second to largest fleet, takes all the kore from the destroyed ships’ cargoes, and retains its place on the board.

**7. Shipyard Collision**

If a fleet occupies the same square as an allied shipyard, that fleet’s ships are added to the shipyard and its kore is added to the player's kore count. If a fleet and shipyard from different players occupy the same cell:
1.  if the fleet contains more ships than the shipyard, the shipyard changes hands (resetting turns controlled) to the fleet player and that player adds the kore from the fleet to their kore supply and the shipyard starts with the `fleet.ship_count - shipyard.ship_count` ships. 
2. if the shipyard contains more ships the fleet is destroyed and the defending shipyard loses ships equal to the attacking fleet's ship count. The defender also claims the kore from the attacking fleet. 

Losing your shipyard does not reduce your total kore - all deposited kore has already been teleported safely back to your homeworld.

**8. Fleet to Fleet Damage**

Each fleet does damage to all enemy fleets orthogonally adjacent to it (North, East, South, West) equal to its current ship count. Destroyed fleets drop 50% of their kore onto their currently occupied position with 50% being awarded to their attackers (proportionally to their attack if there are multiple). If the attacking fleet does not survive, the kore is dropped back onto the tile instead.

Strategy Note: This allows a single fleet to do damage to multiple fleets!

**9. Kore Mining**

All fleets on a square with kore mine it, moving a certain percentage of the cell’s kore into that ship’s storage. Kore in ship storage is indicated in the visualizer by a blue glow in the center of the fleet. The formula to determine the percentage mined is determined by the fleet’s ship count with more ships mining more kore and tops out at 99%. The percentage (decimal) is given by this formula: ln(num_ships) / 20

| Number Ships | % mined  |
| --- | --- | 
| 1 | 0 |
| 2 | 3 |
| 3 | 5 |
| 5 | 8 |
| 8 | 10 |
| 13 | 13 |
| 21 | 15 |
| 34 | 18 |
| 55 | 20 |
| 91 | 23 |
| 149 | 25 |
| 245 | 28 |
| 404 | 30 |

**10. Kore Regeneration**
Every cell on the board that has more than 0 kore and no fleets on top of it will now regenerate by 2% of the existing amount of kore in the cell. Cells with 500+ kore do not regenerate. Note that a cell can contain substantially more than 500 kore if several fleets collide and deposit their carried kore.

**11. End Turn**
The “step” number is incremented, ending the turn. The updated board is saved and redistributed to each agent as the “observation”, moving to the next turn.

At this step, a player is eliminated if they are no longer able to viably compete in the game. This happens when the player no longer has any ships (across both fleets and shipyards) and has less than ship_cost kore remaining. If eliminated, all of a player’s remaining shipyards are removed from the game.

At the end of each turn, the game also checks if a player has been eliminated or if the game has reached turn 400. If either of those is true instead of starting a new turn the game moves to the game end step.