[Community Puzzle] Forest Fire


Send your feedback or ask for help here!

Created by @AlBlazing,validated by @eulerscheZahl,@bbb000bbbyyy and @JBM.
If you have any issues, feel free to ping them.

Errr… I can’t seem to get a submission through.
The IDE’s results pane is stuck in a “computing score” status.


The validators have to be named test<number>.json, not validator<number>.json.
I renamed them and reuploaded.

In the validation process I would really like to see the puzzle in a way as it will be shown after approval (including hidden statement for reverse clashes).


18/06 /2019 - 17:10

Still stuck for me.


Also, 1 on every 3 attempts at stage 2, I get this error:

Thanks, now it works.

1 Like

Test 02 fails on 3/5 runs for me with:

The game has crashed. Please contact the author and enclose the following error:

java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
   at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
   at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
   at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
   at java.base/java.util.Objects.checkIndex(Objects.java:372)
   at java.base/java.util.ArrayList.get(ArrayList.java:458)
   at com.codingame.game.Referee.init(Referee.java:55)
   at com.codingame.gameengine.core.GameManager.start(GameManager.java:111)
   at com.codingame.gameengine.core.RefereeMain.start(RefereeMain.java:69)
   at com.codingame.gameengine.core.RefereeMain.main(RefereeMain.java:52)
1 Like

Can you share the outputs of your bot to reproduce the crash?

the game crashes on this line:
L = Integer.parseInt(gameManager.getTestCaseInput().get(0));
The referee randomly fails reading the map from the testcase. It works most of the time but not always. I think that’s the SDK’s fault, not the game itself.

The game has crashed. Please contact the author and enclose the following error:

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
	at com.codingame.game.Referee.gameTurn(Referee.java:160)
	at com.codingame.gameengine.core.GameManager.start(GameManager.java:122)
	at com.codingame.gameengine.core.RefereeMain.start(RefereeMain.java:69)
	at com.codingame.gameengine.core.RefereeMain.main(RefereeMain.java:52)

As I wrote above, that line 55 reads the testcase input:

L = Integer.parseInt(gameManager.getTestCaseInput().get(0));

For whatever reason it failed to do so.
I had a similar issue with Bender, where one validator was almost always failing. A simple reupload of the game solved the problem.

Maybe reuploading will work here as well, but instead I would like staff to have a look (ping @TwoSteps) as I think the cause goes beyond the puzzle itself.

I had to play the 2nd testcase about 10 times to reproduce the crash. I think any player code should do the job, as the testcase gets loaded before executing the player.

1 Like

I can pass all IDE tests, but not with the same code :frowning:
The statement suggests ‘greedy algorithms’ so I did not implement simulation just selecting ‘best’ next action from all possible ones.
However, if I sort the actions by ‘cost per fire’, ‘fire’, ‘vehiclesize’ then IDE test L fails, all other OK including XL.
If I sort the actions by ‘fire’, ‘cost per fire’, ‘vehiclesize’ then IDE test XL fails, all others OK.
It seems I still need to take into account if an actions make good action in subsequent turn impossible - but that would need simulation and search tree which I wanted to avoid by being greedy.
Any ideas, what is the good greediness criteria to use?


As @TBali pointed out, greedy with weighting also didn’t work for me. I got 100% with some random weights associated to the fires doused, and a check for immediate completion. But I DON’T pass all test cases, so it’s not a correct solution. Can the author of the puzzle please explain what greedy approach is intended by the tag :slight_smile:

A few weeks after my earlier post I finally passed this puzzle with the greedy method by using a manual (but fixed) precedence of the possible actions. (A fixed “[coversize][firecount] => priority” lookup table, I found by try-and-error.) Not nice, but at least not ‘test-case specific hardcoded’. In retrospect, the resulting order has some logic , but not one that I thought of by myself :slight_smile:

1 Like

Congratulations on not having hard coded :pensive:. But I don’t follow your algo. Could you elaborate?

Code excerpt (in PHP syntax, sorry if not your prefered one…)

const Order = array(
// [cover][fire] => precedence
// [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
1 => [ 0, 7, 0, 0, 0, 0, 0, 0, 0, 0],
2 => [ 0, 8, 6, 5, 4, 0, 0, 0, 0, 0],
3 => [ 0, 13, 12, 11, 10, 9, 3, 2, 1, 0]
static function compare3(array $a, array $b): int {
$a1 =self::Order[$a[‘cover’]][$a[‘fire’]];
$b1 =self::Order[$b[‘cover’]][$b[‘fire’]];
return $a1 <=> $b1;

I generate an array for the 14 possible actions (where cover*cover <= fire)
Could have used a class for the Action, used associative array instead.

tryOrder[] = array(‘cover’ => $coverSize, ‘fire’ => $fireSize, ‘cost’ => $perFireCost);

then sort it using the fixed priority above:

usort($tryOrder, array(‘ForestFire’, ‘compare3’));

Then I try to use the actions in this sorted order

foreach ($tryOrder as $try)
// check if current action is still possible (have enough water and have suitable target) and use it

1 Like

I have to wonder if I missed the point of the exercise as I was able to solve the puzzle without taking water usage into consideration (my program assumed there would always be enough water to put out all the fires).

My program just went from most dense to least dense, firing the appropriate amount of water to cover the intended area. I passed every test case, and I was wondering if my solution was possibly too long or if the puzzle wasn’t able to fool the conditions that I had set for it.

It doesn’t work for me. I’m getting this error :
java.lang.NumberFormatException: For input string: “”
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.base/java.lang.Integer.parseInt(Integer.java:662)
at java.base/java.lang.Integer.parseInt(Integer.java:770)
at com.codingame.game.Referee.gameTurn(Referee.java:168)
at com.codingame.gameengine.core.GameManager.start(GameManager.java:122)
at com.codingame.gameengine.core.RefereeMain.start(RefereeMain.java:69)
at com.codingame.gameengine.core.RefereeMain.main(RefereeMain.java:52)

I’ve got an problem too !
I don’t change the code (for Java language).

If I keep the initial result : System.out.println("C 0 0");, it works.
If I replace the result : System.out.println("J 0 0");, i have no result : screen result is all empty.
And if I do only System.out.println("J");, i’ve got an error

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1

Thx for your help !

Indeed, it is possible to solve the puzzle without taking care of water, but if you want to use the less possible water (in the general case, I have not check in the problem tests) you want to maximize the availability of remaining water to extinguish the next fires…

Reading through the other posts, I’m pretty sure it’s just a bug, but I figured I’d mention it - The default output command does not give a warning, however, when adding my own code I receive this - “Warning: your code did not read all available input before printing an instruction, your outputs will not be synchronized with the game’s turns and unexpected behaviour may occur.” My code was added inside of the while true loop and after the for loop where the fire’s x and y variables are initialized, so I’m fairly certain that all of the inputs have been read unless I am missing something, but like I said, after reading through the forum, I feel it is most likely a bug. So far it doesn’t seem to hinder my ability to properly solve this puzzle, it just caught me off guard.

The puzzle expects a single line of output per turn and it seems you’re outputting more than one line, hence desynchronizing the input and ouput in the later turns.