The accountant. Variable is 4 but "SHOOT " + variable gives me SHOOT 5

These are the last two lines in my code.

Console.Error.WriteLine("Current target: " + target);
Console.WriteLine("SHOOT " + target); // MOVE x y or SHOOT id

The code works until test case 8 where i get this:

Current target: 4
Standard Output Stream:
SHOOT 5
Game information:
You attempted to shoot a non-existent target.

Why is it shooting at 5 when the variable target clearly is 4?

You’re not alone. I’m having the same issue in Python 2. It’s the same variable 1 line apart but standard out prints the integer 1 higher.

Standard Error Stream:
Shooting closest 1 Health is 42
Continuing loop
Standard Output Stream:
SHOOT 2
Game information:
You attempted to shoot a non-existent target.

Code:
print >> sys.stderr, “Shooting closest”, tgt , " Health is", closest_to_wolff[3]
print “SHOOT”, int(tgt)

Ok, I fixed the issue in my code.

Hopefully this can help you, but I missed a continue statement earlier so I printed SHOOT/MOVE twice in a turn. It looks like the validator queues the extra print and applies it on the next turn.

2 Likes

Double output in a loop has killed me many times.