Coders Strike Back - Java Initialization

I am new to this site. I am currently writing code for my bot using Java. The instructions tell me that I have a variable named “thrust”. The snippet of pseudocode I received implies the variable is actually called “speed”. I can use the variable when printing, so I know it has been initialized. However, this particular variable does not show up among the others. (So far they are all ints named x, y, nextCheckpointX, nextCheckpointY, nextCheckpointDist, nextCheckpointAngle, opponentX, and opponentY.)

I added my own int called speed to the code since neither “speed” nor “thrust” work when trying to use the predefined variable. This doesn’t actually do anything to affect my bot’s speed. How can I figure out the name of the already-existing variable so I can solve this puzzle?

Thrust is set by the program that you’re going to write. You pass it to the server as an int, along with your desired angle, using console writes.

The server then calculates your new position (x, y) from the thrust and angle you gave it and passes it back to you with the other stuff. Then you figure out what your next thrust and angle should be and repeat.

1 Like

Thank you… this particular exercise takes most of the math out of the equation by granting variables that are already defined. nextCheckpointDist and nextCheckpoint Angle are variables that work as intended. They are predefined. Thrust does not work as intended. It is predefined, yet not present in my code. Thus, the name of this predefined variable (supposed to be thrust) is not present in my code. I can’t ignore it because the program is looking for thrust to be returned… I don’t have access to the classes from which the other variables are being called. Can you please elaborate on what you mean by “console writes”?

You have to write the declaration and determine the value for thrust in the code that you write. For example, in Java, you can just say

int thrust = 100;

If the print statement is looking for a variable called “thrust” it should find it and print 100.

I believe the default print statement in Java (for my league, yours might be different) is:

System.out.println("8000 4500 100");

The “100” is the default thrust. To print out your variable, you change it to:

System.out.println("8000 4500 " + thrust);

If you have also defined x and y you might use:

System.out.println(x + " " + y + " " + thrust);

When coding game runs your code, it will see your output of
8000 4500 100, and use that to calculate your next position. The game is setup as a loop, where at each step you get input data for your current position and you have to print out a line of
x y thrust
You define what to print in that System.out statement at the end of the loop.

1 Like

Thank you! I think I may be able to figure out what I’m doing wrong. I know it’s something simple, yet I can’t catch it. The print statement I have is this:

   System.out.println(nextCheckpointX + " " + nextCheckpointY + " 100");

Yet the instructions imply I actually need two print statements. But when I output two print statements, I get an error. I think it’s weird that the thrust portion of the print statement works for a string, yet all the declared variables are ints… Oh! I think I just figured it out by typing this response! Yes! Thank you!

Edit: I figured out the problem. 1) I needed spaces. 2) I was assuming thrust was predefined because it was working when I changed the string. Thrust was not predefined after all. I feel goofy.

To be fair with Tujae, the hint given by CG is particularly misleading. You’ll find below the french version. The hint should be corrected with replacing “speed” by “thrust” everywhere !

Un algorithme simple utilisant l’angle est celui-ci :

si nextCheckpointAngle > 90 or nextCheckpointAngle < -90 alors
speed = 0
speed = 100
fin si
afficher x y speed


Right, it all goes on one line, if you only have one pod. You have to decide what thrust to print with a variable.

You can change what X and Y you want to print out, too!

1 Like

Done, thank you.