https://www.codingame.com/training/medium/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.
https://www.codingame.com/training/medium/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.
Fixed.
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).
Thanks, now it works.
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)
Can you share the outputs of your bot to reproduce the crash?
Edit:
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.
I can pass all IDE tests, but not with the same code
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
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
Congratulations on not having hard coded . 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;
}
Preparation:
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
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
Blockquote
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.