• 4

Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.



In this game you have to extinguish the fire while saving as many squares in the forest as possible.


You operate on a 10x10 square map.
At each turn, your program receives the map of the forest and the state of each square.
Based on this data, your program must determine which forest square to send water to in order to put out the fire.
Unfortunately, under certain circumstances, as described below, fires spread to neighbouring squares.
To win you must put out all the fires, while limiting the number of squares burned to a maximum given to you in the variable maxBurnedForest.

The map

Each of the 10 lines of the map is given to you by a string. Each character represents a cell of the map.
. represents an empty square with no forest. It cannot burn.
^ represents a forest square.
* represents a burned forest square. It can no longer catch fire.
1, 2 or 3 represents a forest square on fire. The value corresponds to the development level of the fire.

The spread of fire

Fire on a square can have 3 levels of development and, unless fought, evolves as such:
  • fires grow by one level per turn,
  • except for level 3 fires which, on the next turn, turn into burned forest squares and spread the fire to their 4 neighbouring squares (N/S/E/W) if
    • the neighbouring square is a forest square, not burned,
    • there is not already a fire on this square.
    The fire on these neighbouring squares starts at level 1.

Fighting fire

Once per turn you can extinguish the fire in a square by spraying it with water.
The fire in this square is extinguished immediately and does not spread to neighbouring squares.
To determine the box for which you want to fight the fire, you simply write its x and y coordinates (or column and row) on the standard output.

Sequence of actions

In each turn, the game follows the following actions, in this order
  1. Extinguish the fire on the square determined by your program.
  2. Evolution of the remaining fires (1>>2, 2>>3, 3>>burned)
  3. Spread of fire around the squares that have just been burned

Winning and losing

You lose if
  • you do not send the coordinates of a game square within the time limit,
  • the number of squares burned exceeds the maximum indicated in maxBurnedForest
Victory conditions
You win when there are no active fires left on the map and the number of burned forest squares remains below maxBurnedForest.

  Game Input

Initialization input
1 integer maxBurnedForest representing the maximum number of forest squares burned that you are allowed.

Input for a game round
10 rows row representing the map of the forest and its active fires
Two integers X and Y to designate the square on which to put out the fire.

A higher resolution is required to access the IDE

codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
Online Participants