Wood League

Welcome to the Bronze league!

In Bronze, you can now use MINES. There won't be any additional rules.

  The Goal

This is a two-player game based on the board game Captain Sonar.
You pilot a submarine. You know that an enemy is present nearby because you are listening to its radio frequency communication. You don't know exactly where it is but you can hear all of its orders.
You and your opponent start with 6 hit points. When a player's hit points reach 0, that player loses.

  Rules

Environment

  • The map is a square tiling: 15 cells wide and 15 cells high. The NW corner is (0,0); the SW corner is (0,14).
  • Each map cell is either open water or an island. Islands are obstacles. Submarines cannot move to or through islands. Nor can torpedoes or mines.
  • Submarines move on the open water cells of the map. Each player controls one submarine; both submarines move independently. They can share the same water cell without colliding.
  • The map is split in 9 sectors. Each sector encompasses a 5×5 block of 25 cells. You can find the sectors' numbering in the viewer; the top left sector is number 1 and the bottom right sector is number 9.

Game start

At the beginning of the game, you'll receive a full 15×15 map that indicates the position of the islands. You will then decide and reply where you want your submarine's starting position to be.


Turns

This is a turn-based game: each player plays a turn one after the other. The whole game lasts 299 turns per player. The player with id 0 begins.

During your turn, thanks to your radio frequency analysis, you will receive an indication of what your opponent has done. For example, you can receive that it moved to the north. It's up to you to use this valuable information to detect where the opponent actually is.

During your turn, you must perform at least one action.


Actions

Actions are your turn's output. They are provided sequentially, on a single line. You can chain several of them using a pipe symbol |.

But you can use each type of action only once per turn. For example you can MOVE once per turn, and no more. If you fail to output a valid action, your action will be forced to SURFACE.


Move

A move action has two effects:

  1. It moves your submarine by 1 cell in a chosen direction (north, east, south, west).
  2. It charges a special power of your choice, i.e. increases its energy level by 1.

When you move, you must respect the following rules:

  • You cannot move through islands.
  • You cannot move to a cell you have visited before.

Powers

For each move action you take, you have to decide what special power to charge. The special powers are performed by different devices, who require a different amount of energy to be ready.

The energy levels are separate per device, not shared. The amounts of energy needed to activate a device are also distinct per device.
A device's energy is fully consumed when that device's power is used. The energy level cannot grow above that device's requirement for one use of the power.

You can charge the torpedo, the sonar, the silence mode and mines.


Surface

The surface action will reset your path of visited cells, so that you can freely move to a cell that you have previously visited. But surfacing has major impacts: your opponent will know in which sector you are surfacing, and you will lose 1 hit point.

Torpedo

The torpedo action requires an energy level of 3. When fully charged, the torpedo can be fired at an arbitrary water position within a water range of 4 cells. This allows the torpedo's path to contain corners and go around islands, but not through them. The following image illustrates the range of a torpedo:

torpedo range

Explosions

When a torpedo or a mine explodes on a water cell, any submarine present on that cell and its 8 neighbors suffers a loss of hit points. The damage is 2 hit points on the explosion cell itself and 1 hit point on its neighbor cells—this includes diagonals.


explosion range

Explosions damage your opponent's submarine and yours indiscriminately. They have no effect on anything else (mines, islands).


Sonar

The sonar action requires an energy level of 4. When fully charged, it allows you to check whether the opponent's submarine is in a chosen sector.

The response will be provided to you in your next turn's input. Careful! Said response is in respect to the time you issued the order, so the opponent will have issued and performed orders of its own by the time you receive it.


Silence

The silence action requires an energy level of 6. When fully charged, it allows you to move 0 to 4 cells in a chosen direction. Same as with the Move action, you may not visit an island or an already visited cell, be it as a final action destination or a waypoint.
Your opponent will not know in which direction or how far you've moved. It will know that you used the silence action, though.

Mine

The mine action requires an energy level of 3. The mine can be placed on any cell next to you (north, east, south, west).
You can't place two own mines on the same cell. However it's possible to place your own mine on an opponent mine or the opponent's submarine itself.
Mines are only detonated by using the trigger action, not by a submarine moving onto them.

Trigger

The trigger action will cause a mine to explode. You can only trigger your own mines.
You can't trigger multiple mines in the same turn. You can't place a mine and trigger it during the same turn.
Mines' explosions behave exactly as torpedoes'.

Orders' visibility

The following table shows how different actions will be shown to your opponent:
Your actionShown to opponentComment
MOVE N TORPEDO MOVE N The opponent will not see which power is charged.
SURFACE SURFACE 3 The opponent will see which sector (in this case: 3) you surfaced in.
TORPEDO 3 5 TORPEDO 3 5 The opponent will see the same order you issued.
SONAR 4 SONAR 4 The opponent will see the same order you issued.
SILENCE N 4 SILENCE The opponent will see that you moved silently—but not where or how far.
MINE E MINE The opponent will see that you placed a mine—but not in which direction.
TRIGGER 3 5 TRIGGER 3 5 The opponent will see the same order you issued.
Victory Conditions
Have more hit points left than your enemy at the end of the game.
Loss Conditions
  • Don't respond in time.
  • Output an ill-formed order.
  • Reach 0 hit points or lower (while your opponent still has more than you).

  Expert Rules

The source code can be found here: https://github.com/CodinGameCommunity/ocean-of-code.

  Game Input

Inputs of the first turn
Line 1: width height myId, space-separated.
  • width and height indicate the size of the grid in cells (15 15)
  • myId indicates your player ID (0 or 1). The player with ID 0 begins.
Next height lines: a string of width chars representing the content of each cells of this row: x for an island, . for an empty cell.
Output for the first turn
2 space-separated integers x y which represent the coordinates of your starting position. The cell at the specified coordinates should be empty which means no island, but the opponent can choose the same cell!
Inputs for each turn
Line 1: 8 space-separated integers:
x y myLife oppLife torpedoCooldown sonarCooldown silenceCooldown mineCooldown
  • x and y represent your current position.
  • myLife and oppLife give the number of hit points you and your opponent have left
  • torpedoCooldown sonarCooldown silenceCooldown mineCooldown represent the number of charges each device still needs before it can be used.
Line 2: a string sonarResult which gives you the result of your SONAR action: Y for yes, N for no, NA, if you didn't use the sonar on the previous turn.
Line 3: opponentOrders, a summary of your opponent's actions (separated by a pipe symbol |) during its turn.
Example: MOVE N|TORPEDO 3 5
This example indicates that your opponent moved to the north and then fired a torpedo to (3,5).
On the starting player's first turn, this will be the string NA, since the opponent has no previous orders at that point.
Output for each next turns
One or multiple commands separated by a pipe symbol |.
Example: MOVE N TORPEDO | TORPEDO 3 5
These commands move your submarine to the north and then fire a torpedo at (3,5). Here are the different available actions:
  • MOVE direction power
  • SURFACE
  • TORPEDO X Y
  • SONAR
  • SILENCE direction distance
  • MINE direction
  • TRIGGER X Y
  • MSG message
Here are the different available powers to charge:
  • TORPEDO
  • SONAR
  • SILENCE
Constraints
Response time first turn ≤ 1000 ms
Response time per turn ≤ 50 ms
A game ends after 300 turns per player