Copy some more data from parsing
This commit is contained in:
parent
4f765de334
commit
d58f324bef
@ -27,7 +27,7 @@ static timestamp extract_ts(context *ctx, char *fpc) {
|
|||||||
return atoi(ctx->tmp->str);
|
return atoi(ctx->tmp->str);
|
||||||
}
|
}
|
||||||
|
|
||||||
#line 114 "control_parser.rl"
|
#line 122 "control_parser.rl"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -240,7 +240,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 117 "control_parser.rl"
|
#line 125 "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;
|
||||||
@ -257,7 +257,7 @@ void control_parser_new(trial *t) {
|
|||||||
{
|
{
|
||||||
( ctx->cs) = control_parser_start;
|
( ctx->cs) = control_parser_start;
|
||||||
}
|
}
|
||||||
#line 129 "control_parser.rl"
|
#line 137 "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;
|
||||||
@ -271,7 +271,7 @@ void control_parser_reset(trial *t) {
|
|||||||
{
|
{
|
||||||
( ctx->cs) = control_parser_start;
|
( ctx->cs) = control_parser_start;
|
||||||
}
|
}
|
||||||
#line 138 "control_parser.rl"
|
#line 146 "control_parser.rl"
|
||||||
g_string_truncate(ctx->tmp, 0);
|
g_string_truncate(ctx->tmp, 0);
|
||||||
ctx->mark = -1;
|
ctx->mark = -1;
|
||||||
ctx->pos = 0;
|
ctx->pos = 0;
|
||||||
@ -292,7 +292,7 @@ run_t control_parse(trial *t) {
|
|||||||
|
|
||||||
p = ctx->buffer->str + ctx->pos;
|
p = ctx->buffer->str + ctx->pos;
|
||||||
pe = p + wehave;
|
pe = p + wehave;
|
||||||
fprintf(stderr, "Parsing '%s' (len=%zu)\n", p, wehave);
|
/* fprintf(stderr, "Parsing '%s' (len=%zu)\n", p, wehave); */
|
||||||
|
|
||||||
|
|
||||||
#line 299 "control_parser.c"
|
#line 299 "control_parser.c"
|
||||||
@ -384,15 +384,23 @@ _match:
|
|||||||
#line 37 "control_parser.rl"
|
#line 37 "control_parser.rl"
|
||||||
{
|
{
|
||||||
g_queue_push_tail(&t->telemetry, ctx->tm);
|
g_queue_push_tail(&t->telemetry, ctx->tm);
|
||||||
|
if (!t->alive) {
|
||||||
|
t->vehicle.accel = ctx->tm->vehicle.accel;
|
||||||
|
t->vehicle.turn = ctx->tm->vehicle.turn;
|
||||||
|
}
|
||||||
t->last_ts = ctx->tm->ts;
|
t->last_ts = ctx->tm->ts;
|
||||||
ctx->tm = NULL;
|
ctx->tm = NULL;
|
||||||
t->alive = 1;
|
t->alive = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
#line 43 "control_parser.rl"
|
#line 47 "control_parser.rl"
|
||||||
{
|
{
|
||||||
ctx->tm->ts = ctx->ts;
|
ctx->tm->ts = ctx->ts;
|
||||||
|
ctx->tm->vehicle.x = ctx->x;
|
||||||
|
ctx->tm->vehicle.y = ctx->y;
|
||||||
|
ctx->tm->vehicle.dir = ctx->dir;
|
||||||
|
ctx->tm->vehicle.speed = ctx->speed;
|
||||||
t->vehicle.x = ctx->x;
|
t->vehicle.x = ctx->x;
|
||||||
t->vehicle.y = ctx->y;
|
t->vehicle.y = ctx->y;
|
||||||
t->vehicle.dir = ctx->dir;
|
t->vehicle.dir = ctx->dir;
|
||||||
@ -401,115 +409,115 @@ _match:
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
#line 56 "control_parser.rl"
|
#line 64 "control_parser.rl"
|
||||||
{ t->map.dx = extract_double(ctx, p); }
|
{ t->map.dx = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
#line 57 "control_parser.rl"
|
#line 65 "control_parser.rl"
|
||||||
{ t->map.dy = extract_double(ctx, p); }
|
{ t->map.dy = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
#line 58 "control_parser.rl"
|
#line 66 "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 59 "control_parser.rl"
|
#line 67 "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 60 "control_parser.rl"
|
#line 68 "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 61 "control_parser.rl"
|
#line 69 "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 62 "control_parser.rl"
|
#line 70 "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 66 "control_parser.rl"
|
#line 74 "control_parser.rl"
|
||||||
{ ctx->x = extract_double(ctx, p); }
|
{ ctx->x = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 13:
|
case 13:
|
||||||
#line 67 "control_parser.rl"
|
#line 75 "control_parser.rl"
|
||||||
{ ctx->y = extract_double(ctx, p); }
|
{ ctx->y = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
#line 68 "control_parser.rl"
|
#line 76 "control_parser.rl"
|
||||||
{ ctx->r = extract_double(ctx, p); }
|
{ ctx->r = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 15:
|
case 15:
|
||||||
#line 69 "control_parser.rl"
|
#line 77 "control_parser.rl"
|
||||||
{ ctx->dir = extract_double(ctx, p); }
|
{ ctx->dir = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
#line 70 "control_parser.rl"
|
#line 78 "control_parser.rl"
|
||||||
{ ctx->speed = extract_double(ctx, p); }
|
{ ctx->speed = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 17:
|
case 17:
|
||||||
#line 72 "control_parser.rl"
|
#line 80 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.accel = ACCEL; }
|
{ ctx->tm->vehicle.accel = ACCEL; }
|
||||||
break;
|
break;
|
||||||
case 18:
|
case 18:
|
||||||
#line 73 "control_parser.rl"
|
#line 81 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.accel = ROLL; }
|
{ ctx->tm->vehicle.accel = ROLL; }
|
||||||
break;
|
break;
|
||||||
case 19:
|
case 19:
|
||||||
#line 74 "control_parser.rl"
|
#line 82 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.accel = BREAK; }
|
{ ctx->tm->vehicle.accel = BREAK; }
|
||||||
break;
|
break;
|
||||||
case 20:
|
case 20:
|
||||||
#line 76 "control_parser.rl"
|
#line 84 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.turn = TURN_HARD_LEFT; }
|
{ ctx->tm->vehicle.turn = TURN_HARD_LEFT; }
|
||||||
break;
|
break;
|
||||||
case 21:
|
case 21:
|
||||||
#line 77 "control_parser.rl"
|
#line 85 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.turn = TURN_LEFT; }
|
{ ctx->tm->vehicle.turn = TURN_LEFT; }
|
||||||
break;
|
break;
|
||||||
case 22:
|
case 22:
|
||||||
#line 78 "control_parser.rl"
|
#line 86 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.turn = TURN_STRAIGHT; }
|
{ ctx->tm->vehicle.turn = TURN_STRAIGHT; }
|
||||||
break;
|
break;
|
||||||
case 23:
|
case 23:
|
||||||
#line 79 "control_parser.rl"
|
#line 87 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.turn = TURN_RIGHT; }
|
{ ctx->tm->vehicle.turn = TURN_RIGHT; }
|
||||||
break;
|
break;
|
||||||
case 24:
|
case 24:
|
||||||
#line 80 "control_parser.rl"
|
#line 88 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.turn = TURN_HARD_RIGHT; }
|
{ ctx->tm->vehicle.turn = TURN_HARD_RIGHT; }
|
||||||
break;
|
break;
|
||||||
case 25:
|
case 25:
|
||||||
#line 82 "control_parser.rl"
|
#line 90 "control_parser.rl"
|
||||||
{ ctx->ts = extract_ts(ctx, p); }
|
{ ctx->ts = extract_ts(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 26:
|
case 26:
|
||||||
#line 83 "control_parser.rl"
|
#line 91 "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 85 "control_parser.rl"
|
#line 93 "control_parser.rl"
|
||||||
{
|
{
|
||||||
object o = { BOLDER, ctx->x, ctx->y, ctx->r, 0, 0 };
|
object o = { BOLDER, ctx->x, ctx->y, ctx->r, 0, 0 };
|
||||||
g_array_append_val(ctx->tm->objects, o);
|
g_array_append_val(ctx->tm->objects, o);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 28:
|
case 28:
|
||||||
#line 89 "control_parser.rl"
|
#line 97 "control_parser.rl"
|
||||||
{
|
{
|
||||||
object o = { CRATER, ctx->x, ctx->y, ctx->r, 0, 0 };
|
object o = { CRATER, ctx->x, ctx->y, ctx->r, 0, 0 };
|
||||||
g_array_append_val(ctx->tm->objects, o);
|
g_array_append_val(ctx->tm->objects, o);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 29:
|
case 29:
|
||||||
#line 94 "control_parser.rl"
|
#line 102 "control_parser.rl"
|
||||||
{
|
{
|
||||||
object o = { MARTIAN, ctx->x, ctx->y, ctx->r, ctx->dir, ctx->speed };
|
object o = { MARTIAN, ctx->x, ctx->y, ctx->r, ctx->dir, ctx->speed };
|
||||||
g_array_append_val(ctx->tm->objects, o);
|
g_array_append_val(ctx->tm->objects, o);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#line 513 "control_parser.c"
|
#line 521 "control_parser.c"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,7 +529,7 @@ _again:
|
|||||||
_test_eof: {}
|
_test_eof: {}
|
||||||
_out: {}
|
_out: {}
|
||||||
}
|
}
|
||||||
#line 161 "control_parser.rl"
|
#line 169 "control_parser.rl"
|
||||||
|
|
||||||
ctx->pos = p - ctx->buffer->str;
|
ctx->pos = p - ctx->buffer->str;
|
||||||
if (ctx->mark == -1) {
|
if (ctx->mark == -1) {
|
||||||
|
@ -36,12 +36,20 @@ static timestamp extract_ts(context *ctx, char *fpc) {
|
|||||||
action telemetrystart { ctx->tm = telemetry_new(); }
|
action telemetrystart { ctx->tm = telemetry_new(); }
|
||||||
action telemetrystop {
|
action telemetrystop {
|
||||||
g_queue_push_tail(&t->telemetry, ctx->tm);
|
g_queue_push_tail(&t->telemetry, ctx->tm);
|
||||||
|
if (!t->alive) {
|
||||||
|
t->vehicle.accel = ctx->tm->vehicle.accel;
|
||||||
|
t->vehicle.turn = ctx->tm->vehicle.turn;
|
||||||
|
}
|
||||||
t->last_ts = ctx->tm->ts;
|
t->last_ts = ctx->tm->ts;
|
||||||
ctx->tm = NULL;
|
ctx->tm = NULL;
|
||||||
t->alive = 1;
|
t->alive = 1;
|
||||||
}
|
}
|
||||||
action vehicle {
|
action vehicle {
|
||||||
ctx->tm->ts = ctx->ts;
|
ctx->tm->ts = ctx->ts;
|
||||||
|
ctx->tm->vehicle.x = ctx->x;
|
||||||
|
ctx->tm->vehicle.y = ctx->y;
|
||||||
|
ctx->tm->vehicle.dir = ctx->dir;
|
||||||
|
ctx->tm->vehicle.speed = ctx->speed;
|
||||||
t->vehicle.x = ctx->x;
|
t->vehicle.x = ctx->x;
|
||||||
t->vehicle.y = ctx->y;
|
t->vehicle.y = ctx->y;
|
||||||
t->vehicle.dir = ctx->dir;
|
t->vehicle.dir = ctx->dir;
|
||||||
@ -155,7 +163,7 @@ run_t control_parse(trial *t) {
|
|||||||
|
|
||||||
p = ctx->buffer->str + ctx->pos;
|
p = ctx->buffer->str + ctx->pos;
|
||||||
pe = p + wehave;
|
pe = p + wehave;
|
||||||
fprintf(stderr, "Parsing '%s' (len=%zu)\n", p, wehave);
|
/* fprintf(stderr, "Parsing '%s' (len=%zu)\n", p, wehave); */
|
||||||
|
|
||||||
%% write exec;
|
%% write exec;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user