Hey,
I’ve managed to complete the code for testcase 1, but I’m still struggling with scattered mountains. My ship gets destroyey at mountain 4.
import java.util.;
import java.io.;
import java.math.*;
/**
-
The while loop represents the game.
-
Each iteration represents a turn of the game
-
where you are given inputs (the heights of the mountains)
-
and where you have to print an output (the index of the mountain to fire on)
-
The inputs you are given are automatically updated according to your last actions.
**/
class Player {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int hmax = 0;
int imax = 0;
// game loop
while (true) {
for (int i = 0; i < 8; i++) {
int mountainH = in.nextInt(); // represents the height of one mountain.
if(mountainH > hmax) {
hmax = mountainH;
imax = i;
}
else if (mountainH < hmax) {
hmax++;
imax++;
}
System.out.println(imax);
}
// Write an action using System.out.println()
// To debug: System.err.println("Debug messages...");
}
}
}
Game information:
Let's destroy those mountains to secure our landing...
Height of mountain 0 : 9
Height of mountain 1 : 8
Height of mountain 2 : 7
Height of mountain 3 : 3
Height of mountain 4 : 6
Height of mountain 5 : 5
Height of mountain 6 : 2
Height of mountain 7 : 4
16
Standard Output Stream:
0
Game information:
Your spaceship targeted mountain 0, your altitude is now 9
Height of mountain 0 : 0
Height of mountain 1 : 8
Height of mountain 2 : 7
Height of mountain 3 : 3
Height of mountain 4 : 6
Height of mountain 5 : 5
Height of mountain 6 : 2
Height of mountain 7 : 4
26
Standard Output Stream:
1
Game information:
Your spaceship targeted mountain 1, your altitude is now 8
BOOOOMM!! Nice Shot!
Height of mountain 0 : 0
Height of mountain 1 : 0
Height of mountain 2 : 7
Height of mountain 3 : 3
Height of mountain 4 : 6
Height of mountain 5 : 5
Height of mountain 6 : 2
Height of mountain 7 : 4
36
Standard Output Stream:
2
Game information:
Your spaceship targeted mountain 2, your altitude is now 7
Height of mountain 0 : 0
Height of mountain 1 : 0
Height of mountain 2 : 0
Height of mountain 3 : 3
Height of mountain 4 : 6
Height of mountain 5 : 5
Height of mountain 6 : 2
Height of mountain 7 : 4
46
Standard Output Stream:
3
Game information:
Your spaceship targeted mountain 3, your altitude is now 6
Height of mountain 0 : 0
Height of mountain 1 : 0
Height of mountain 2 : 0
Height of mountain 3 : 0
Height of mountain 4 : 6
Height of mountain 5 : 5
Height of mountain 6 : 2
Height of mountain 7 : 4
56
Standard Output Stream:
4
Game information:
You crashed your spaceship on mountain 4
Height of mountain 0 : 0
Height of mountain 1 : 0
Height of mountain 2 : 0
Height of mountain 3 : 0
Height of mountain 4 : 6
Height of mountain 5 : 5
Height of mountain 6 : 2
Height of mountain 7 : 4
If someone could help me, I would be really appreciate it.