Mad Pod Racing - Puzzle Discussion

so i have a mammoth of a code and still cant get out of silver…

using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

/**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 **/
class Player
{
    static void Main(string[] args)
    {
        string[] inputs;

        int b = 100;
        int boost1 = 0;
        int boost2 = 0;

        int C1X = 0;
        int C2X = 0;
        int C3X = 0;
        int C4X = 0;
        int C5X = 0;
        int C6X = 0;
        int C7X = 0;
        int C8X = 0;
        int C9X = 0;
        int C10X = 0;

        int C1Y = 0;
        int C2Y = 0;
        int C3Y = 0;
        int C4Y = 0;
        int C5Y = 0;
        int C6Y = 0;
        int C7Y = 0;
        int C8Y = 0;
        int C9Y = 0;
        int C10Y = 0;

        int checkpoints = 0;
        string nextcheckpoint = "";
        bool checkpointhaschanged = false;
        bool assignedcheckpoint = false;
        bool allcheckpointsfound = false;
        int lastcheckpointx = 0;
        int lastcheckpointy = 0;
        double checkpointangle = 0;
        float cpanglepercentage = 0;
        int overnextcpx = 0;
        int overnextcpy = 0;

        int turndist = 0;

        int boost = 1;
        bool usedboost = false;

        int wasx = 600;
        int wasy = 200;
        double wasa = 90;
        int startup = 5;

        // game loop
        while (true)
        {
            inputs = Console.ReadLine().Split(' ');
            int x = int.Parse(inputs[0]);
            int y = int.Parse(inputs[1]);
            int ncx = int.Parse(inputs[2]); // x position of the next check point
            int ncy = int.Parse(inputs[3]); // y position of the next check point
            int ncd = int.Parse(inputs[4]); // distance to the next checkpoint
            int nca = int.Parse(inputs[5]); // angle between your pod orientation and the direction of the next checkpoint
            inputs = Console.ReadLine().Split(' ');
            int opx = int.Parse(inputs[0]);
            int opy = int.Parse(inputs[1]);

            b = 100;
            checkpointhaschanged = false;
            assignedcheckpoint = false;
            bool usedability = false;

            if (nextcheckpoint != (ncx+" "+ncy)){
                nextcheckpoint = ncx+" "+ncy;
                checkpointhaschanged = true;
                if (ncx == C1X && ncy == C1Y){
                    allcheckpointsfound = true;
                }
            }

            if (checkpointhaschanged == true){
                if (ncx != C1X && ncy != C1Y && allcheckpointsfound == false){
                    if (C1X == 0 && C1Y == 0){
                        checkpoints = 1;
                        C1X = ncx;
                        C1Y = ncy;
                        assignedcheckpoint = true;
                        
                    }
                    if (assignedcheckpoint==false && C2X == 0 && C2Y == 0){
                        checkpoints = 2;
                        C2X = ncx;
                        C2Y = ncy;
                        assignedcheckpoint = true;
                        
                    }
                    if (assignedcheckpoint==false && C3X == 0 && C3Y == 0){
                        checkpoints = 3;
                        C3X = ncx;
                        C3Y = ncy;
                        assignedcheckpoint = true;
                        
                    }
                    if (assignedcheckpoint==false && C4X == 0 && C4Y == 0){
                        checkpoints = 4;
                        C4X = ncx;
                        C4Y = ncy;
                        assignedcheckpoint = true;
                        
                    }
                    if (assignedcheckpoint==false && C5X == 0 && C5Y == 0){
                        checkpoints = 5;
                        C5X = ncx;
                        C5Y = ncy;
                        assignedcheckpoint = true;
                        
                    }
                    if (assignedcheckpoint==false && C6X == 0 && C6Y == 0){
                        checkpoints = 6;
                        C6X = ncx;
                        C6Y = ncy;
                        assignedcheckpoint = true;
                        
                    }
                    if (assignedcheckpoint==false && C7X == 0 && C7Y == 0){
                        checkpoints = 7;
                        C7X = ncx;
                        C7Y = ncy;
                        assignedcheckpoint = true;
                        
                    }
                    if (assignedcheckpoint==false && C8X == 0 && C8Y == 0){
                        checkpoints = 8;
                        C8X = ncx;
                        C8Y = ncy;
                        assignedcheckpoint = true;
                        
                    }
                    if (assignedcheckpoint==false && C9X == 0 && C9Y == 0){
                        checkpoints = 9;
                        C9X = ncx;
                        C9Y = ncy;
                        assignedcheckpoint = true;
                        
                    }
                    if (assignedcheckpoint==false && C10X == 0 && C10Y == 0){
                        checkpoints = 10;
                        C10X = ncx;
                        C10Y = ncy;
                        
                    }
                }
            }
            //------------------------------------------------------------------------------
            if (allcheckpointsfound == true){
                if (ncx == C1X && ncy == C1Y && checkpoints >= 1){
                    if (checkpoints == 2){
                        lastcheckpointx = C2X;
                        lastcheckpointy = C2Y;
                    }
                    if (checkpoints == 3){
                        lastcheckpointx = C3X;
                        lastcheckpointy = C3Y;
                    }
                    if (checkpoints == 4){
                        lastcheckpointx = C4X;
                        lastcheckpointy = C4Y;
                    }
                    if (checkpoints == 5){
                        lastcheckpointx = C5X;
                        lastcheckpointy = C5Y;
                    }
                    if (checkpoints == 6){
                        lastcheckpointx = C6X;
                        lastcheckpointy = C6Y;
                    }
                    if (checkpoints == 7){
                        lastcheckpointx = C7X;
                        lastcheckpointy = C7Y;
                    }
                    if (checkpoints == 8){
                        lastcheckpointx = C8X;
                        lastcheckpointy = C8Y;
                    }
                    if (checkpoints == 9){
                        lastcheckpointx = C9X;
                        lastcheckpointy = C9Y;
                    }
                    if (checkpoints == 10){
                        lastcheckpointx = C10X;
                        lastcheckpointy = C10Y;
                    }
                }
                if (ncx == C2X && ncy == C2Y && checkpoints >= 2){
                    lastcheckpointx = C1X;
                    lastcheckpointy = C1Y;
                }
                if (ncx == C3X && ncy == C3Y && checkpoints >= 3){
                    lastcheckpointx = C2X;
                    lastcheckpointy = C2Y;
                }
                if (ncx == C4X && ncy == C4Y && checkpoints >= 4){
                    lastcheckpointx = C3X;
                    lastcheckpointy = C3Y;
                }
                if (ncx == C5X && ncy == C5Y && checkpoints >= 5){
                    lastcheckpointx = C4X;
                    lastcheckpointy = C4Y;
                }
                if (ncx == C6X && ncy == C6Y && checkpoints >= 6){
                    lastcheckpointx = C5X;
                    lastcheckpointy = C5Y;
                }
                if (ncx == C7X && ncy == C7Y && checkpoints >= 7){
                    lastcheckpointx = C6X;
                    lastcheckpointy = C6Y;
                }
                if (ncx == C8X && ncy == C8Y && checkpoints >= 8){
                    lastcheckpointx = C7X;
                    lastcheckpointy = C7Y;
                }
                if (ncx == C9X && ncy == C9Y && checkpoints >= 9){
                    lastcheckpointx = C8X;
                    lastcheckpointy = C8Y;
                }
                if (ncx == C10X && ncy == C10Y && checkpoints >= 10){
                    lastcheckpointx = C9X;
                    lastcheckpointy = C9Y;
                }
                if (ncx == C1X && ncy == C1Y && checkpoints > 1){
                    overnextcpx = C2X;
                    overnextcpy = C2Y;
                }
                else if (ncx == C2X && ncy == C2Y && checkpoints > 2){
                    overnextcpx = C3X;
                    overnextcpy = C3Y;
                }
                else if (ncx == C3X && ncy == C3Y && checkpoints > 3){
                    overnextcpx = C4X;
                    overnextcpy = C4Y;
                }
                else if (ncx == C4X && ncy == C4Y && checkpoints > 4){
                    overnextcpx = C5X;
                    overnextcpy = C5Y;
                }
                else if (ncx == C5X && ncy == C5Y && checkpoints > 5){
                    overnextcpx = C6X;
                    overnextcpy = C6Y;
                }
                else if (ncx == C6X && ncy == C6Y && checkpoints > 6){
                    overnextcpx = C7X;
                    overnextcpy = C7Y;
                }
                else if (ncx == C7X && ncy == C7Y && checkpoints > 7){
                    overnextcpx = C8X;
                    overnextcpy = C8Y;
                }
                else if (ncx == C8X && ncy == C8Y && checkpoints > 8){
                    overnextcpx = C9X;
                    overnextcpy = C9Y;
                }
                else if (ncx == C9X && ncy == C9Y && checkpoints > 9){
                    overnextcpx = C10X;
                    overnextcpy = C10Y;
                }
                else{
                    overnextcpx = C1X;
                    overnextcpy = C1Y;
                }
                if (ncx == C10X && ncy == C10Y){
                    overnextcpx = C1X;
                    overnextcpy = C1Y;
                }

                double dif1to2x = x - ncx;
                if (dif1to2x<0) {dif1to2x = dif1to2x * -1;}

                double dif1to2y = y - ncy;
                if (dif1to2y<0) {dif1to2y = dif1to2y * -1;}

                double leng1to2 = Math.Sqrt((dif1to2x*dif1to2x)+(dif1to2y*dif1to2y));

                double dif1to3x = x - overnextcpx;
                if (dif1to3x<0) {dif1to3x = dif1to3x * -1;}

                double dif1to3y = y - overnextcpy;
                if (dif1to3y<0) {dif1to3y = dif1to3y * -1;}

                double leng1to3 = Math.Sqrt((dif1to3x*dif1to3x)+(dif1to3y*dif1to3y));

                double dif2to3x = ncx - overnextcpx;
                if (dif2to3x<0) {dif2to3x = dif2to3x * -1;}

                double dif2to3y = ncy - overnextcpy;
                if (dif2to3y<0) {dif2to3y = dif2to3y * -1;}

                double leng2to3 = Math.Sqrt((dif2to3x*dif2to3x)+(dif2to3y*dif2to3y));

                double a1 = 0-((leng1to3*leng1to3)/(2*leng2to3*leng1to2));
                double a2 = (leng2to3/(2*leng1to2));
                double a3 = (leng1to2/(2*leng2to3));

                checkpointangle = Math.Acos(a1+a2+a3);

                if (checkpointangle > 180){
                    checkpointangle = 180-(checkpointangle-180);
                }
                cpanglepercentage = (float)(checkpointangle/1.8);
                Console.Error.WriteLine("checkpointangle= "+((int)(checkpointangle*100)).ToString());
                Console.Error.WriteLine("cpanglepercentage= "+((int)(cpanglepercentage*100)).ToString());
                dif1to2x = lastcheckpointx - ncx;
                if (dif1to2x<0) {dif1to2x = dif1to2x * -1;}
                dif1to2y = lastcheckpointy - ncy;
                if (dif1to2y<0) {dif1to2y = dif1to2y * -1;}
                leng1to2 = Math.Sqrt((dif1to2x*dif1to2x)+(dif1to2y*dif1to2y));
                turndist = (int)(leng1to2 * (cpanglepercentage/100));

                double a1x = lastcheckpointx - ncx;
                if (a1x<0) {a1x=a1x*-1;}

                double a1y = lastcheckpointy - ncy;
                if (a1y<0) {a1y=a1y*-1;}

                double c1 = Math.Sqrt((a1x*a1x)+(a1y*a1y));
                Console.Error.WriteLine("between last and me= "+c1.ToString());

                double b1x = x - ncx;
                if (b1x<0) {b1x=b1x*-1;}

                double b1y = y - ncy;
                if (b1y<0) {b1y=b1y*-1;}

                double a12 = Math.Sqrt((b1x*b1x)+(b1y*b1y));
                Console.Error.WriteLine("between next and last= "+a12.ToString());

                double c1x = lastcheckpointx - x;
                if (c1x<0){c1x=c1x*-1;}

                double c1y = lastcheckpointy - y;
                if (c1y<0){c1y=c1y*-1;}

                double b1 = Math.Sqrt((c1x*c1x)+(c1y*c1y));
                Console.Error.WriteLine("between me and next= "+b1.ToString());

                double a23 = 0-((a12*a12)/(2*b1*c1));
                double b2 = (b1/(2*c1));
                double c2 = (c1/(2*b1));

                wasa = Math.Acos(a23+b2+c2);
                if (wasa>180){
                    wasa = 180-(wasa-180);
                }
                Console.Error.WriteLine("wasa= "+wasa.ToString());
            }
            Console.Error.WriteLine("Last cp= "+lastcheckpointx.ToString()+" "+lastcheckpointy.ToString());
            Console.Error.WriteLine("next cp= "+ncx.ToString()+" "+ncy.ToString());
            Console.Error.WriteLine("overnext cp= "+overnextcpx.ToString()+" "+overnextcpy.ToString());
            // Write an action using Console.WriteLine()
            // To debug: Console.Error.WriteLine(""+.ToString());


            // you have to output the target position
            // followed by the power (0 <= thrust <= 100) or "BOOST" or "SHIELD"
            // i.e.: "x y thrust"
            if (allcheckpointsfound == true){
                Console.Error.WriteLine("turn dist= "+turndist.ToString());
                if (turndist < 0){
                    turndist = turndist * -1;
                }
                turndist = turndist * 50;
                if (turndist > 2000){
                    turndist = 2000;
                }
                if (ncd<turndist){
                    ncx = overnextcpx;
                    ncy = overnextcpy;
                }
            }
            if (startup==0){
                //b = (int)(100-(wasa/1.8));
                b = 100-((nca/180)*100);
                Console.Error.WriteLine("boost= "+b.ToString());
                if (b<0){b=b*-1;}
                Console.Error.WriteLine("boost= "+b.ToString());
            }
            if (b>90){
                b=100;
            }
            Console.Error.WriteLine("boost= "+b.ToString());
            if (startup>0){
                b=100;
                startup=startup-1;
            }
            if (nca == 0 && ncd > 3500 && allcheckpointsfound == true && boost == 1){
                Console.WriteLine(ncx + " " + ncy + " BOOST");
                boost = 0;
                usedability = true;
                usedboost = true;
            }
            if (usedability == false){
                Console.WriteLine(ncx + " " + ncy + " " + b.ToString());
            }
            Console.Error.WriteLine("Checkpoints= "+checkpoints.ToString());
            Console.Error.WriteLine("allcheckpointsfound? "+allcheckpointsfound.ToString());
            Console.Error.WriteLine("boost= "+b.ToString());
            Console.Error.WriteLine("turn dist= "+turndist.ToString());
            Console.Error.WriteLine("usedboost? "+usedboost.ToString());
            wasx = x;
            wasy = y;
        }
    }
}

pls someone help

Hi, I have a little question about this game. Excuse me, this racing game first pass how. However, I’m using ‘Python’ thank you

Have you followed the interactive tutorial when you first start the game? If so, do you think you have fixed the issue in the code as highlighted during the tutorial?

did you get the answer ? i’m still stuck int the same level

Hey, I am stuck in bronze league and I don’t know how to proceed from here so can anyone help me how can I solve this.

Hey, I am stuck in bronze league and I don’t know how to proceed from here so can anyone help me in this how to solve this and go to next.

hello !
excellent exercice and fun!
starting bronze league atm, and i d like to have some advice and what not comparisons on other code of the same league, i m quite a bit lost atm :smiley:
i ve created distance with opponent wich is not used in this code ( i d like to add it to the boost usage in future in the meaning to skip bouncing with opponent )
let xyb = 1;

let thrust = ’ 100’;

let ligneDroite = false;

let oldCheckpointDist = 0;

let oldCheckpointAngle = 0;

// game loop

while (true) {

var inputs = readline().split(' ');

const x = parseInt(inputs[0]);

const y = parseInt(inputs[1]);

const nextCheckpointX = parseInt(inputs[2]); // x position of the next check point

const nextCheckpointY = parseInt(inputs[3]); // y position of the next check point

const nextCheckpointDist = parseInt(inputs[4]); // distance to the next checkpoint

const nextCheckpointAngle = parseInt(inputs[5]); // angle between your pod orientation and the direction of the next checkpoint

var inputs = readline().split(' ');

const opponentX = parseInt(inputs[0]);

const opponentY = parseInt(inputs[1]);

let distOpp = Math.sqrt(Math.abs(x-opponentX)^2*(y-opponentY)^2);

if (oldCheckpointDist > 2000 && nextCheckpointDist > 2000 && nextCheckpointAngle < 30 && oldCheckpointAngle < 30){

    ligneDroite = true;

} else {

    ligneDroite = false;

}



if (ligneDroite === true && xyb >= 1){

    thrust = ' BOOST';

    xyb = xyb -1;

} else if (nextCheckpointDist < oldCheckpointDist){

    if (nextCheckpointDist >= 2000){

        thrust = ' 100';

    }else {

        thrust = ' 80';

    }

} else if (nextCheckpointDist >= oldCheckpointDist && Math.abs(nextCheckpointAngle) >= 100){

    thrust = ' 10';

} else if (nextCheckpointDist >= oldCheckpointDist && Math.abs(nextCheckpointAngle) <= 30){

    thrust = ' 100';

} else if (nextCheckpointDist >= oldCheckpointDist && Math.abs(nextCheckpointAngle) > 30 && Math.abs(nextCheckpointAngle) < 100){

    thrust = ' 30';

}



console.log(nextCheckpointX + ' ' + nextCheckpointY + thrust);

oldCheckpointDist = nextCheckpointDist;

oldCheckpointAngle = nextCheckpointAngle;

}

ANY TIP AND ADVICE MORE THAN WELCOME :wink:

hello. I wanted to try mad pods racing but have no idea what I’m supposed to do. it says it requires thrust or power or something. can someone explain a bit? would appreciate. thanks

Go full speed at all times unless the checkpoint is not in front of you
Aim for the next checkpoint before you hit the current one; you should skid through the checkpoints instead of going into them and then turning (hint: your current speed is useful for figuring out when to start turning)
Remember the position of each checkpoint on the first lap, so you can predict better on the later ones
Ignore collisions; you can get all the way to Gold by just racing efficiently

3 Likes

hey, i’m new in this game and i have some questions.
i have made some tests like

if (next_checkpoint_dist <= 1000 && next_checkpoint_dist > 800)
thrust *= 0.5;

but my speed never change why ?
the next checkpoint dist have an update only when i pass a checkpoint ?

i have to make a counter for use boost only one time, but it start at the beginning at the course…
how i can make to have my boost only after the first checkpoint per exemple ?

at the start the pod will advance toward the position of the next checkpoint.
u need to adjust the speed of the pod, via a variable, like thrust that u can modify with conditions.
for exemple
if nextCheckpointDist > 2000 then thrust = ’ 100’ ( this value is in percent)

and then at the end of u re console.log, u put that variable

2 Likes

i m not yet skilled enough to use skids, have any ressource bout that to tip me ? :smiley:

edit : now i understood what u said about stocking checkpoint id value for 2 nd lap

You may add some code to check what values your variables hold during code execution. For example in JavaScript, the code is like this:
console.error('Debug messages... ' + variable_name_here);

Using the same technique you may also check whether your “if” condition is fulfilled or not. If the condition is never fulfilled, the code within the “if” block will never be executed (and hence nothing is output to the error stream).

Also make sure you include the updated thrust (instead of e.g. a constant value of 100) in your output.

Regarding the question on counter: you may do something like this:

counter = 0;
while (true) {
    if (some_condition && counter == 0) {
        do something;
        counter = 1;
    }
}

This will ensure that when a condition is fulfilled, the actions of that “if” block will execute once only.

I don’t get it. I tried to put different constant values of thrust to see it moving at least to the first point but nothing happened it just shows a message about the pod not reaching anything. maybe I can read somewhere about how it works or it’s obvious and I’m too dumb for all this stuff. it seems to be interesting but I don’t know how to get started. thanks for the response tho

Maybe you can copy and paste the whole error message here?

I tried this puzzle, but I don’t know how to close the popups at the beginning, so I can’t read the instrctions.

The popups will be gone once you have followed all the instructions in the tutorial successfully. Are you stuck at any particular instruction?

I should repair the code, but I haven’t the data of the game, how moves the pod, for example. The popup masks me the rest of the screen.

I saw, I don’t need to understand, just see the error and repair it. :slightly_smiling_face:

1 Like

I have been promoted to Bronze, and I don’t know why. I don’t understand how it works, I just change very few of the code, and now i don’t change nothing more, sometimes I win, sometimes no, and I haven’t the faintest idea what I"m supposed to do to reach silver!