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

This commit is contained in:
Johannes Reinhardt 2008-07-12 03:47:54 +02:00
commit 3c6f6f92f8
2 changed files with 186 additions and 114 deletions

View File

@ -14,7 +14,7 @@ static void extract(context *ctx, char *fpc) {
g_string_truncate(ctx->tmp, 0); g_string_truncate(ctx->tmp, 0);
g_string_append_len(ctx->tmp, ctx->buffer->str + ctx->mark, len); g_string_append_len(ctx->tmp, ctx->buffer->str + ctx->mark, len);
ctx->mark = -1; ctx->mark = -1;
printf("Read chunk '%s'\n", ctx->tmp->str); /* printf("Read chunk '%s'\n", ctx->tmp->str); */
} }
static double extract_double(context *ctx, char *fpc) { static double extract_double(context *ctx, char *fpc) {
@ -27,7 +27,7 @@ static timestamp extract_ts(context *ctx, char *fpc) {
return atoi(ctx->tmp->str); return atoi(ctx->tmp->str);
} }
#line 101 "control_parser.rl" #line 113 "control_parser.rl"
@ -39,25 +39,28 @@ static const char _control_parser_actions[] = {
11, 1, 12, 1, 13, 1, 14, 1, 11, 1, 12, 1, 13, 1, 14, 1,
15, 1, 16, 1, 17, 1, 18, 1, 15, 1, 16, 1, 17, 1, 18, 1,
19, 1, 20, 1, 21, 1, 22, 1, 19, 1, 20, 1, 21, 1, 22, 1,
23, 1, 24, 1, 25, 1, 26, 2, 23, 1, 24, 1, 25, 1, 26, 1,
1, 5, 2, 1, 6, 2, 1, 7, 27, 1, 28, 1, 29, 2, 1, 5,
2, 1, 8, 2, 1, 9, 2, 1, 2, 1, 6, 2, 1, 7, 2, 1,
10, 2, 1, 11, 2, 1, 12, 2, 8, 2, 1, 9, 2, 1, 10, 2,
1, 13, 2, 1, 14, 2, 1, 15, 1, 11, 2, 1, 12, 2, 1, 13,
2, 1, 16, 2, 1, 25, 2, 1, 2, 1, 14, 2, 1, 15, 2, 1,
26, 2, 3, 2 16, 2, 1, 25, 2, 1, 26, 2,
3, 2
}; };
static const unsigned char _control_parser_key_offsets[] = { static const short _control_parser_key_offsets[] = {
0, 0, 1, 2, 7, 12, 17, 22, 0, 0, 1, 2, 7, 12, 17, 22,
27, 32, 37, 42, 43, 49, 50, 53, 27, 32, 37, 42, 43, 49, 50, 53,
56, 57, 60, 61, 62, 63, 66, 69, 56, 57, 60, 61, 62, 63, 66, 69,
70, 73, 76, 79, 80, 83, 86, 91, 70, 73, 76, 79, 80, 83, 86, 91,
92, 97, 102, 107, 112, 117, 123, 124, 92, 97, 102, 107, 112, 117, 123, 124,
129, 134, 139, 144, 145, 150, 155, 160, 129, 134, 139, 144, 145, 150, 155, 160,
165, 169, 173, 177, 181, 185, 189, 193, 165, 166, 171, 176, 181, 186, 187, 192,
197, 201, 205, 209, 212, 216, 220, 224, 197, 202, 207, 212, 216, 220, 224, 228,
228, 232, 236, 240, 244 232, 236, 240, 244, 248, 252, 256, 260,
264, 268, 272, 276, 280, 283, 287, 291,
295, 299, 303, 307, 311, 315
}; };
static const char _control_parser_trans_keys[] = { static const char _control_parser_trans_keys[] = {
@ -75,23 +78,32 @@ static const char _control_parser_trans_keys[] = {
82, 108, 114, 32, 32, 45, 46, 48, 82, 108, 114, 32, 32, 45, 46, 48,
57, 32, 45, 46, 48, 57, 32, 45, 57, 32, 45, 46, 48, 57, 32, 45,
46, 48, 57, 32, 45, 46, 48, 57, 46, 48, 57, 32, 45, 46, 48, 57,
59, 104, 109, 98, 99, 66, 67, 69, 59, 98, 99, 104, 109, 66, 67, 69,
75, 83, 84, 32, 32, 45, 46, 48, 75, 83, 84, 32, 32, 45, 46, 48,
57, 32, 45, 46, 48, 57, 32, 45, 57, 32, 45, 46, 48, 57, 32, 45,
46, 48, 57, 59, 104, 109, 98, 99, 46, 48, 57, 59, 98, 99, 104, 109,
32, 32, 45, 46, 48, 57, 32, 45, 32, 32, 45, 46, 48, 57, 32, 45,
46, 48, 57, 32, 45, 46, 48, 57, 46, 48, 57, 32, 45, 46, 48, 57,
32, 45, 46, 48, 57, 32, 46, 48, 59, 98, 99, 104, 109, 32, 32, 45,
57, 32, 46, 48, 57, 32, 46, 48, 46, 48, 57, 32, 45, 46, 48, 57,
57, 32, 46, 48, 57, 32, 46, 48, 32, 45, 46, 48, 57, 59, 98, 99,
57, 32, 46, 48, 57, 32, 46, 48, 104, 109, 32, 32, 45, 46, 48, 57,
57, 32, 46, 48, 57, 32, 46, 48, 32, 45, 46, 48, 57, 32, 45, 46,
57, 32, 46, 48, 57, 32, 46, 48, 48, 57, 32, 45, 46, 48, 57, 59,
57, 32, 48, 57, 32, 46, 48, 57, 98, 99, 104, 109, 32, 46, 48, 57,
32, 46, 48, 57, 32, 46, 48, 57, 32, 46, 48, 57, 32, 46, 48, 57,
32, 46, 48, 57, 32, 46, 48, 57, 32, 46, 48, 57, 32, 46, 48, 57,
32, 46, 48, 57, 32, 46, 48, 57, 32, 46, 48, 57, 32, 46, 48, 57,
32, 46, 48, 57, 0 32, 46, 48, 57, 32, 46, 48, 57,
32, 46, 48, 57, 32, 46, 48, 57,
32, 46, 48, 57, 32, 46, 48, 57,
32, 46, 48, 57, 32, 46, 48, 57,
32, 46, 48, 57, 32, 46, 48, 57,
32, 48, 57, 32, 46, 48, 57, 32,
46, 48, 57, 32, 46, 48, 57, 32,
46, 48, 57, 32, 46, 48, 57, 32,
46, 48, 57, 32, 46, 48, 57, 32,
46, 48, 57, 0
}; };
static const char _control_parser_single_lengths[] = { static const char _control_parser_single_lengths[] = {
@ -99,11 +111,13 @@ static const char _control_parser_single_lengths[] = {
1, 1, 1, 1, 6, 1, 1, 1, 1, 1, 1, 1, 6, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 3, 5, 1, 1, 1, 1, 1, 1, 3, 5, 1,
1, 1, 1, 1, 3, 6, 1, 1, 1, 1, 1, 1, 5, 6, 1, 1,
1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 5,
1, 1, 1, 1, 5, 1, 1, 1,
1, 1, 5, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2,
2, 2, 2, 2, 0 2, 2, 2, 2, 2, 0
}; };
static const char _control_parser_range_lengths[] = { static const char _control_parser_range_lengths[] = {
@ -111,11 +125,13 @@ static const char _control_parser_range_lengths[] = {
2, 2, 2, 0, 0, 0, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1,
0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0,
1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0,
2, 2, 2, 2, 1, 0, 0, 2, 2, 2, 2, 2, 0, 0, 0, 2,
2, 2, 1, 0, 2, 2, 2, 2, 2, 2, 0, 0, 2, 2, 2, 0,
0, 2, 2, 2, 0, 0, 2, 2,
2, 2, 0, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 0 1, 1, 1, 1, 1, 0
}; };
static const short _control_parser_index_offsets[] = { static const short _control_parser_index_offsets[] = {
@ -123,69 +139,89 @@ static const short _control_parser_index_offsets[] = {
24, 28, 32, 36, 38, 45, 47, 50, 24, 28, 32, 36, 38, 45, 47, 50,
53, 55, 58, 60, 62, 64, 67, 70, 53, 55, 58, 60, 62, 64, 67, 70,
72, 75, 78, 81, 83, 86, 90, 96, 72, 75, 78, 81, 83, 86, 90, 96,
98, 102, 106, 110, 114, 119, 126, 128, 98, 102, 106, 110, 114, 120, 127, 129,
132, 136, 140, 145, 147, 151, 155, 159, 133, 137, 141, 147, 149, 153, 157, 161,
163, 167, 171, 175, 179, 183, 187, 191, 167, 169, 173, 177, 181, 187, 189, 193,
195, 199, 203, 207, 210, 214, 218, 222, 197, 201, 205, 211, 215, 219, 223, 227,
226, 230, 234, 238, 242 231, 235, 239, 243, 247, 251, 255, 259,
263, 267, 271, 275, 279, 282, 286, 290,
294, 298, 302, 306, 310, 314
}; };
static const char _control_parser_trans_targs[] = { static const char _control_parser_trans_targs[] = {
2, 0, 3, 0, 4, 67, 67, 0, 2, 0, 3, 0, 4, 84, 84, 0,
5, 66, 66, 0, 6, 65, 65, 0, 5, 83, 83, 0, 6, 82, 82, 0,
7, 64, 64, 0, 8, 63, 63, 0, 7, 81, 81, 0, 8, 80, 80, 0,
9, 62, 62, 0, 10, 61, 61, 0, 9, 79, 79, 0, 10, 78, 78, 0,
11, 60, 60, 0, 12, 0, 13, 16, 11, 77, 77, 0, 12, 0, 13, 16,
20, 16, 16, 27, 0, 14, 0, 11, 20, 16, 16, 27, 0, 14, 0, 11,
15, 0, 11, 15, 0, 17, 0, 18, 15, 0, 11, 15, 0, 17, 0, 18,
26, 0, 19, 0, 20, 0, 21, 0, 26, 0, 19, 0, 20, 0, 21, 0,
22, 25, 0, 23, 24, 0, 68, 0, 22, 25, 0, 23, 24, 0, 85, 0,
23, 24, 0, 22, 25, 0, 18, 26, 23, 24, 0, 22, 25, 0, 18, 26,
0, 28, 0, 29, 59, 0, 30, 30, 0, 28, 0, 29, 76, 0, 30, 30,
30, 0, 31, 31, 31, 31, 31, 0, 30, 0, 31, 31, 31, 31, 31, 0,
32, 0, 33, 58, 58, 0, 34, 57, 32, 0, 33, 75, 75, 0, 34, 74,
57, 0, 35, 56, 56, 0, 36, 55, 74, 0, 35, 73, 73, 0, 36, 72,
55, 0, 37, 38, 43, 38, 0, 13, 72, 0, 37, 38, 43, 48, 53, 0,
16, 20, 16, 16, 27, 0, 39, 0, 13, 16, 20, 16, 16, 27, 0, 39,
40, 54, 54, 0, 41, 53, 53, 0, 0, 40, 71, 71, 0, 41, 70, 70,
42, 52, 52, 0, 37, 38, 43, 38, 0, 42, 69, 69, 0, 37, 38, 43,
0, 44, 0, 45, 51, 51, 0, 46, 48, 53, 0, 44, 0, 45, 68, 68,
50, 50, 0, 47, 49, 49, 0, 42, 0, 46, 67, 67, 0, 47, 66, 66,
48, 48, 0, 42, 48, 48, 0, 47, 0, 37, 38, 43, 48, 53, 0, 49,
49, 49, 0, 46, 50, 50, 0, 45, 0, 50, 65, 65, 0, 51, 64, 64,
51, 51, 0, 42, 52, 52, 0, 41, 0, 52, 63, 63, 0, 37, 38, 43,
53, 53, 0, 40, 54, 54, 0, 36, 48, 53, 0, 54, 0, 55, 62, 62,
55, 55, 0, 35, 56, 56, 0, 34, 0, 56, 61, 61, 0, 57, 60, 60,
57, 57, 0, 33, 58, 58, 0, 29, 0, 58, 59, 59, 0, 37, 38, 43,
59, 0, 11, 60, 60, 0, 10, 61, 48, 53, 0, 58, 59, 59, 0, 57,
61, 0, 9, 62, 62, 0, 8, 63, 60, 60, 0, 56, 61, 61, 0, 55,
63, 0, 7, 64, 64, 0, 6, 65, 62, 62, 0, 52, 63, 63, 0, 51,
65, 0, 5, 66, 66, 0, 4, 67, 64, 64, 0, 50, 65, 65, 0, 47,
67, 0, 0, 0 66, 66, 0, 46, 67, 67, 0, 45,
68, 68, 0, 42, 69, 69, 0, 41,
70, 70, 0, 40, 71, 71, 0, 36,
72, 72, 0, 35, 73, 73, 0, 34,
74, 74, 0, 33, 75, 75, 0, 29,
76, 0, 11, 77, 77, 0, 10, 78,
78, 0, 9, 79, 79, 0, 8, 80,
80, 0, 7, 81, 81, 0, 6, 82,
82, 0, 5, 83, 83, 0, 4, 84,
84, 0, 0, 0
}; };
static const char _control_parser_trans_actions[] = { static const char _control_parser_trans_actions[] = {
0, 0, 0, 0, 55, 3, 3, 0, 0, 0, 0, 0, 61, 3, 3, 0,
58, 3, 3, 0, 0, 0, 0, 0, 64, 3, 3, 0, 0, 0, 0, 0,
61, 3, 3, 0, 64, 3, 3, 0,
67, 3, 3, 0, 70, 3, 3, 0, 67, 3, 3, 0, 70, 3, 3, 0,
73, 3, 3, 0, 0, 0, 0, 0, 73, 3, 3, 0, 76, 3, 3, 0,
0, 0, 0, 5, 0, 0, 0, 91, 79, 3, 3, 0, 0, 0, 0, 0,
3, 0, 51, 0, 0, 0, 0, 91, 0, 0, 0, 5, 0, 0, 0, 97,
3, 0, 51, 0, 0, 0, 0, 97,
3, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0,
91, 3, 0, 94, 3, 0, 1, 0, 97, 3, 0, 100, 3, 0, 1, 0,
53, 0, 0, 51, 0, 0, 51, 0, 53, 0, 0, 51, 0, 0, 51, 0,
0, 0, 0, 91, 3, 0, 37, 35, 0, 0, 0, 97, 3, 0, 37, 35,
39, 0, 45, 41, 49, 43, 47, 0, 39, 0, 45, 41, 49, 43, 47, 0,
0, 0, 76, 3, 3, 0, 79, 3, 0, 0, 82, 3, 3, 0, 85, 3,
3, 0, 85, 3, 3, 0, 88, 3, 3, 0, 91, 3, 3, 0, 94, 3,
3, 0, 9, 9, 9, 9, 0, 7, 3, 0, 9, 9, 9, 9, 9, 0,
7, 7, 7, 7, 97, 0, 0, 0, 7, 7, 7, 7, 7, 103, 0, 0,
76, 3, 3, 0, 79, 3, 3, 0, 0, 82, 3, 3, 0, 85, 3, 3,
82, 3, 3, 0, 0, 0, 0, 0, 0, 88, 3, 3, 0, 55, 55, 55,
0, 0, 0, 76, 3, 3, 0, 79, 55, 55, 0, 0, 0, 82, 3, 3,
3, 3, 0, 85, 3, 3, 0, 88, 0, 85, 3, 3, 0, 88, 3, 3,
3, 3, 0, 33, 0, 0, 0, 31, 0, 57, 57, 57, 57, 57, 0, 0,
0, 82, 3, 3, 0, 85, 3, 3,
0, 88, 3, 3, 0, 0, 0, 0,
0, 0, 0, 0, 0, 82, 3, 3,
0, 85, 3, 3, 0, 91, 3, 3,
0, 94, 3, 3, 0, 59, 59, 59,
59, 59, 0, 33, 0, 0, 0, 31,
0, 0, 0, 27, 0, 0, 0, 25,
0, 0, 0, 29, 0, 0, 0, 27,
0, 0, 0, 25, 0, 0, 0, 29,
0, 0, 0, 27, 0, 0, 0, 25, 0, 0, 0, 27, 0, 0, 0, 25,
0, 0, 0, 29, 0, 0, 0, 27, 0, 0, 0, 29, 0, 0, 0, 27,
0, 0, 0, 25, 0, 0, 0, 33, 0, 0, 0, 25, 0, 0, 0, 33,
@ -199,12 +235,12 @@ static const char _control_parser_trans_actions[] = {
}; };
static const int control_parser_start = 1; static const int control_parser_start = 1;
static const int control_parser_first_final = 68; static const int control_parser_first_final = 85;
static const int control_parser_error = 0; static const int control_parser_error = 0;
static const int control_parser_en_main = 1; static const int control_parser_en_main = 1;
#line 104 "control_parser.rl" #line 116 "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;
@ -217,11 +253,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 221 "control_parser.c" #line 257 "control_parser.c"
{ {
( ctx->cs) = control_parser_start; ( ctx->cs) = control_parser_start;
} }
#line 116 "control_parser.rl" #line 128 "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;
@ -231,11 +267,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 235 "control_parser.c" #line 271 "control_parser.c"
{ {
( ctx->cs) = control_parser_start; ( ctx->cs) = control_parser_start;
} }
#line 125 "control_parser.rl" #line 137 "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;
@ -259,7 +295,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 263 "control_parser.c" #line 299 "control_parser.c"
{ {
int _klen; int _klen;
unsigned int _trans; unsigned int _trans;
@ -355,100 +391,124 @@ _match:
case 4: case 4:
#line 42 "control_parser.rl" #line 42 "control_parser.rl"
{ {
ctx->tm->ts = ctx->ts;
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.speed = ctx->speed;
printf("Vehicle at %f / %f\n", ctx->x, ctx->y); printf("Vehicle at %f / %f\n", ctx->x, ctx->y);
} }
break; break;
case 5: case 5:
#line 52 "control_parser.rl" #line 55 "control_parser.rl"
{ t->map.dx = extract_double(ctx, p); } { t->map.dx = extract_double(ctx, p); }
break; break;
case 6: case 6:
#line 53 "control_parser.rl" #line 56 "control_parser.rl"
{ t->map.dy = extract_double(ctx, p); } { t->map.dy = extract_double(ctx, p); }
break; break;
case 7: case 7:
#line 54 "control_parser.rl" #line 57 "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 55 "control_parser.rl" #line 58 "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 56 "control_parser.rl" #line 59 "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 57 "control_parser.rl" #line 60 "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 58 "control_parser.rl" #line 61 "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 62 "control_parser.rl" #line 65 "control_parser.rl"
{ ctx->x = extract_double(ctx, p); } { ctx->x = extract_double(ctx, p); }
break; break;
case 13: case 13:
#line 63 "control_parser.rl" #line 66 "control_parser.rl"
{ ctx->y = extract_double(ctx, p); } { ctx->y = extract_double(ctx, p); }
break; break;
case 14: case 14:
#line 64 "control_parser.rl" #line 67 "control_parser.rl"
{ ctx->r = extract_double(ctx, p); } { ctx->r = extract_double(ctx, p); }
break; break;
case 15: case 15:
#line 65 "control_parser.rl" #line 68 "control_parser.rl"
{ ctx->dir = extract_double(ctx, p); } { ctx->dir = extract_double(ctx, p); }
break; break;
case 16: case 16:
#line 66 "control_parser.rl" #line 69 "control_parser.rl"
{ ctx->speed = extract_double(ctx, p); } { ctx->speed = extract_double(ctx, p); }
break; break;
case 17: case 17:
#line 68 "control_parser.rl" #line 71 "control_parser.rl"
{ ctx->tm->vehicle.accel = ACCEL; } { ctx->tm->vehicle.accel = ACCEL; }
break; break;
case 18: case 18:
#line 69 "control_parser.rl" #line 72 "control_parser.rl"
{ ctx->tm->vehicle.accel = ROLL; } { ctx->tm->vehicle.accel = ROLL; }
break; break;
case 19: case 19:
#line 70 "control_parser.rl" #line 73 "control_parser.rl"
{ ctx->tm->vehicle.accel = BREAK; } { ctx->tm->vehicle.accel = BREAK; }
break; break;
case 20: case 20:
#line 72 "control_parser.rl" #line 75 "control_parser.rl"
{ ctx->tm->vehicle.turn = TURN_HARD_LEFT; } { ctx->tm->vehicle.turn = TURN_HARD_LEFT; }
break; break;
case 21: case 21:
#line 73 "control_parser.rl" #line 76 "control_parser.rl"
{ ctx->tm->vehicle.turn = TURN_LEFT; } { ctx->tm->vehicle.turn = TURN_LEFT; }
break; break;
case 22: case 22:
#line 74 "control_parser.rl" #line 77 "control_parser.rl"
{ ctx->tm->vehicle.turn = TURN_STRAIGHT; } { ctx->tm->vehicle.turn = TURN_STRAIGHT; }
break; break;
case 23: case 23:
#line 75 "control_parser.rl" #line 78 "control_parser.rl"
{ ctx->tm->vehicle.turn = TURN_RIGHT; } { ctx->tm->vehicle.turn = TURN_RIGHT; }
break; break;
case 24: case 24:
#line 76 "control_parser.rl" #line 79 "control_parser.rl"
{ ctx->tm->vehicle.turn = TURN_HARD_RIGHT; } { ctx->tm->vehicle.turn = TURN_HARD_RIGHT; }
break; break;
case 25: case 25:
#line 78 "control_parser.rl" #line 81 "control_parser.rl"
{ ctx->ts = extract_ts(ctx, p); } { ctx->ts = extract_ts(ctx, p); }
break; break;
case 26: case 26:
#line 79 "control_parser.rl" #line 82 "control_parser.rl"
{ printf("Score %u\n", extract_ts(ctx, p)); } { printf("Score %u\n", extract_ts(ctx, p)); }
break; break;
#line 452 "control_parser.c" case 27:
#line 84 "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 88 "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 93 "control_parser.rl"
{
object o = { MARTIAN, ctx->x, ctx->y, ctx->r, ctx->dir, ctx->speed };
g_array_append_val(ctx->tm->objects, o);
}
break;
#line 512 "control_parser.c"
} }
} }
@ -460,7 +520,7 @@ _again:
_test_eof: {} _test_eof: {}
_out: {} _out: {}
} }
#line 148 "control_parser.rl" #line 160 "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

@ -13,7 +13,7 @@ static void extract(context *ctx, char *fpc) {
g_string_truncate(ctx->tmp, 0); g_string_truncate(ctx->tmp, 0);
g_string_append_len(ctx->tmp, ctx->buffer->str + ctx->mark, len); g_string_append_len(ctx->tmp, ctx->buffer->str + ctx->mark, len);
ctx->mark = -1; ctx->mark = -1;
printf("Read chunk '%s'\n", ctx->tmp->str); /* printf("Read chunk '%s'\n", ctx->tmp->str); */
} }
static double extract_double(context *ctx, char *fpc) { static double extract_double(context *ctx, char *fpc) {
@ -40,8 +40,11 @@ static timestamp extract_ts(context *ctx, char *fpc) {
t->alive = 1; t->alive = 1;
} }
action vehicle { action vehicle {
ctx->tm->ts = ctx->ts;
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.speed = ctx->speed;
printf("Vehicle at %f / %f\n", ctx->x, ctx->y); printf("Vehicle at %f / %f\n", ctx->x, ctx->y);
} }
@ -78,10 +81,19 @@ static timestamp extract_ts(context *ctx, char *fpc) {
timestamp = (digit*) >mark % { ctx->ts = extract_ts(ctx, fpc); }; timestamp = (digit*) >mark % { ctx->ts = extract_ts(ctx, fpc); };
score = (digit*) >mark % { printf("Score %u\n", extract_ts(ctx, fpc)); }; score = (digit*) >mark % { printf("Score %u\n", extract_ts(ctx, fpc)); };
boulder = "b" SP x SP y SP r SP; boulder = "b" SP x SP y SP r SP % {
crater = "c" SP x SP y SP r SP; object o = { BOLDER, ctx->x, ctx->y, ctx->r, 0, 0 };
homebase = "h" SP x SP y SP r SP; g_array_append_val(ctx->tm->objects, o);
martian = "m" SP x SP y SP dir SP speed SP; };
crater = "c" SP x SP y SP r SP % {
object o = { CRATER, ctx->x, ctx->y, ctx->r, 0, 0 };
g_array_append_val(ctx->tm->objects, o);
};
homebase = "h" SP x SP y SP r SP; # ignore it
martian = "m" SP x SP y SP dir SP speed SP % {
object o = { MARTIAN, ctx->x, ctx->y, ctx->r, ctx->dir, ctx->speed };
g_array_append_val(ctx->tm->objects, o);
};
object = boulder | crater | homebase | martian; object = boulder | crater | homebase | martian;
objects = object*; objects = object*;
telemetry = ( ("T" SP timestamp SP ctl SP x SP y SP dir SP speed SP) %vehicle objects) >telemetrystart ";" % telemetrystop; telemetry = ( ("T" SP timestamp SP ctl SP x SP y SP dir SP speed SP) %vehicle objects) >telemetrystart ";" % telemetrystop;