Merge branch 'master' of git+ssh://gitosis@stbuehler.de:522/icfp11

This commit is contained in:
Johannes Reinhardt 2008-07-13 23:13:55 +02:00
commit 189d6f78c3
7 changed files with 53 additions and 80 deletions

View File

@ -138,7 +138,7 @@ int trial_check_input(trial *t) {
p.fd = t->socket; p.fd = t->socket;
p.events = POLLIN; p.events = POLLIN;
switch (poll(&p, 1, 0)) { switch (poll(&p, 1, 1)) {
case -1: case -1:
switch (errno) { switch (errno) {
case EAGAIN: case EAGAIN:

View File

@ -1,6 +1,7 @@
#line 1 "control_parser.rl" #line 1 "control_parser.rl"
#include "control_parser.h" #include "control_parser.h"
#include "lookahead.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -27,11 +28,11 @@ static timestamp extract_ts(context *ctx, char *fpc) {
return atoi(ctx->tmp->str); 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[] = { static const char _control_parser_actions[] = {
0, 1, 0, 1, 1, 1, 2, 1, 0, 1, 0, 1, 1, 1, 2, 1,
3, 1, 4, 1, 5, 1, 6, 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; 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) { static int control_parser_has_error(context *ctx) {
return ctx->cs == control_parser_error; return ctx->cs == control_parser_error;
@ -256,11 +257,11 @@ static int control_parser_is_finished(context *ctx) {
void control_parser_new(trial *t) { void control_parser_new(trial *t) {
context *ctx = t->parse_ctx = g_slice_new(context); context *ctx = t->parse_ctx = g_slice_new(context);
#line 260 "control_parser.c" #line 261 "control_parser.c"
{ {
( ctx->cs) = control_parser_start; ( ctx->cs) = control_parser_start;
} }
#line 161 "control_parser.rl" #line 149 "control_parser.rl"
ctx->buffer = g_string_sized_new(0); ctx->buffer = g_string_sized_new(0);
ctx->tmp = g_string_sized_new(0); ctx->tmp = g_string_sized_new(0);
ctx->mark = -1; ctx->mark = -1;
@ -270,11 +271,11 @@ void control_parser_new(trial *t) {
void control_parser_reset(trial *t) { void control_parser_reset(trial *t) {
context *ctx = t->parse_ctx; context *ctx = t->parse_ctx;
#line 274 "control_parser.c" #line 275 "control_parser.c"
{ {
( ctx->cs) = control_parser_start; ( ctx->cs) = control_parser_start;
} }
#line 170 "control_parser.rl" #line 158 "control_parser.rl"
g_string_truncate(ctx->tmp, 0); g_string_truncate(ctx->tmp, 0);
ctx->mark = -1; ctx->mark = -1;
/* fprintf(stderr, "Parser reset\n"); */ /* fprintf(stderr, "Parser reset\n"); */
@ -298,7 +299,7 @@ run_t control_parse(trial *t) {
/* fprintf(stderr, "Parsing '%s' (len=%zu)\n", p, wehave); */ /* fprintf(stderr, "Parsing '%s' (len=%zu)\n", p, wehave); */
#line 302 "control_parser.c" #line 303 "control_parser.c"
{ {
int _klen; int _klen;
unsigned int _trans; unsigned int _trans;
@ -372,7 +373,7 @@ _match:
switch ( *_acts++ ) switch ( *_acts++ )
{ {
case 0: case 0:
#line 34 "control_parser.rl" #line 35 "control_parser.rl"
{ {
t->alive = 0; t->alive = 0;
/* fprintf(stderr, "Run finished\n"); */ /* fprintf(stderr, "Run finished\n"); */
@ -380,15 +381,15 @@ _match:
} }
break; break;
case 1: case 1:
#line 39 "control_parser.rl" #line 40 "control_parser.rl"
{ ctx->mark = p - ctx->buffer->str; } { ctx->mark = p - ctx->buffer->str; }
break; break;
case 2: case 2:
#line 40 "control_parser.rl" #line 41 "control_parser.rl"
{ ctx->tm = telemetry_new(); } { ctx->tm = telemetry_new(); }
break; break;
case 3: case 3:
#line 41 "control_parser.rl" #line 42 "control_parser.rl"
{ {
g_queue_push_tail(&t->telemetry, ctx->tm); g_queue_push_tail(&t->telemetry, ctx->tm);
if (!t->alive) { if (!t->alive) {
@ -396,22 +397,9 @@ _match:
t->vehicle.turn = ctx->tm->vehicle.turn; t->vehicle.turn = ctx->tm->vehicle.turn;
gettimeofday(&t->started, NULL); gettimeofday(&t->started, NULL);
/* fprintf(stderr, "New run\n"); */ /* 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 */ /* Reset simulation */
t->sim.tm.ts = ctx->tm->ts; sim_update(t);
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;
t->last_ts = ctx->tm->ts; t->last_ts = ctx->tm->ts;
ctx->tm = NULL; ctx->tm = NULL;
@ -419,7 +407,7 @@ _match:
} }
break; break;
case 4: case 4:
#line 69 "control_parser.rl" #line 57 "control_parser.rl"
{ {
ctx->tm->ts = ctx->ts; ctx->tm->ts = ctx->ts;
ctx->tm->vehicle.x = ctx->x; ctx->tm->vehicle.x = ctx->x;
@ -434,95 +422,95 @@ _match:
} }
break; break;
case 5: case 5:
#line 86 "control_parser.rl" #line 74 "control_parser.rl"
{ t->map.dx = extract_double(ctx, p); } { t->map.dx = extract_double(ctx, p); }
break; break;
case 6: case 6:
#line 87 "control_parser.rl" #line 75 "control_parser.rl"
{ t->map.dy = extract_double(ctx, p); } { t->map.dy = extract_double(ctx, p); }
break; break;
case 7: case 7:
#line 88 "control_parser.rl" #line 76 "control_parser.rl"
{ t->map.min_sensor = extract_double(ctx, p); } { t->map.min_sensor = extract_double(ctx, p); }
break; break;
case 8: case 8:
#line 89 "control_parser.rl" #line 77 "control_parser.rl"
{ t->map.max_sensor = extract_double(ctx, p); } { t->map.max_sensor = extract_double(ctx, p); }
break; break;
case 9: case 9:
#line 90 "control_parser.rl" #line 78 "control_parser.rl"
{ t->map.max_speed = extract_double(ctx, p); } { t->map.max_speed = extract_double(ctx, p); }
break; break;
case 10: case 10:
#line 91 "control_parser.rl" #line 79 "control_parser.rl"
{ t->map.max_turn = extract_double(ctx, p); } { t->map.max_turn = extract_double(ctx, p); }
break; break;
case 11: case 11:
#line 92 "control_parser.rl" #line 80 "control_parser.rl"
{ t->map.max_hard_turn = extract_double(ctx, p); } { t->map.max_hard_turn = extract_double(ctx, p); }
break; break;
case 12: case 12:
#line 96 "control_parser.rl" #line 84 "control_parser.rl"
{ ctx->x = extract_double(ctx, p); } { ctx->x = extract_double(ctx, p); }
break; break;
case 13: case 13:
#line 97 "control_parser.rl" #line 85 "control_parser.rl"
{ ctx->y = extract_double(ctx, p); } { ctx->y = extract_double(ctx, p); }
break; break;
case 14: case 14:
#line 98 "control_parser.rl" #line 86 "control_parser.rl"
{ ctx->r = extract_double(ctx, p); } { ctx->r = extract_double(ctx, p); }
break; break;
case 15: case 15:
#line 99 "control_parser.rl" #line 87 "control_parser.rl"
{ ctx->dir = extract_double(ctx, p); } { ctx->dir = extract_double(ctx, p); }
break; break;
case 16: case 16:
#line 100 "control_parser.rl" #line 88 "control_parser.rl"
{ ctx->speed = extract_double(ctx, p); } { ctx->speed = extract_double(ctx, p); }
break; break;
case 17: case 17:
#line 102 "control_parser.rl" #line 90 "control_parser.rl"
{ ctx->tm->vehicle.accel = ACCEL; } { ctx->tm->vehicle.accel = ACCEL; }
break; break;
case 18: case 18:
#line 103 "control_parser.rl" #line 91 "control_parser.rl"
{ ctx->tm->vehicle.accel = ROLL; } { ctx->tm->vehicle.accel = ROLL; }
break; break;
case 19: case 19:
#line 104 "control_parser.rl" #line 92 "control_parser.rl"
{ ctx->tm->vehicle.accel = BRAKE; } { ctx->tm->vehicle.accel = BRAKE; }
break; break;
case 20: case 20:
#line 106 "control_parser.rl" #line 94 "control_parser.rl"
{ ctx->tm->vehicle.turn = TURN_HARD_LEFT; } { ctx->tm->vehicle.turn = TURN_HARD_LEFT; }
break; break;
case 21: case 21:
#line 107 "control_parser.rl" #line 95 "control_parser.rl"
{ ctx->tm->vehicle.turn = TURN_LEFT; } { ctx->tm->vehicle.turn = TURN_LEFT; }
break; break;
case 22: case 22:
#line 108 "control_parser.rl" #line 96 "control_parser.rl"
{ ctx->tm->vehicle.turn = TURN_STRAIGHT; } { ctx->tm->vehicle.turn = TURN_STRAIGHT; }
break; break;
case 23: case 23:
#line 109 "control_parser.rl" #line 97 "control_parser.rl"
{ ctx->tm->vehicle.turn = TURN_RIGHT; } { ctx->tm->vehicle.turn = TURN_RIGHT; }
break; break;
case 24: case 24:
#line 110 "control_parser.rl" #line 98 "control_parser.rl"
{ ctx->tm->vehicle.turn = TURN_HARD_RIGHT; } { ctx->tm->vehicle.turn = TURN_HARD_RIGHT; }
break; break;
case 25: case 25:
#line 112 "control_parser.rl" #line 100 "control_parser.rl"
{ ctx->ts = extract_ts(ctx, p); } { ctx->ts = extract_ts(ctx, p); }
break; break;
case 26: case 26:
#line 113 "control_parser.rl" #line 101 "control_parser.rl"
{ printf("Score %u\n", extract_ts(ctx, p)); } { printf("Score %u\n", extract_ts(ctx, p)); }
break; break;
case 27: 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); object *o = object_new(BOLDER, ctx->x, ctx->y, ctx->r, 0, 0);
/* g_array_append_vals(ctx->tm->objects, o, 1); */ /* g_array_append_vals(ctx->tm->objects, o, 1); */
@ -530,7 +518,7 @@ _match:
} }
break; break;
case 28: 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); object *o = object_new(CRATER, ctx->x, ctx->y, ctx->r, 0, 0);
/* g_array_append_vals(ctx->tm->objects, o, 1); */ /* g_array_append_vals(ctx->tm->objects, o, 1); */
@ -538,13 +526,13 @@ _match:
} }
break; break;
case 29: 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 }; object o = { MARTIAN, ctx->x, ctx->y, MARTIAN_RADIUS, ctx->dir, ctx->speed };
g_array_append_val(ctx->tm->objects, o); g_array_append_val(ctx->tm->objects, o);
} }
break; break;
#line 548 "control_parser.c" #line 536 "control_parser.c"
} }
} }
@ -556,7 +544,7 @@ _again:
_test_eof: {} _test_eof: {}
_out: {} _out: {}
} }
#line 193 "control_parser.rl" #line 181 "control_parser.rl"
ctx->pos = p - ctx->buffer->str; ctx->pos = p - ctx->buffer->str;
if (ctx->mark == -1) { if (ctx->mark == -1) {

View File

@ -1,5 +1,6 @@
#include "control_parser.h" #include "control_parser.h"
#include "lookahead.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -45,22 +46,9 @@ static timestamp extract_ts(context *ctx, char *fpc) {
t->vehicle.turn = ctx->tm->vehicle.turn; t->vehicle.turn = ctx->tm->vehicle.turn;
gettimeofday(&t->started, NULL); gettimeofday(&t->started, NULL);
/* fprintf(stderr, "New run\n"); */ /* 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 */ /* Reset simulation */
t->sim.tm.ts = ctx->tm->ts; sim_update(t);
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;
t->last_ts = ctx->tm->ts; t->last_ts = ctx->tm->ts;
ctx->tm = NULL; ctx->tm = NULL;

View File

@ -80,6 +80,7 @@ void sim_update(trial* t){
telemetry *tm,*tmp; telemetry *tm,*tmp;
tm = (telemetry*) g_queue_peek_tail(&t->telemetry); 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*/ /*run simulation up to new telemetry timestamp*/
radar_dgl(t,tm->ts); radar_dgl(t,tm->ts);

View File

@ -10,5 +10,6 @@ int dgl(trial* t, vehicle* after, vehicle* before, timestamp h, timestamp deltat
void sim_update(trial* t); void sim_update(trial* t);
void radar_dgl(trial* t, timestamp ts); void radar_dgl(trial* t, timestamp ts);
#endif #endif

View File

@ -4,7 +4,7 @@
#include <stdio.h> #include <stdio.h>
#define LATENCY 20 #define LATENCY 2
void trial_loop(trial *t) { void trial_loop(trial *t) {
do { do {
@ -32,15 +32,10 @@ void trial_loop(trial *t) {
} }
while (t->alive) { while (t->alive) {
timestamp step=getcurts(t) + LATENCY - t->sim.tm.ts; radar_dgl(t, getcurts(t) + LATENCY);
if (step > 0) { // goradar(t);
t->sim.tm.vehicle.w = turn2w(t, t->sim.tm.vehicle.turn); vehicle_break(t);
dgl(t,&t->sim.tm.vehicle,&t->sim.tm.vehicle,step,1); vehicle_hard_right(t);
t->sim.tm.ts += step;
t->sim.steps++;
}
// simulate(t, getcurts(t) + LATENCY);
goradar(t);
if (-1 == trial_check_input(t)) return; if (-1 == trial_check_input(t)) return;
// if (-1 == trial_wait_for_input(t)) return; // if (-1 == trial_wait_for_input(t)) return;
} }

View File

@ -7,7 +7,7 @@ CMD="./build/default/src/icfp08radar localhost 17676"
if [ "$1" == "--gdb" ]; then if [ "$1" == "--gdb" ]; then
CMD="gdb --args ${CMD}" CMD="gdb --args ${CMD}"
elif [ "$1" == "--valgrind" ]; then elif [ "$1" == "--valgrind" ]; then
CMD="valgrind --leak-check=full ${CMD}" CMD="valgrind --leak-check=full -v ${CMD}"
fi fi
exec $CMD exec $CMD