xxx
This commit is contained in:
parent
24e8bf6496
commit
8be5c7e20e
@ -94,7 +94,7 @@ struct trial {
|
||||
};
|
||||
|
||||
/* extern */
|
||||
void simulate(trial *t);
|
||||
void simulate(trial *t, timestamp ts);
|
||||
void godown(trial *t);
|
||||
|
||||
/* trial */
|
||||
|
@ -27,7 +27,7 @@ static timestamp extract_ts(context *ctx, char *fpc) {
|
||||
return atoi(ctx->tmp->str);
|
||||
}
|
||||
|
||||
#line 134 "control_parser.rl"
|
||||
#line 138 "control_parser.rl"
|
||||
|
||||
|
||||
|
||||
@ -243,7 +243,7 @@ static const int control_parser_error = 0;
|
||||
|
||||
static const int control_parser_en_main = 1;
|
||||
|
||||
#line 137 "control_parser.rl"
|
||||
#line 141 "control_parser.rl"
|
||||
|
||||
static int control_parser_has_error(context *ctx) {
|
||||
return ctx->cs == control_parser_error;
|
||||
@ -260,7 +260,7 @@ void control_parser_new(trial *t) {
|
||||
{
|
||||
( ctx->cs) = control_parser_start;
|
||||
}
|
||||
#line 149 "control_parser.rl"
|
||||
#line 153 "control_parser.rl"
|
||||
ctx->buffer = g_string_sized_new(0);
|
||||
ctx->tmp = g_string_sized_new(0);
|
||||
ctx->mark = -1;
|
||||
@ -274,7 +274,7 @@ void control_parser_reset(trial *t) {
|
||||
{
|
||||
( ctx->cs) = control_parser_start;
|
||||
}
|
||||
#line 158 "control_parser.rl"
|
||||
#line 162 "control_parser.rl"
|
||||
g_string_truncate(ctx->tmp, 0);
|
||||
ctx->mark = -1;
|
||||
/* fprintf(stderr, "Parser reset\n"); */
|
||||
@ -398,6 +398,10 @@ _match:
|
||||
/* fprintf(stderr, "New run\n"); */
|
||||
} else {
|
||||
/* fprintf(stderr, "time difference [ms]: %i\n", getcurts(t) - ctx->tm->ts); */
|
||||
fprintf(stderr, "Miss predict: dx=%f, dy=%f, ddir=%f\n",
|
||||
t->sim.vehicle.x - t->vehicle.x,
|
||||
t->sim.vehicle.y - t->vehicle.y,
|
||||
t->sim.vehicle.dir - t->vehicle.dir);
|
||||
}
|
||||
/* Reset simulation */
|
||||
t->sim.ts = ctx->tm->ts;
|
||||
@ -409,7 +413,7 @@ _match:
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
#line 59 "control_parser.rl"
|
||||
#line 63 "control_parser.rl"
|
||||
{
|
||||
ctx->tm->ts = ctx->ts;
|
||||
ctx->tm->vehicle.x = ctx->x;
|
||||
@ -424,115 +428,115 @@ _match:
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
#line 76 "control_parser.rl"
|
||||
#line 80 "control_parser.rl"
|
||||
{ t->map.dx = extract_double(ctx, p); }
|
||||
break;
|
||||
case 6:
|
||||
#line 77 "control_parser.rl"
|
||||
#line 81 "control_parser.rl"
|
||||
{ t->map.dy = extract_double(ctx, p); }
|
||||
break;
|
||||
case 7:
|
||||
#line 78 "control_parser.rl"
|
||||
#line 82 "control_parser.rl"
|
||||
{ t->map.min_sensor = extract_double(ctx, p); }
|
||||
break;
|
||||
case 8:
|
||||
#line 79 "control_parser.rl"
|
||||
#line 83 "control_parser.rl"
|
||||
{ t->map.max_sensor = extract_double(ctx, p); }
|
||||
break;
|
||||
case 9:
|
||||
#line 80 "control_parser.rl"
|
||||
#line 84 "control_parser.rl"
|
||||
{ t->map.max_speed = extract_double(ctx, p); }
|
||||
break;
|
||||
case 10:
|
||||
#line 81 "control_parser.rl"
|
||||
#line 85 "control_parser.rl"
|
||||
{ t->map.max_turn = extract_double(ctx, p); }
|
||||
break;
|
||||
case 11:
|
||||
#line 82 "control_parser.rl"
|
||||
#line 86 "control_parser.rl"
|
||||
{ t->map.max_hard_turn = extract_double(ctx, p); }
|
||||
break;
|
||||
case 12:
|
||||
#line 86 "control_parser.rl"
|
||||
#line 90 "control_parser.rl"
|
||||
{ ctx->x = extract_double(ctx, p); }
|
||||
break;
|
||||
case 13:
|
||||
#line 87 "control_parser.rl"
|
||||
#line 91 "control_parser.rl"
|
||||
{ ctx->y = extract_double(ctx, p); }
|
||||
break;
|
||||
case 14:
|
||||
#line 88 "control_parser.rl"
|
||||
#line 92 "control_parser.rl"
|
||||
{ ctx->r = extract_double(ctx, p); }
|
||||
break;
|
||||
case 15:
|
||||
#line 89 "control_parser.rl"
|
||||
#line 93 "control_parser.rl"
|
||||
{ ctx->dir = extract_double(ctx, p); }
|
||||
break;
|
||||
case 16:
|
||||
#line 90 "control_parser.rl"
|
||||
#line 94 "control_parser.rl"
|
||||
{ ctx->speed = extract_double(ctx, p); }
|
||||
break;
|
||||
case 17:
|
||||
#line 92 "control_parser.rl"
|
||||
#line 96 "control_parser.rl"
|
||||
{ ctx->tm->vehicle.accel = ACCEL; }
|
||||
break;
|
||||
case 18:
|
||||
#line 93 "control_parser.rl"
|
||||
#line 97 "control_parser.rl"
|
||||
{ ctx->tm->vehicle.accel = ROLL; }
|
||||
break;
|
||||
case 19:
|
||||
#line 94 "control_parser.rl"
|
||||
#line 98 "control_parser.rl"
|
||||
{ ctx->tm->vehicle.accel = BRAKE; }
|
||||
break;
|
||||
case 20:
|
||||
#line 96 "control_parser.rl"
|
||||
#line 100 "control_parser.rl"
|
||||
{ ctx->tm->vehicle.turn = TURN_HARD_LEFT; }
|
||||
break;
|
||||
case 21:
|
||||
#line 97 "control_parser.rl"
|
||||
#line 101 "control_parser.rl"
|
||||
{ ctx->tm->vehicle.turn = TURN_LEFT; }
|
||||
break;
|
||||
case 22:
|
||||
#line 98 "control_parser.rl"
|
||||
#line 102 "control_parser.rl"
|
||||
{ ctx->tm->vehicle.turn = TURN_STRAIGHT; }
|
||||
break;
|
||||
case 23:
|
||||
#line 99 "control_parser.rl"
|
||||
#line 103 "control_parser.rl"
|
||||
{ ctx->tm->vehicle.turn = TURN_RIGHT; }
|
||||
break;
|
||||
case 24:
|
||||
#line 100 "control_parser.rl"
|
||||
#line 104 "control_parser.rl"
|
||||
{ ctx->tm->vehicle.turn = TURN_HARD_RIGHT; }
|
||||
break;
|
||||
case 25:
|
||||
#line 102 "control_parser.rl"
|
||||
#line 106 "control_parser.rl"
|
||||
{ ctx->ts = extract_ts(ctx, p); }
|
||||
break;
|
||||
case 26:
|
||||
#line 103 "control_parser.rl"
|
||||
#line 107 "control_parser.rl"
|
||||
{ printf("Score %u\n", extract_ts(ctx, p)); }
|
||||
break;
|
||||
case 27:
|
||||
#line 105 "control_parser.rl"
|
||||
#line 109 "control_parser.rl"
|
||||
{
|
||||
object o = { BOLDER, ctx->x, ctx->y, ctx->r, 0, 0 };
|
||||
g_array_append_val(ctx->tm->objects, o);
|
||||
}
|
||||
break;
|
||||
case 28:
|
||||
#line 109 "control_parser.rl"
|
||||
#line 113 "control_parser.rl"
|
||||
{
|
||||
object o = { CRATER, ctx->x, ctx->y, ctx->r, 0, 0 };
|
||||
g_array_append_val(ctx->tm->objects, o);
|
||||
}
|
||||
break;
|
||||
case 29:
|
||||
#line 114 "control_parser.rl"
|
||||
#line 118 "control_parser.rl"
|
||||
{
|
||||
object o = { MARTIAN, ctx->x, ctx->y, MARTIAN_RADIUS, ctx->dir, ctx->speed };
|
||||
g_array_append_val(ctx->tm->objects, o);
|
||||
}
|
||||
break;
|
||||
#line 536 "control_parser.c"
|
||||
#line 540 "control_parser.c"
|
||||
}
|
||||
}
|
||||
|
||||
@ -544,7 +548,7 @@ _again:
|
||||
_test_eof: {}
|
||||
_out: {}
|
||||
}
|
||||
#line 181 "control_parser.rl"
|
||||
#line 185 "control_parser.rl"
|
||||
|
||||
ctx->pos = p - ctx->buffer->str;
|
||||
if (ctx->mark == -1) {
|
||||
|
@ -47,6 +47,10 @@ static timestamp extract_ts(context *ctx, char *fpc) {
|
||||
/* fprintf(stderr, "New run\n"); */
|
||||
} else {
|
||||
/* fprintf(stderr, "time difference [ms]: %i\n", getcurts(t) - ctx->tm->ts); */
|
||||
fprintf(stderr, "Miss predict: dx=%f, dy=%f, ddir=%f\n",
|
||||
t->sim.vehicle.x - t->vehicle.x,
|
||||
t->sim.vehicle.y - t->vehicle.y,
|
||||
t->sim.vehicle.dir - t->vehicle.dir);
|
||||
}
|
||||
/* Reset simulation */
|
||||
t->sim.ts = ctx->tm->ts;
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define LATENCY 20
|
||||
|
||||
void trial_loop(trial *t) {
|
||||
// path *p;
|
||||
// int offset;
|
||||
@ -16,7 +18,7 @@ void trial_loop(trial *t) {
|
||||
// offset = path_app_target(p,t,offset,0,0);
|
||||
while (t->alive) {
|
||||
// path_execute(t,p);
|
||||
simulate(t);
|
||||
simulate(t, getcurts(t) + LATENCY);
|
||||
godown(t);
|
||||
if (-1 == trial_check_input(t)) return;
|
||||
}
|
||||
|
@ -17,17 +17,20 @@ void godown(trial *t) {
|
||||
vehicle v;
|
||||
telemetry *tm;
|
||||
|
||||
double xpot, ypot, r, angle;
|
||||
double xpot, ypot, r, vr, angle, vdirx, vdiry;
|
||||
|
||||
/* todo: simulate movement */
|
||||
v = t->sim.vehicle;
|
||||
|
||||
tm = (telemetry*) g_queue_peek_tail(&t->telemetry);
|
||||
|
||||
r = sqrt(v.x*v.x + v.y*v.y);
|
||||
if (r < 4) return; /* done */
|
||||
xpot = 0.2 * v.x/r;
|
||||
ypot = 0.2 * v.y/r;
|
||||
vr = sqrt(v.x*v.x + v.y*v.y);
|
||||
if (vr < 4) return; /* done */
|
||||
xpot = 0.1 * v.x/vr;
|
||||
ypot = 0.1 * v.y/vr;
|
||||
vr = vr*vr;
|
||||
vdirx = cos(v.dir);
|
||||
vdiry = sin(v.dir);
|
||||
|
||||
for (guint i = 0; i < tm->objects->len; i++) {
|
||||
object *o = &g_array_index(tm->objects, object, i);
|
||||
@ -36,20 +39,25 @@ void godown(trial *t) {
|
||||
|
||||
switch (o->type) {
|
||||
case BOLDER:
|
||||
sigma = 2;
|
||||
r = (o->x * o->x + o->y + o->y);
|
||||
if ((vdirx*(o->x-v.x) + vdiry*(o->y-v.y)) < 0) continue;
|
||||
sigma = 2 * o->rad + 1;
|
||||
h = 1;
|
||||
break;
|
||||
case CRATER:
|
||||
sigma = 4;
|
||||
r = (o->x * o->x + o->y + o->y);
|
||||
if ((vdirx*(o->x-v.x) + vdiry*(o->y-v.y)) < 0) continue;
|
||||
sigma = 2 * o->rad + 3;
|
||||
h = 1;
|
||||
break;
|
||||
case MARTIAN:
|
||||
sigma = 8;
|
||||
sigma = 6;
|
||||
h = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
r = sqrt( (o->x - v.x) * (o->x - v.x) + (o->y - v.y) * (o->y - v.y) ) - o->rad;
|
||||
r = sqrt((o->x - v.x) * (o->x - v.x) + (o->y - v.y) * (o->y - v.y)) - o->rad;
|
||||
r = r*r;
|
||||
// r = r*r*r * 10;
|
||||
r = C1 * h / (sigma*sigma) / exp (r / (2*sigma) );
|
||||
xpot += (o->x - v.x) * r;
|
||||
@ -71,7 +79,7 @@ void godown(trial *t) {
|
||||
vehicle_left(t);
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "Angle: %f, objects: %u\n", angle, tm->objects->len);
|
||||
// fprintf(stderr, "Angle: %f, objects: %u\n", angle, tm->objects->len);
|
||||
angle = abs(angle);
|
||||
if (angle > 60) {
|
||||
vehicle_break(t);
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#define LATENCY 20
|
||||
|
||||
static double fixdir(double a) {
|
||||
if (a < 0) a += 360;
|
||||
@ -11,23 +10,24 @@ static double fixdir(double a) {
|
||||
return a;
|
||||
}
|
||||
|
||||
void simulate(trial *t) {
|
||||
void simulate(trial *t, timestamp ts) {
|
||||
double move, angle;
|
||||
|
||||
timestamp now = getcurts(t) + LATENCY, diff = now - t->sim.ts;
|
||||
if (diff < 20) return;
|
||||
timestamp diff = ts - t->sim.ts;
|
||||
if (diff == 0) return;
|
||||
t->sim.ts = ts;
|
||||
|
||||
/* move = t->sim.vehicle.speed / 1000 * diff;
|
||||
move = t->sim.vehicle.speed / 1000 * diff;
|
||||
angle = t->sim.vehicle.dir*M_PI/180;
|
||||
t->sim.vehicle.x += cos(angle)*move;
|
||||
t->sim.vehicle.y += sin(angle)*move;*/
|
||||
t->sim.vehicle.y += sin(angle)*move;
|
||||
|
||||
/* switch (t->sim.vehicle.turn) {
|
||||
case TURN_HARD_LEFT : t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir + t->map.max_hard_turn); break;
|
||||
case TURN_LEFT : t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir + t->map.max_turn); break;
|
||||
case TURN_HARD_LEFT : t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir + t->map.max_hard_turn/1000*diff); break;
|
||||
case TURN_LEFT : t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir + t->map.max_turn/1000*diff); break;
|
||||
case TURN_STRAIGHT : break;
|
||||
case TURN_RIGHT : t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir - t->map.max_turn); break;
|
||||
case TURN_HARD_RIGHT: t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir - t->map.max_hard_turn); break;
|
||||
case TURN_RIGHT : t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir - t->map.max_turn/1000*diff); break;
|
||||
case TURN_HARD_RIGHT: t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir - t->map.max_hard_turn/1000*diff); break;
|
||||
}
|
||||
|
||||
t->sim.vehicle.accel = t->vehicle.accel;
|
||||
|
Loading…
Reference in New Issue
Block a user