From 3ab78db7f509e943abef0b93d31b48860bf7cca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Sun, 13 Jul 2008 23:12:52 +0200 Subject: [PATCH] top secret --- src/control.c | 2 +- src/control_parser.c | 96 +++++++++++++++++++------------------------ src/control_parser.rl | 16 +------- src/lookahead.c | 1 + src/lookahead.h | 1 + src/radar_main.c | 15 +++---- testitradar | 2 +- 7 files changed, 53 insertions(+), 80 deletions(-) diff --git a/src/control.c b/src/control.c index 8543335..ab14c3e 100644 --- a/src/control.c +++ b/src/control.c @@ -138,7 +138,7 @@ int trial_check_input(trial *t) { p.fd = t->socket; p.events = POLLIN; - switch (poll(&p, 1, 0)) { + switch (poll(&p, 1, 1)) { case -1: switch (errno) { case EAGAIN: diff --git a/src/control_parser.c b/src/control_parser.c index 7db5d9c..624dcfe 100644 --- a/src/control_parser.c +++ b/src/control_parser.c @@ -1,6 +1,7 @@ #line 1 "control_parser.rl" #include "control_parser.h" +#include "lookahead.h" #include #include @@ -27,11 +28,11 @@ static timestamp extract_ts(context *ctx, char *fpc) { return atoi(ctx->tmp->str); } -#line 146 "control_parser.rl" +#line 134 "control_parser.rl" -#line 35 "control_parser.c" +#line 36 "control_parser.c" static const char _control_parser_actions[] = { 0, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, @@ -243,7 +244,7 @@ static const int control_parser_error = 0; static const int control_parser_en_main = 1; -#line 149 "control_parser.rl" +#line 137 "control_parser.rl" static int control_parser_has_error(context *ctx) { return ctx->cs == control_parser_error; @@ -256,11 +257,11 @@ static int control_parser_is_finished(context *ctx) { void control_parser_new(trial *t) { context *ctx = t->parse_ctx = g_slice_new(context); -#line 260 "control_parser.c" +#line 261 "control_parser.c" { ( ctx->cs) = control_parser_start; } -#line 161 "control_parser.rl" +#line 149 "control_parser.rl" ctx->buffer = g_string_sized_new(0); ctx->tmp = g_string_sized_new(0); ctx->mark = -1; @@ -270,11 +271,11 @@ void control_parser_new(trial *t) { void control_parser_reset(trial *t) { context *ctx = t->parse_ctx; -#line 274 "control_parser.c" +#line 275 "control_parser.c" { ( ctx->cs) = control_parser_start; } -#line 170 "control_parser.rl" +#line 158 "control_parser.rl" g_string_truncate(ctx->tmp, 0); ctx->mark = -1; /* fprintf(stderr, "Parser reset\n"); */ @@ -298,7 +299,7 @@ run_t control_parse(trial *t) { /* fprintf(stderr, "Parsing '%s' (len=%zu)\n", p, wehave); */ -#line 302 "control_parser.c" +#line 303 "control_parser.c" { int _klen; unsigned int _trans; @@ -372,7 +373,7 @@ _match: switch ( *_acts++ ) { case 0: -#line 34 "control_parser.rl" +#line 35 "control_parser.rl" { t->alive = 0; /* fprintf(stderr, "Run finished\n"); */ @@ -380,15 +381,15 @@ _match: } break; case 1: -#line 39 "control_parser.rl" +#line 40 "control_parser.rl" { ctx->mark = p - ctx->buffer->str; } break; case 2: -#line 40 "control_parser.rl" +#line 41 "control_parser.rl" { ctx->tm = telemetry_new(); } break; case 3: -#line 41 "control_parser.rl" +#line 42 "control_parser.rl" { g_queue_push_tail(&t->telemetry, ctx->tm); if (!t->alive) { @@ -396,22 +397,9 @@ _match: t->vehicle.turn = ctx->tm->vehicle.turn; gettimeofday(&t->started, NULL); /* fprintf(stderr, "New run\n"); */ - } else { -/* dgl(t, &t->sim.tm.vehicle, &t->sim.tm.vehicle, ctx->tm->ts - t->sim.tm.ts); - ctx->tm->vehicle.w = t->sim.tm.vehicle.w;*/ - /* fprintf(stderr, "time difference [ms]: %i\n", getcurts(t) - ctx->tm->ts); */ - fprintf(stderr, "Miss predict: dx=%f, dy=%f, ddir=%f, steps=%u\n", - t->sim.tm.vehicle.x - t->vehicle.x, - t->sim.tm.vehicle.y - t->vehicle.y, - t->sim.tm.vehicle.dir - t->vehicle.dir, - t->sim.steps); } /* Reset simulation */ - t->sim.tm.ts = ctx->tm->ts; - t->sim.tm.vehicle = ctx->tm->vehicle; - g_array_set_size(t->sim.tm.objects, 0); - g_array_append_vals(t->sim.tm.objects, ctx->tm->objects->data, ctx->tm->objects->len); - t->sim.steps = 0; + sim_update(t); t->last_ts = ctx->tm->ts; ctx->tm = NULL; @@ -419,7 +407,7 @@ _match: } break; case 4: -#line 69 "control_parser.rl" +#line 57 "control_parser.rl" { ctx->tm->ts = ctx->ts; ctx->tm->vehicle.x = ctx->x; @@ -434,95 +422,95 @@ _match: } break; case 5: -#line 86 "control_parser.rl" +#line 74 "control_parser.rl" { t->map.dx = extract_double(ctx, p); } break; case 6: -#line 87 "control_parser.rl" +#line 75 "control_parser.rl" { t->map.dy = extract_double(ctx, p); } break; case 7: -#line 88 "control_parser.rl" +#line 76 "control_parser.rl" { t->map.min_sensor = extract_double(ctx, p); } break; case 8: -#line 89 "control_parser.rl" +#line 77 "control_parser.rl" { t->map.max_sensor = extract_double(ctx, p); } break; case 9: -#line 90 "control_parser.rl" +#line 78 "control_parser.rl" { t->map.max_speed = extract_double(ctx, p); } break; case 10: -#line 91 "control_parser.rl" +#line 79 "control_parser.rl" { t->map.max_turn = extract_double(ctx, p); } break; case 11: -#line 92 "control_parser.rl" +#line 80 "control_parser.rl" { t->map.max_hard_turn = extract_double(ctx, p); } break; case 12: -#line 96 "control_parser.rl" +#line 84 "control_parser.rl" { ctx->x = extract_double(ctx, p); } break; case 13: -#line 97 "control_parser.rl" +#line 85 "control_parser.rl" { ctx->y = extract_double(ctx, p); } break; case 14: -#line 98 "control_parser.rl" +#line 86 "control_parser.rl" { ctx->r = extract_double(ctx, p); } break; case 15: -#line 99 "control_parser.rl" +#line 87 "control_parser.rl" { ctx->dir = extract_double(ctx, p); } break; case 16: -#line 100 "control_parser.rl" +#line 88 "control_parser.rl" { ctx->speed = extract_double(ctx, p); } break; case 17: -#line 102 "control_parser.rl" +#line 90 "control_parser.rl" { ctx->tm->vehicle.accel = ACCEL; } break; case 18: -#line 103 "control_parser.rl" +#line 91 "control_parser.rl" { ctx->tm->vehicle.accel = ROLL; } break; case 19: -#line 104 "control_parser.rl" +#line 92 "control_parser.rl" { ctx->tm->vehicle.accel = BRAKE; } break; case 20: -#line 106 "control_parser.rl" +#line 94 "control_parser.rl" { ctx->tm->vehicle.turn = TURN_HARD_LEFT; } break; case 21: -#line 107 "control_parser.rl" +#line 95 "control_parser.rl" { ctx->tm->vehicle.turn = TURN_LEFT; } break; case 22: -#line 108 "control_parser.rl" +#line 96 "control_parser.rl" { ctx->tm->vehicle.turn = TURN_STRAIGHT; } break; case 23: -#line 109 "control_parser.rl" +#line 97 "control_parser.rl" { ctx->tm->vehicle.turn = TURN_RIGHT; } break; case 24: -#line 110 "control_parser.rl" +#line 98 "control_parser.rl" { ctx->tm->vehicle.turn = TURN_HARD_RIGHT; } break; case 25: -#line 112 "control_parser.rl" +#line 100 "control_parser.rl" { ctx->ts = extract_ts(ctx, p); } break; case 26: -#line 113 "control_parser.rl" +#line 101 "control_parser.rl" { printf("Score %u\n", extract_ts(ctx, p)); } break; case 27: -#line 115 "control_parser.rl" +#line 103 "control_parser.rl" { object *o = object_new(BOLDER, ctx->x, ctx->y, ctx->r, 0, 0); /* g_array_append_vals(ctx->tm->objects, o, 1); */ @@ -530,7 +518,7 @@ _match: } break; case 28: -#line 120 "control_parser.rl" +#line 108 "control_parser.rl" { object *o = object_new(CRATER, ctx->x, ctx->y, ctx->r, 0, 0); /* g_array_append_vals(ctx->tm->objects, o, 1); */ @@ -538,13 +526,13 @@ _match: } break; case 29: -#line 126 "control_parser.rl" +#line 114 "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 548 "control_parser.c" +#line 536 "control_parser.c" } } @@ -556,7 +544,7 @@ _again: _test_eof: {} _out: {} } -#line 193 "control_parser.rl" +#line 181 "control_parser.rl" ctx->pos = p - ctx->buffer->str; if (ctx->mark == -1) { diff --git a/src/control_parser.rl b/src/control_parser.rl index 3db4042..172a948 100644 --- a/src/control_parser.rl +++ b/src/control_parser.rl @@ -1,5 +1,6 @@ #include "control_parser.h" +#include "lookahead.h" #include #include @@ -45,22 +46,9 @@ static timestamp extract_ts(context *ctx, char *fpc) { t->vehicle.turn = ctx->tm->vehicle.turn; gettimeofday(&t->started, NULL); /* fprintf(stderr, "New run\n"); */ - } else { -/* dgl(t, &t->sim.tm.vehicle, &t->sim.tm.vehicle, ctx->tm->ts - t->sim.tm.ts); - ctx->tm->vehicle.w = t->sim.tm.vehicle.w;*/ - /* fprintf(stderr, "time difference [ms]: %i\n", getcurts(t) - ctx->tm->ts); */ - fprintf(stderr, "Miss predict: dx=%f, dy=%f, ddir=%f, steps=%u\n", - t->sim.tm.vehicle.x - t->vehicle.x, - t->sim.tm.vehicle.y - t->vehicle.y, - t->sim.tm.vehicle.dir - t->vehicle.dir, - t->sim.steps); } /* Reset simulation */ - t->sim.tm.ts = ctx->tm->ts; - t->sim.tm.vehicle = ctx->tm->vehicle; - g_array_set_size(t->sim.tm.objects, 0); - g_array_append_vals(t->sim.tm.objects, ctx->tm->objects->data, ctx->tm->objects->len); - t->sim.steps = 0; + sim_update(t); t->last_ts = ctx->tm->ts; ctx->tm = NULL; diff --git a/src/lookahead.c b/src/lookahead.c index f2ea270..e0b0254 100644 --- a/src/lookahead.c +++ b/src/lookahead.c @@ -80,6 +80,7 @@ void sim_update(trial* t){ telemetry *tm,*tmp; tm = (telemetry*) g_queue_peek_tail(&t->telemetry); + fprintf(stderr, "Time diff: %i\n", tm->ts - t->sim.tm.ts); /*run simulation up to new telemetry timestamp*/ radar_dgl(t,tm->ts); diff --git a/src/lookahead.h b/src/lookahead.h index 3fd582c..73aebaf 100644 --- a/src/lookahead.h +++ b/src/lookahead.h @@ -10,5 +10,6 @@ int dgl(trial* t, vehicle* after, vehicle* before, timestamp h, timestamp deltat void sim_update(trial* t); void radar_dgl(trial* t, timestamp ts); + #endif diff --git a/src/radar_main.c b/src/radar_main.c index 9ffec65..8484dbb 100644 --- a/src/radar_main.c +++ b/src/radar_main.c @@ -4,7 +4,7 @@ #include -#define LATENCY 20 +#define LATENCY 2 void trial_loop(trial *t) { do { @@ -32,15 +32,10 @@ void trial_loop(trial *t) { } while (t->alive) { - timestamp step=getcurts(t) + LATENCY - t->sim.tm.ts; - if (step > 0) { - t->sim.tm.vehicle.w = turn2w(t, t->sim.tm.vehicle.turn); - dgl(t,&t->sim.tm.vehicle,&t->sim.tm.vehicle,step,1); - t->sim.tm.ts += step; - t->sim.steps++; - } -// simulate(t, getcurts(t) + LATENCY); - goradar(t); + radar_dgl(t, getcurts(t) + LATENCY); +// goradar(t); + vehicle_break(t); + vehicle_hard_right(t); if (-1 == trial_check_input(t)) return; // if (-1 == trial_wait_for_input(t)) return; } diff --git a/testitradar b/testitradar index 18ee7e8..6fe4598 100755 --- a/testitradar +++ b/testitradar @@ -7,7 +7,7 @@ CMD="./build/default/src/icfp08radar localhost 17676" if [ "$1" == "--gdb" ]; then CMD="gdb --args ${CMD}" elif [ "$1" == "--valgrind" ]; then - CMD="valgrind --leak-check=full ${CMD}" + CMD="valgrind --leak-check=full -v ${CMD}" fi exec $CMD