Mad Pod Racing - Puzzle Discussion

Hi,
I wood be interested to see a PID controller example for this puzzle
For the wood league (with or without the boost feature)

Thank you for sharing.

There shouldn’t be any difference depending on the language. Unless you’re timing out some of the matches.

Between 19.11 and 20.03, there isn’t much difference. You could try to resubmit and check. Did you really implement the same algo?

1 Like

Nothing happen when use BOOST. This code I assume will trigger BOOST effect (got larger fire trail?) at least once.

while (true) {
    //default code here
    print(nextCheckpointX + ' ' + nextCheckpointY + ' '+'BOOST');
}

Since the question state that it I can only use once, so I expect will receive some kind of error, “you have use more than once”

BTW, here’s my full code

When there is no boost available, the BOOST is like using a max thrust.

1 Like

I’ve been trying to understand Magus’ simulator these past few days. It tracks the output pretty well but the impulse calculation seems weird. I’m gonna try a neural network so I want to clarify something before I generate millions of training data.

    float product = nx*dvx + ny*dvy;
    // fx and fy are missing a factor of 2?
    float fx = (nx * product) / (nxnysquare * mcoeff);
    float fy = (ny * product) / (nxnysquare * mcoeff);

    apply_impact_vector();

    float impulse = sqrt(fx*fx + fy*fy); // I think this is only a quarter of the true impulse
    if (impulse < 120.0) {
        fx = fx * 120.0 / impulse;
        fy = fy * 120.0 / impulse;
    }

    apply_impact_vector_again();

If the variable impulse is greater than the minimum of 120, this algorithm is the same as applying the impact vector once using the correct(?) impulse. The calculated coordinates after the collision are off by +/-1, I’m not sure if it’s a rounding error or the algorithm is incorrect. If it’s correct, can someone explain why the minimum is being checked against the quarter of the true impulse?

1 Like

Here’s my PID version. Works until collisions set in, then I haven’t tuned it further.

import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
boosted = False
checkpoints = []

accumerr = 0
lasterr = 0
P, I, D = 0.03, 0.00, 0.02
lasttarget = (0,0)

def distance(p1, p2):
    return math.sqrt( (p1[0]-p2[0])**2 + (p1[1]-p2[1])**2 )

# game loop
while True:
    # next_checkpoint_x: x position of the next check point
    # next_checkpoint_y: y position of the next check point
    # next_checkpoint_dist: distance to the next checkpoint
    # next_checkpoint_angle: angle between your pod orientation and the direction of the next checkpoint
    x, y, next_checkpoint_x, next_checkpoint_y, next_checkpoint_dist, next_checkpoint_angle = [int(i) for i in raw_input().split()]
    opponent_x, opponent_y = [int(i) for i in raw_input().split()]

    # Write an action using print
    # To debug: print >> sys.stderr, "Debug messages..."
    
    newpos = (x,y)
    target = (next_checkpoint_x, next_checkpoint_y)
    if target not in checkpoints:
        checkpoints.append(target)
    if target != lasttarget:
        lasttarget = target
        accumerr = 0
        lasterr = 0
    err = distance(newpos, target)
    accumerr += err
    errdiff = err - lasterr
    PID = (P*err + D*errdiff + I*accumerr)
    lasterr = err
    
    print >> sys.stderr, "P: " + str(P*err) + " I: " + str(I*accumerr) + " D: " + str(D*errdiff)
    print >> sys.stderr, "PID: " + str(PID)
    thrust = max(0, min(100, PID))

    if 60 <= abs(next_checkpoint_angle):
        thrust = 10
        print >> sys.stderr, "Angle big: " + str(next_checkpoint_angle)

    # You have to output the target position
    # followed by the power (0 <= thrust <= 100)
    # i.e.: "x y thrust"
    if not boosted and 10 >= abs(next_checkpoint_angle) and next_checkpoint_dist >= 6000:
        strthrust = "BOOST"
        boosted = True
    else:
        strthrust = str(int(thrust))
    
    print >> sys.stderr, "Thrust: " + strthrust
    print >> sys.stderr, "Checkpoints: " + str(checkpoints)
    print str(next_checkpoint_x) + " " + str(next_checkpoint_y) + " " + strthrust
3 Likes

well in Ruby :
pastebin com/DeHS92hP
and in go:
pastebin com/bqgtksh4
(need to modify the links cause of the limitation :confused: )
it’s just an If/else …

My concern is not between Ruby and JS, it’s between Go being very low compared to there others

Is there any way to look in to the tutorial part which I’ve already passed. I need the picture from tutorial that shows which angle is + and which is -. I need to know does it starts relatively from checkpoint (or bot) and which one is counted clockwise.

3 Likes

Can I have some help, my pod isn’t going forward. Or it’s not going straight forward when I change “thrust” in the print with for example “100”

import sys
import math

        thrust = 100
        # Auto-generated code below aims at helping you parse
        # the standard input according to the problem statement.


        # game loop
        while True:
            # next_checkpoint_x: x position of the next check point
            # next_checkpoint_y: y position of the next check point
            # next_checkpoint_dist: distance to the next checkpoint
            # next_checkpoint_angle: angle between your pod orientation and the direction of the next checkpoint
            x, y, next_checkpoint_x, next_checkpoint_y, next_checkpoint_dist, next_checkpoint_angle = [int(i) for i in input().split()]
            opponent_x, opponent_y = [int(i) for i in input().split()]

            # Write an action using print
            # To debug: print("Debug messages...", file=sys.stderr)


            # You have to output the target position
            # followed by the power (0 <= thrust <= 100)
            # i.e.: "x y thrust"
            print(str(next_checkpoint_x) + " " + str(next_checkpoint_y) + " " + thrust)

            if next_checkpoint_angle > 90 or next_checkpoint_angle < -90 and next_checkpoint_dist >= 6000:
                thrust = 0
            else:
                thrust = 100
            print(x, y, thrust)

Hi @JBM, I tried adding a text to the output line, but I get an error for invalid input. Shouldn’t it work like this: Console.WriteLine(X + " " + Y + " " + thrust + " " + text);

Edit: Already found the error. It’s not possible to include an empty space without an text following. You must have atleast one char behind the " ".

Is there a way to check the current Lap you’re in and your opponent is in? Or is there a way to check if you are in the leading position?

1 Like

Since they are not given in the inputs, you have to track them in your program.
Current lap: A pod completes a lap when it passes checkpoint 0. Count how many times that happens.
Leading position: Compare number of checkpoints passed and use distance to next checkpoint as a tiebreaker.

2 Likes

My code was crashing in the gold leage. I found out it was because of a received value -1 from readline for opponent pod next checkpoint id!? Easy fix, but still strange…

I’m more than sure it’s because you read input wrong.Copy your code somewhere and reset code in the IDE to get correct input reading.

I think you aren’t giving the correct output to the program. First of all, you are giving the input TWICE (you have two print statetemetns. Second of all, your second output is wrong; it is not a string, and most importantly, you are giving the pod’s location as it’s goal instead of the next checkpoint! And rembember, having a thrust of 0 can cause your pod to be unable to turn inside the 90 degrees barrier you have set.

I was working in the IDE right before I leveled up and it overwrote my previous good submission with uncompilable code. Now my score is tanking because it doesn’t compile. I can’t figure out how to edit a previous level’s code after leveling up. Any one know how to fix a previous level’s submission?

Hello,
I would like to report 2 things about Coders Strike Back

  1. It should be written somewhere that the next check point id of a dead opponent is -1!
    https://www.codingame.com/replay/157943234
    Agade die, then I die at the next lap (due to idCheckPoint for Agade equals -1). Which leads to equality.
    This issue seems to happen only when I am player 2.

  2. I think that I found a bug in codingame
    Here is an example of match:
    https://www.codingame.com/replay/157929038
    I have printed the input data at each turn, here is turn 7:
    Sortie d’erreur : (Player 1)
    0 : angle = 227.0 - x = 8359.0 - y = 6927.0 - vx = -215.0 - vy = -52.0
    1 : angle = 215.0 - x = 8951.0 - y = 6246.0 - vx = -81.0 - vy = -206.0
    2 : angle = 239.0 - x = 7860.0 - y = 7580.0 - vx = -209.0 - vy = -20.0
    3 : angle = 203.0 - x = 9538.0 - y = 5655.0 - vx = -49.0 - vy = -205.0
    Lap = 7

Sortie d’erreur : (Player 2)
0 : angle = 239.0 - x = 7860.0 - y = 7580.0 - vx = -209.0 - vy = -20.0
1 : angle = 203.0 - x = 9538.0 - y = 5655.0 - vx = -49.0 - vy = -205.0
2 : angle = 228.0 - x = 8359.0 - y = 6927.0 - vx = -215.0 - vy = -52.0
3 : angle = 214.0 - x = 8951.0 - y = 6246.0 - vx = -81.0 - vy = -206.0
Lap = 7

The angles provided for player 1 are different then the one provided for player 2 (obviously for the same turn/same pod). The issue seems to appear after the first collision.
I have checked, and it’s the player 2 that have the wrong data.
I don’t know if its specific to the language, but I am using Java :wink:

Thanks in advance for your feedback. This game is still awesome :wink:

1 Like

I can reproduce the 2), so I added it to the bug board. It will be fix as soon as possible. Thanks for the report.

1 Like

Thanks SaiksyApo :slight_smile:
You haven’t been able to reproduce the 1) ?
It only happens when player 1 timeout (not when player 2 timeout).

I am sorry in advance, but I think that I just find another bug… XD
I think there is something wrong in CG computations. (If I am right, I am really surprised to be the first one to highlight this)

3) Math error
I have tried to have something easy to reproduce the issue:
Options:
seed=807222711
pod_per_player=2
pod_timeout=100
map=3608 5206 13596 7597 12464 1358 10518 5956

Output loop 1
Player 1
86385 60997 100
91225 53679 100
Player 2
0 0 0
0 0 0

Ouput loop 2
Player 1
65373 83577 100
71779 78875 100
Player 2
0 0 0
0 0 0

ERROR FOUND!
Data provided by CG
Pod id = 1 - position (3723.0 5853.0) - speed (121.0 95.0) - angle = 47.0
Computed data
Pod id = 1 - position (3722.0 5853.0) - speed (120.0 96.0) - angle = 47.0

I have manually performed the math, and the error seems to be in your side.
x = 3580, y = 5740, vx = 74, vy = 40
Output : x = 71779 y = 78875 Trust = 100
New vx = 74 + 100 * cos(47.0002057) = 142.199573
New vy = 40 + 100 * cos(47.0002057) = 113.135615
New x = 3580 + 142.199573 = 3722.19957
New y = 5740 + 113.135615 = 5853.13561

End loop leads to:
x = Round(3722.19957) = 3722
y = Round(5853.13561) = 5853
vx = Trunc(142.199573 x 0.85) = 120
vy = Trunc(113.135615 x 0.85) = 96

If you want I can help for the debug :wink:

EDIT: Thanks PB, the issue is due to the angles! Angles are never rounded, the ones provided as input by CG are provided rounded (finally its like mars lander), to have the correct behaviour you have to keep the computed one :wink:

1 Like

The 1) is the default behavior in every puzzle. We may drop a line about it, but it’s not a bug.