Kirk's Quest - The Descent - puzzle discussion (old)

Great help, thanks

Hello,
I wrote the code in C. All test cases passed successfully. When I submit then on the game play it says ā€œMission Completedā€. But at the bottom it highlights the last test case in RED. On Screen I get the message saying ā€œReplay the game to find errorsā€. And I replayed like 20 times and it is perfect. Even in game play it destroys all the mountains that too in correct sequence and flashes ā€œMission Completedā€ as well. But it scores me only 83%. Any ideas.

ā€œI am talking about the Result screen. On the IDE panel all test cases passed no issues. But its when I click on submit and on the Result pageā€.

Thanks

The result page doesnā€™t show you the failing testcase by default. You have to select it. The bullet points on the result page are actually play buttons.

For every turn you are given 3 information
-spaceX CURRENT POSITION
-spaceY CURRENT HEIGHT
-array of all the height of mountains.(from mountain 1 to mountain 8)

just find the position of the mountain having max height and
fire when ship is at that position.

Am I wrong, or is this completely broken in Haskell? All getLine will return is the non-zero mountain heights.

Example being the first test:
First use of getLine returns the ship position as expected.
Second use gets you 9, and that is it. There is no relative information about the actual location of the mountain.

Ok, I actually donā€™t know what to do. I read the same problem, but it didā€™nt help. When I do the first ā€œFIREā€ above the mountain it goes wrong and the next ā€œFIREā€ is making on spot near the mountain.
if(mountainH[i]>max){
max=mountainH[i];
loc=i;}
}

 if( spaceX==loc )
it fire. 
Without else statement cause the programm don't work.

The if statement at the end is not working properly but the logic is solidā€¦ The cerr gives me the right values, but for some reason the if statement is being wrongly called.

EDIT CODE

Got it working with this solution (but its odd, because the logic is the same):
EDIT CODE

You are confusing = and ==. The first is an assignment. The second is a boolean comparison.

You are right! I got myself confused there! Thanks

Even I Face the same issueā€¦ this might be because, the ship moves from right to left in the return tripā€¦ that is from 7 to 6 toā€¦ and so on to 1ā€¦ I think this has to be taken care of. I also doubt, If the game has bug!

I really have absolutely no idea how to go about starting this. Iā€™m only just starting to learn JavaScript (have done the Codecademy stuff and that is it). Are these challenges more people with a bit more experience than me? Or am I just not seeing something?
I canā€™t figure out where each mountain height is stored. Also, do you just have to add to the code that is there, or can you delete some of it? Iā€™m really lost here, any help would be great.
Thanks.

You can do anything you want to the autogenerated code. The only thing that matters is the output to standard-out your code produces.

If you donā€™t know where to start try to formulate an algorithm with words, that would tell you every turn which command (either ā€œFIREā€ or ā€œHOLDā€) to use.

Did Codecademy tell you something about the loops and the variables?

There is a loop that looks like this:

for (var i = 0; i < 8; i++) {
    var mountainH = parseInt(readline()); // represents the height of one mountain, from 9 to 0. Mountain heights are provided from left to right.
}

In the first iteration i will have the value 0 and mountainH will contain the hight of the first mountain. In the second iteration i will have the value 1 and mountainH will contain the hight of the second mountain. You get the picture.

I donā€™t understand what does this code :

for i in range(8):
    mountain_h = int(input())

please

The machine gives values, eight of them are stored in mountain_h. Of course, this code will store only the last one, the previous ones are crushed. Your work consist in storing all the eight values in mountain_h (which canā€™t be a simple integer).

i have the following code:

Ā Ā Ā  while (1) {
Ā Ā Ā Ā Ā Ā Ā  int spaceX;
Ā Ā Ā Ā Ā Ā Ā  int spaceY;
Ā Ā Ā Ā Ā Ā Ā  cin >> spaceX >> spaceY;
        cin.ignore();
        cerr << spaceX << endl;
        cout << "HOLD" << endl;
}

sometimes the cerr line appears in the log several times and sometimes not even once. What am i doing wrong?

Found the bug.
You must execute the for loop that reads the mountains in every turn.

This maybe a dumb question but how to get the ship to make decision which mountain to fire at???

am using VB for this

When its x-coordinate is the x-coordinate of the highest mountain?

the question is how to make it search to get the location of highest mountain