Don't Panic - Episode 1 - Puzzle discussion

alright ill try some of those out not exactly sure how to do it but ill probably figure something out

Itā€™s missing some tags, like arrays and loops. I donā€™t think you can solve this without checking where the elevator is and for that you need an array, datatable or sth.

Iā€™m stuck on the first part.
When I put ā€˜LEFTā€™ or ā€˜RIGHTā€™ in output, I get the message "invalid input. Expected ā€˜WAIT, BLOCKā€™ but found ā€˜LEFTā€™ ". But if I put ā€˜WAIT, BLOCKā€™, I get "invalid input. Expected ā€˜WAIT, BLOCKā€™ but found ā€˜WAIT, BLOCKā€™ ". And if I put ā€˜WAITā€™ or ā€˜BLOCKā€™ the time all the clones come out, I lose. So what do you have to do to give a direction to the clones ? :frowning_face:

You should output either ā€œWAITā€ or ā€œBLOCKā€ in each turn. You do not output the same command for all turns. For example, you BLOCK the first clone to prevent future clones from moving right. Then you output WAIT for the rest of the game because all clones are moving in the correct direction.

Hi,

Can someone give me a hand with this please ?
I dont know why but, my code wont work properly. When it should ā€œblockā€ it wont even if my ā€œifā€ is true.
Here is my code, I know itā€™s not clean and optimized but I think it should workā€¦ I think :sweat_smile:

class Player {

public static void main(String args[]) {

    Scanner in = new Scanner(System.in);

    int nbFloors = in.nextInt(); // number of floors

    int width = in.nextInt(); // width of the area

    int nbRounds = in.nextInt(); // maximum number of rounds

    int exitFloor = in.nextInt(); // floor on which the exit is found

    int exitPos = in.nextInt(); // position of the exit on its floor

    int nbTotalClones = in.nextInt(); // number of generated clones

    int nbAdditionalElevators = in.nextInt(); // ignore (always zero)

    int nbElevators = in.nextInt(); // number of elevators

    int[] refAsc = new int[nbElevators + 1]; // an array to save the exit and elevator position

    for (int i = 0; i < nbElevators; i++) {

        int elevatorFloor = in.nextInt(); // floor on which this elevator is found

        int elevatorPos = in.nextInt(); // position of the elevator on its floor

        refAsc[elevatorFloor]=elevatorPos;

    }

     System.err.println(nbElevators+ "nb elev");

    System.err.println(Arrays.toString(refAsc));

    int deplacement = 1;

    int cible = exitPos;

    int distanceT0; // distance at T=0

    int distanceT1; // distance after the "move"

    refAsc[exitFloor]=exitPos;

    // game loop

    while (true) {

        int cloneFloor = in.nextInt(); // floor of the leading clone

        int clonePos = in.nextInt(); // position of the leading clone on its floor

        String direction = in.next(); // direction of the leading clone: LEFT or RIGHT

        System.err.println(cloneFloor + " clonefloor");

        if (direction.contains("R")){ // give an num valeur in fonction of the direction

            deplacement = 1;

        } else if (direction.contains("L")){

            deplacement = -1;

        }

        System.err.println(deplacement + " deplacement");

        if (cloneFloor >=0 ){

            cible = refAsc[cloneFloor];

        } else {

            System.out.println("WAIT");

        }

        distanceT0 = Math.abs(cible - clonePos);            

        distanceT1 = Math.abs(cible - (clonePos + deplacement));

        System.err.println(cible + " cible");

        System.err.println(clonePos + " position clone");

        System.err.println(deplacement + " depl");

        System.err.println(distanceT0 + " dist0");

        System.err.println(distanceT1 + " dist1");

        System.err.println(cible + " cible");

        if (distanceT0 == distanceT1){

            System.out.println("WAIT");

        }

        else if (distanceT0 < distanceT1) {

            System.err.println(" if of block");

            System.out.println("BLOCK");

        } else {

            System.err.println(" le w8");

            System.out.println("WAIT");

        }

        // Write an action using System.out.println()

        // To debug: System.err.println("Debug messages...");

        System.out.println("WAIT"); // action: WAIT or BLOCK

    }

}

}

The problem is at this stage:
else if (distanceT0 < distanceT1) {
System.err.println(" if of block");
System.out.println(ā€œBLOCKā€);

It work on the first lvl but it goes wrong at the third lvl

Respectfully Einsenhorm,

It would help to debug if you read your code and walk through it manually :wink:

You should notice that you have Sytem.out.println in a few places: within the first if-block, within the second if-block, and outside the said if-blocks. In a single while-loop (i.e. a single turn), youā€™re supposed to output once only. But your code outputs more than one command in a single turn, so, the game engine treats them as commands for several turns, and the logic as a result goes out of sync with your original intention.

Thanks, I will change that and try with only one out.println.

UPDATE :
Well Iā€™ve change the out.println into only one but the probleme is still the same.

error exits :

1 clonefloor
1 deplacement
1 cible
7 position clone
1 depl
6 distanceT0
7 distanceT1
1 cible
le w8

Standard exit:

WAIT

Informations :

You do nothing.
My if condition to give a ā€œBLOCKā€ is :

else if (distanceT0 < distanceT1) {
System.err.println(" if of block");
System.out.println(ā€œBLOCKā€);

So normaly it should be true, as you can see above : 6 distanceT0 and 7 distanceT1
6 < 7 = true normaly but, in this case it seem not . . .

You may PM me your code so that I can check and discuss with you further in private.

Quite sure I understand the game but i checked with the debug options and it is not synchronised the values that are taken from input with the game.

I got the ā€œ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.ā€ but i do not understand. I use the variables I need and the logic is quite simple.

Any idea of how to synchonised and avoid the warning?

The message means your code has either output too many lines or skipped output before reading the new roundā€™s inputs. You are suggested to use the error stream to keep track of when you read new inputs and when you write outputs.

1 Like

It seems Iā€™m not allowed to send you a PM "^^.

Iā€™ve sent you a PM. You may continue from there :slight_smile:

Continuing the discussion from Don't Panic - Episode 1 - Puzzle discussion:

Already solved it. Finally, it was too may output lines.

I see strange behaviour: in IDE all tests are passed but in submitting validation step last test - ā€œSpaced elevators, few roundsā€ - is failed, and when I watch the animation of failing test I notice that leading clone does reach elevator at (last-1) floor but does not appear on last floor with exit - instead it becomes blocked.

Could you share your replay link here?

hi good morning, im hving issues with the code, i got the first 5th rounds but th 6th and the7th shows this erros message ā€œMax rounds count reachedā€ and i used this code
int tope = width-1;

        int cero = width - tope;

       if (clonePos < tope && clonePos >= cero )

       {

         Console.WriteLine("WAIT");

       }

       else

       {

        Console.WriteLine("BLOCK");

       }

can anyone help me :

Could you please specify which test case you are talking about, and share a link to the replay?

the las 2 of them.
few rounds
spaced elevators few rounds

This is replay from IDE - Coding Games and Programming Challenges to Code Better

This is replay from Submit - Coding Games and Programming Challenges to Code Better

1 Like

Sorry, I was confused because you talked about ā€œroundsā€ not ā€œcasesā€.

Could you please share the replay links?