“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.” when I run my code. My code obviously didn’t read all the inputs before printing the output, but I’m pretty sure I didn’t tinker with any of the input codes for this to be happening.
Does someone have an idea why this warning pops up and how to fix it??
The codes I wrote are between the comments:
“// ** My code:” and
“// ** My code; end!”
Everything else are initial skeleton codes
class Player {
static void Main(string[] args) {
string[] inputs;
inputs = Console.ReadLine().Split(' ');
int W = int.Parse(inputs[0]); // width of the building.
int H = int.Parse(inputs[1]); // height of the building.
int N = int.Parse(Console.ReadLine()); // maximum number of turns before game over.
inputs = Console.ReadLine().Split(' ');
int X0 = int.Parse(inputs[0]);
int Y0 = int.Parse(inputs[1]);
// ** My code:
int batmanX = X0;
int batmanY = Y0; // Batman's current X & Y position.
int[,] building = new int[H,W];
int jumpsRemaining = N;
int heightFloor = H - 1;
int heightRoof = 0;
int widthLeft = 0;
int widthRight = W - 1; // ** My code; end!
// game loop
while (true) {
string bombDir = Console.ReadLine(); // the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)
// Write an action using Console.WriteLine()
// To debug: Console.Error.WriteLine("Debug messages...");
// ** My code:
for (int n = 0; n < jumpsRemaining; ++n) {
int midX, midY; // The midpoint of batman's next X- & Y-pos.
if (bombDir.Contains("U")) { // If "Up" is in the direction,
heightFloor = batmanY - 1; //
midY = (heightFloor + heightRoof) / 2;
batmanY = midY;
}
if (bombDir.Contains("D")) { // If "Down" is in the direction
heightRoof = batmanY + 1;
midY = (heightFloor + heightRoof) / 2;
batmanY = midY;
}
if (bombDir.Contains("R")) { // If "Right" is in the direction
widthLeft = batmanX + 1;
midX = (widthLeft + widthRight) / 2;
batmanX = midX;
}
if (bombDir.Contains("L")) { // If "Left" is in the direction
widthRight = batmanX - 1;
midX = (widthLeft + widthRight) / 2;
batmanX = midX;
}
/*for (int i = heightFloor; i >= heightRoof; --i) { // Height
for (int j = widthLeft; j <= widthRight; ++j) { // Width
}
}*/
Console.WriteLine(batmanX + " " + batmanY);
}
// ** My code; end!
// the location of the next window Batman should jump to.
//Console.WriteLine("0 0");
}
}
}
You use Console.WriteLine in the for-loop. So you print several times a command in one round. You have to put the Write-Command after the for-loop to avoid that problem.
@ItsAFeature is right. Furthermore it seems that you’re trying to use your for loop to represent the game turns, but the while loop around already have this purpose. To say it differently, you are trying to play the whole game in a single game turn.
Hi there,
I come here telling you that I’ve a problem with the “Less jump” validate.
For any reason, my batman just stuck in front of the bomb looking at it real hard.
I assume that he is affraid but it’s probably my code that suck.
I’ve successed of all other stages but this one make me have headaches.
If somoene wanna help me I’ll be thankfull.
Is anyone having time problem with “Not There?”. Also, if I try to printing the input value the timeout error happens before i can print anything which makes me think that the problem is not the code itself.
I am working with python and np arrays. Each iteration I choose a position based only on the possible locations left and not the whole width/length.
The only thing i managed to print out is the Width, the Height and the Number of jumps. everything that comes after seems to be unprintable because of timeout error
Hi everyone! I’ve got an issue on the last episode n°07.
I go in one move from round 14 to 12, and then stops, You loose with 12 rounds left on screen…
Any idea?
Here’s my code bellow
import sys
import math
# w: width of the building.
# h: height of the building.
w, h = [int(i) for i in input().split()]
n = int(input()) # maximum number of turns before game over.
x0, y0 = [int(i) for i in input().split()]
x_zone = [i for i in range(w)] # active zone w
y_zone = [i for i in range(h)] # active zone h
while True:
bomb_dir = input() # the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)
directions = {'U' : [y0,h], 'D' : [0,y0], 'R' : [0,x0], 'L' : [x0,w]} # forms : zone to substract f° to direction
for i in bomb_dir:
di = directions[i]
retrait = [n for n in range(di[0], di[1]+1)] # zone to substract
if i in ('U','D'): # if Up or Down
y_zone = [n for n in y_zone if n not in retrait]
elif i in ('R','L'): # if Right or Left
x_zone = [n for n in x_zone if n not in retrait]
x0 = sum(x_zone)//len(x_zone)
y0 = sum(y_zone)//len(y_zone)
print(x0,y0)
If I understand your code correctly, you are storing all possible X and all possible Y positions in the lists x_zone and y_zone. Then you jump to the middle of all positions.
The problem is, your program is working too inefficiently. The last testcase with a large number of possible positions took too long to process and recreate the lists.
You should think about a more efficient way of displaying the possible positions for the bomb.
A little tip: If you activate the debug mode you will always see all windows colored blue that might still contain the bomb with your information. This will make it easier for you to see what shape the rest of the windows are taking.