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

Feel free to send your feedback or ask some help here!

WARNING: The rules of this game have been changed on the 3rd of March 2016.

5 Likes

Wrote some code that runs correctly as a test singly and in batch, but when submitting it shows entirely diffrerent behavior and insists I do not meet the objective for the single shot per mountain test.

you have to shot the tallest mountain each time to make it work.

  • You need to be careful about the X coordinate to not be wrong.

At last, as a general advice, tests performed at submit time are different (slightly) than tests at coding time.

I donā€™t think this input for this game is correct? Or possibly the way you output the strings in the game view on the left?

import sys, math

Ā Ā Ā  # game loop
Ā Ā Ā  while 1:
Ā Ā  Ā 
Ā Ā Ā  SX, SY = [int(i) for i in input().split()]
Ā Ā Ā  print(SX, SY, file=sys.stderr)
Ā Ā Ā  for i in range(8):
Ā Ā Ā Ā Ā Ā Ā  MH = int(input())
Ā Ā Ā Ā Ā Ā Ā  print(MH, file=sys.stderr)
Ā Ā  Ā 
Ā Ā Ā  print("HOLD")

I see:

"Let's destroy those mountains to secure our landing..."
stderr: 0 10  (+ mountain ranges)

Your spaceship is over mountain 0, your altitude is 10
stderr: 1 10Ā  (+ mountain ranges)

Your spaceship is over mountain 1, your altitude is 10
stderr: 2 10Ā  (+ mountain ranges)

Your spaceship is over mountain 2, your altitude is 10
stderr: 3 10Ā  (+ mountain ranges)

...

Your spaceship is over mountain 6, your altitude is 10
7 10

Your spaceship is over mountain 7, your altitude is 10
7 9

Your spaceship is over mountain 7, your altitude is 9
6 9

...

Your spaceship is over mountain 4, your altitude is 9
3 9

You crashed your spaceship on mountain 3

This isnā€™t that much of a problem, but the text does state:

You can only fire once per passĀ on the mountainĀ located directly below the starship.Ā Firing on a mountain base will only destroy part of it and it will sink a random number of kilometers.

(emph in original)

1 Like

Ok this is frustrating me to no end.
Iā€™m on test case two.
this is an example of whatā€™s in my code:

print >> sys.stderr, X == Y
if X == Y:
   print Statement

and on the output console I see:
False
Statement

(WHAT!?)

any help, explaination, or ideas would be welcome?

I dunno why you have this error but your condition is odd, isnā€™t it?

How is it ā€œoddā€? Iā€™m afraid your comment is a little vague. Purposely so I assume but it hasnā€™t helped me. So Iā€™ll try to explain my situation differently. I hope that if I describe my method for a solution here it wonā€™t give any one information they donā€™t want, and if so they should stop reading here. What Iā€™m trying to do is find the biggest mountian and when the ship is over it telling it to fire and hold otherwise. In my code I check to see if the ship is currently over the largest mountain and then tell it to fire. However for some reason after the first shot, which is always correct on every test case, the ship then proceeds to mis-fire. Some times it holds when the conditions for firing are met sometimes it fires when the conditions for firing are not met and sometimes it fires more than once in the same 8 game turns.

1 Like

Sorry, i didnā€™t mean to confuse you.

I remember that this puzzle is a little tricky, not to choose which mountain to shoot, but to update the position of the ship correctly, search in that direction :wink:

Iā€™ve gotten it to work. I found the assumption that wasnā€™t true. In my code there was this situation.

if (condition):
      print fire
print hold

the problem was that sometimes even though the condition was true my ship was still holding
I fixed it like this:

if (condition):
    print fire
else:
    print hold

the assumption that was incorrect was that for the purpose of these games I was using the print() as a return() and that after the the program encountered itā€™s first print() it stopped running it. However that wasnā€™t the case so after the first time ā€˜fireā€™ and ā€˜holdā€™ were printed my ship became more and more out of sync with the game state. Thus throwing off future shots and causing me to fail.

3 Likes

Great answer, thans this helped me too, I guess the problem in my and your code was that we was printing 2 echo statements for single position this why next points was moved by each of those double echo.

Can anyone tell me how to get the mountain height of the place where the ship currently is? Iā€™m a total programming noob, so Iā€™d love some advice/feedback!

Oh, I should mention, Iā€™m doing this in Javascript.

if (condition):
    print fire
print hold

(I canā€™t quote code, thatā€™s annoying ^^) so thanks, i forgot to put that kind of common mistake in the FAQ section. Itā€™ll be there soon
EDIT: I didnā€™t forget, but i wasnā€™t explicit, so now itā€™s fixed :slight_smile:

Frequently asked questions

If you get the 8 moutain height + X position of the ship, then the mountain under the ship is at mountain_height[X]. Now it is your duty to find a way to stock mountain height, but it shouldnā€™t be a problem.

Read the problem again and Iā€™m sure youā€™ll find the answer :wink:

So are you saying that MH returns an array? That was not clear to me. Perhaps this is a hint to whoever can edit the puzzle! Anyway, thanks!

Nope, but you could stock each MH in an array, yes :wink:

2 Likes

Basic challenge, finished it with Java. Good practice, hardest part for me is always understanding the initial problem.

1 Like

this was annoying. made same error. great catch

I got half of the half of the problems done with :
if mh != 0 :
print fire
else
print hold

Canā€™t understand how to make the other half work.

I did the first two ā€œgamesā€ easily without a problem. However, I do not understand this one and have become rather frustrated. I donā€™t understand this concept of a ā€œgame turnā€ and what exactly that means. Do I try to set up actions for the ship within the for loop? Or is every ā€œgame turnā€ one iteration of the while loop? I also dislike that I canā€™t see what my values for SX and SY are as I update them, so thereā€™s no way to tell if that is what is causing the issues. It would make things a lot simpler if there were some way to more directly interact with the results of my code.

5 Likes

A turn is a full iteration of the while loop. Every turn you will get a reading of the map first, You need to shoot rhe tallest one every turn, if that helps.
Use System.err.println{"SX: " + SX);

to see your values in real time.

MHā€™s value changes because of the while loop. MH will change ten times as it reads each mountain height of the map each turn.
Try using the System.err.println to see how your code is changing.