Hello guys,
I’m fresh new user of Coding Game, and a beginner in C language.
After few level of playing Mad Pod Racing, i start to modify my code to make a little bit efficient. And, first, i tried to use cos() function provided by math.h lib, and i get a time out, i didn’t found where the problem came. My first idea was that the program will not compile with the -lm flag. So i change my code.
Then, i just replaced my function using cos() with another one without extra libs provided by the game.
But i get the same time out, and executing directly by myself i got the right output.
Does someones got an idea or ressources so i can fix it by myself?
Below you can find my code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define ABS(x) (((x) < 0) ? -(x) : (x))
typedef struct race1{
int x;
int y;
int next_checkpoint_x;
int next_checkpoint_y;
int next_checkpoint_dist;
int next_checkpoint_angle;
int opponent_x;
int opponent_y;
} t_position;
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
int generate_speed(t_position p)
{
double angle;
double coef;
int speed;
angle = (double)ABS(p.next_checkpoint_angle);
coef = 1.0 - (angle/90.0);
speed = (int)(100.0 * (coef));
if (speed <= 0)
return (0);
if (speed >= 100)
return (100);
return (speed);
}
int main()
{
t_position *p;
while (1) {
scanf("%d%d%d%d%d%d", &p->x, &p->y, &p->next_checkpoint_x, &p->next_checkpoint_y, &p->next_checkpoint_dist, &p->next_checkpoint_angle);
scanf("%d%d", &p->opponent_x, &p->opponent_y);
// Write an action using printf(). DON'T FORGET THE TRAILING \n
// To debug: fprintf(stderr, "Debug messages...\n");
int speed;
speed = generate_speed(*p);
// You have to output the target position
// followed by the power (0 <= thrust <= 100)
// i.e.: "x y thrust"
printf("%d %d %d\n", p->next_checkpoint_x, p->next_checkpoint_y, speed);
}
return 0;
}
There you can find the terminal output ingame:
Informations :
Timeout: the program did not provide 1 input lines in due time... KanticField will no longer be active in this game.
Sortie standard :
4524 6021 100
Informations :
Pod 1 of player Boss 3 moves towards (4524, 6021) at power 100
Thank you guys for reading me.