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

This commit is contained in:
Johannes Reinhardt 2008-07-12 11:33:03 +02:00
commit 656e3f7a77
4 changed files with 225 additions and 203 deletions

View File

@ -27,7 +27,7 @@ static timestamp extract_ts(context *ctx, char *fpc) {
return atoi(ctx->tmp->str);
}
#line 125 "control_parser.rl"
#line 130 "control_parser.rl"
@ -50,188 +50,191 @@ static const char _control_parser_actions[] = {
};
static const short _control_parser_key_offsets[] = {
0, 0, 1, 2, 7, 12, 17, 22,
27, 32, 37, 42, 43, 49, 50, 53,
56, 57, 60, 61, 62, 63, 66, 69,
70, 73, 76, 79, 80, 83, 86, 91,
92, 97, 102, 107, 112, 117, 123, 124,
129, 134, 139, 144, 145, 150, 155, 160,
165, 166, 171, 176, 181, 186, 187, 192,
197, 202, 207, 212, 216, 220, 224, 228,
232, 236, 240, 244, 248, 252, 256, 260,
264, 268, 272, 276, 280, 283, 287, 291,
295, 299, 303, 307, 311, 315
0, 0, 7, 8, 11, 12, 18, 19,
22, 23, 24, 25, 28, 31, 32, 35,
38, 41, 42, 45, 48, 53, 54, 59,
64, 69, 74, 79, 85, 86, 91, 96,
101, 106, 107, 112, 117, 122, 127, 128,
133, 138, 143, 148, 149, 154, 159, 164,
169, 174, 178, 182, 186, 190, 194, 198,
202, 206, 210, 214, 218, 222, 226, 230,
234, 238, 242, 245, 248, 249, 254, 259,
264, 269, 274, 279, 284, 289, 293, 297,
301, 305, 309, 313, 317, 321
};
static const char _control_parser_trans_keys[] = {
73, 32, 32, 45, 46, 48, 57, 32,
45, 46, 48, 57, 32, 45, 46, 48,
57, 32, 45, 46, 48, 57, 32, 45,
66, 67, 69, 73, 75, 83, 84, 32,
32, 48, 57, 59, 66, 67, 69, 75,
83, 84, 32, 32, 48, 57, 59, 69,
32, 32, 48, 57, 32, 48, 57, 59,
32, 48, 57, 32, 48, 57, 32, 48,
57, 32, 32, 48, 57, 45, 97, 98,
45, 76, 82, 108, 114, 32, 32, 45,
46, 48, 57, 32, 45, 46, 48, 57,
32, 45, 46, 48, 57, 32, 45, 46,
48, 57, 59, 66, 67, 69, 75, 83,
84, 32, 32, 48, 57, 32, 48, 57,
32, 32, 48, 57, 59, 69, 32, 32,
48, 57, 32, 48, 57, 59, 32, 48,
57, 32, 48, 57, 32, 48, 57, 32,
32, 48, 57, 45, 97, 98, 45, 76,
82, 108, 114, 32, 32, 45, 46, 48,
57, 32, 45, 46, 48, 57, 32, 45,
46, 48, 57, 32, 45, 46, 48, 57,
59, 98, 99, 104, 109, 66, 67, 69,
75, 83, 84, 32, 32, 45, 46, 48,
57, 32, 45, 46, 48, 57, 32, 45,
46, 48, 57, 59, 98, 99, 104, 109,
32, 32, 45, 46, 48, 57, 32, 45,
46, 48, 57, 32, 45, 46, 48, 57,
59, 98, 99, 104, 109, 32, 32, 45,
48, 57, 59, 98, 99, 104, 109, 66,
67, 69, 75, 83, 84, 32, 32, 45,
46, 48, 57, 32, 45, 46, 48, 57,
32, 45, 46, 48, 57, 59, 98, 99,
104, 109, 32, 32, 45, 46, 48, 57,
32, 45, 46, 48, 57, 32, 45, 46,
48, 57, 59, 98, 99, 104, 109, 32,
32, 45, 46, 48, 57, 32, 45, 46,
48, 57, 32, 45, 46, 48, 57, 59,
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, 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
98, 99, 104, 109, 32, 32, 45, 46,
48, 57, 32, 45, 46, 48, 57, 32,
45, 46, 48, 57, 32, 45, 46, 48,
57, 59, 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, 32, 46,
48, 57, 32, 46, 48, 57, 32, 46,
48, 57, 32, 48, 57, 32, 48, 57,
32, 32, 45, 46, 48, 57, 32, 45,
46, 48, 57, 32, 45, 46, 48, 57,
32, 45, 46, 48, 57, 32, 45, 46,
48, 57, 32, 45, 46, 48, 57, 32,
45, 46, 48, 57, 32, 45, 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
};
static const char _control_parser_single_lengths[] = {
0, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 6, 1, 1, 1,
0, 7, 1, 1, 1, 6, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 3, 5, 1,
1, 1, 1, 1, 5, 6, 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,
1, 1, 1, 3, 5, 1, 1, 1,
1, 1, 5, 6, 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, 1, 2, 2, 2,
2, 2, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 2, 2, 2,
2, 2, 2, 2, 2, 0
};
static const char _control_parser_range_lengths[] = {
0, 0, 0, 2, 2, 2, 2, 2,
2, 2, 2, 0, 0, 0, 1, 1,
0, 1, 0, 0, 0, 1, 1, 0,
1, 1, 1, 0, 1, 0, 0, 0,
2, 2, 2, 2, 0, 0, 0, 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,
0, 0, 0, 1, 0, 0, 0, 1,
0, 0, 0, 1, 1, 0, 1, 1,
1, 0, 1, 0, 0, 0, 2, 2,
2, 2, 0, 0, 0, 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, 0, 2, 2, 2,
2, 2, 2, 2, 2, 1, 1, 1,
1, 1, 1, 1, 1, 0
};
static const short _control_parser_index_offsets[] = {
0, 0, 2, 4, 8, 12, 16, 20,
24, 28, 32, 36, 38, 45, 47, 50,
53, 55, 58, 60, 62, 64, 67, 70,
72, 75, 78, 81, 83, 86, 90, 96,
98, 102, 106, 110, 114, 120, 127, 129,
133, 137, 141, 147, 149, 153, 157, 161,
167, 169, 173, 177, 181, 187, 189, 193,
197, 201, 205, 211, 215, 219, 223, 227,
231, 235, 239, 243, 247, 251, 255, 259,
263, 267, 271, 275, 279, 282, 286, 290,
294, 298, 302, 306, 310, 314
0, 0, 8, 10, 13, 15, 22, 24,
27, 29, 31, 33, 36, 39, 41, 44,
47, 50, 52, 55, 59, 65, 67, 71,
75, 79, 83, 89, 96, 98, 102, 106,
110, 116, 118, 122, 126, 130, 136, 138,
142, 146, 150, 156, 158, 162, 166, 170,
174, 180, 184, 188, 192, 196, 200, 204,
208, 212, 216, 220, 224, 228, 232, 236,
240, 244, 248, 251, 254, 256, 260, 264,
268, 272, 276, 280, 284, 288, 292, 296,
300, 304, 308, 312, 316, 320
};
static const char _control_parser_trans_targs[] = {
2, 0, 3, 0, 4, 84, 84, 0,
5, 83, 83, 0, 6, 82, 82, 0,
7, 81, 81, 0, 8, 80, 80, 0,
9, 79, 79, 0, 10, 78, 78, 0,
11, 77, 77, 0, 12, 0, 13, 16,
20, 16, 16, 27, 0, 14, 0, 11,
15, 0, 11, 15, 0, 17, 0, 18,
26, 0, 19, 0, 20, 0, 21, 0,
22, 25, 0, 23, 24, 0, 85, 0,
23, 24, 0, 22, 25, 0, 18, 26,
0, 28, 0, 29, 76, 0, 30, 30,
30, 0, 31, 31, 31, 31, 31, 0,
32, 0, 33, 75, 75, 0, 34, 74,
74, 0, 35, 73, 73, 0, 36, 72,
72, 0, 37, 38, 43, 48, 53, 0,
13, 16, 20, 16, 16, 27, 0, 39,
0, 40, 71, 71, 0, 41, 70, 70,
0, 42, 69, 69, 0, 37, 38, 43,
48, 53, 0, 44, 0, 45, 68, 68,
0, 46, 67, 67, 0, 47, 66, 66,
0, 37, 38, 43, 48, 53, 0, 49,
0, 50, 65, 65, 0, 51, 64, 64,
0, 52, 63, 63, 0, 37, 38, 43,
48, 53, 0, 54, 0, 55, 62, 62,
0, 56, 61, 61, 0, 57, 60, 60,
0, 58, 59, 59, 0, 37, 38, 43,
48, 53, 0, 58, 59, 59, 0, 57,
60, 60, 0, 56, 61, 61, 0, 55,
62, 62, 0, 52, 63, 63, 0, 51,
64, 64, 0, 50, 65, 65, 0, 47,
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
2, 6, 10, 68, 6, 6, 17, 0,
3, 0, 4, 67, 0, 5, 0, 2,
6, 10, 6, 6, 17, 0, 7, 0,
8, 16, 0, 9, 0, 10, 0, 11,
0, 12, 15, 0, 13, 14, 0, 85,
0, 13, 14, 0, 12, 15, 0, 8,
16, 0, 18, 0, 19, 66, 0, 20,
20, 20, 0, 21, 21, 21, 21, 21,
0, 22, 0, 23, 65, 65, 0, 24,
64, 64, 0, 25, 63, 63, 0, 26,
62, 62, 0, 27, 28, 33, 38, 43,
0, 2, 6, 10, 6, 6, 17, 0,
29, 0, 30, 61, 61, 0, 31, 60,
60, 0, 32, 59, 59, 0, 27, 28,
33, 38, 43, 0, 34, 0, 35, 58,
58, 0, 36, 57, 57, 0, 37, 56,
56, 0, 27, 28, 33, 38, 43, 0,
39, 0, 40, 55, 55, 0, 41, 54,
54, 0, 42, 53, 53, 0, 27, 28,
33, 38, 43, 0, 44, 0, 45, 52,
52, 0, 46, 51, 51, 0, 47, 50,
50, 0, 48, 49, 49, 0, 27, 28,
33, 38, 43, 0, 48, 49, 49, 0,
47, 50, 50, 0, 46, 51, 51, 0,
45, 52, 52, 0, 42, 53, 53, 0,
41, 54, 54, 0, 40, 55, 55, 0,
37, 56, 56, 0, 36, 57, 57, 0,
35, 58, 58, 0, 32, 59, 59, 0,
31, 60, 60, 0, 30, 61, 61, 0,
26, 62, 62, 0, 25, 63, 63, 0,
24, 64, 64, 0, 23, 65, 65, 0,
19, 66, 0, 4, 67, 0, 69, 0,
70, 84, 84, 0, 71, 83, 83, 0,
72, 82, 82, 0, 73, 81, 81, 0,
74, 80, 80, 0, 75, 79, 79, 0,
76, 78, 78, 0, 4, 77, 77, 0,
4, 77, 77, 0, 76, 78, 78, 0,
75, 79, 79, 0, 74, 80, 80, 0,
73, 81, 81, 0, 72, 82, 82, 0,
71, 83, 83, 0, 70, 84, 84, 0,
0, 0
};
static const char _control_parser_trans_actions[] = {
0, 0, 0, 0, 61, 3, 3, 0,
64, 3, 3, 0, 0, 0, 0, 0,
67, 3, 3, 0, 70, 3, 3, 0,
73, 3, 3, 0, 76, 3, 3, 0,
79, 3, 3, 0, 0, 0, 0, 0,
0, 0, 0, 5, 0, 0, 0, 97,
3, 0, 51, 0, 0, 0, 0, 97,
3, 0, 0, 0, 0, 0, 0, 0,
97, 3, 0, 100, 3, 0, 1, 0,
53, 0, 0, 51, 0, 0, 51, 0,
0, 0, 0, 97, 3, 0, 37, 35,
39, 0, 45, 41, 49, 43, 47, 0,
0, 0, 0, 0, 0, 0, 5, 0,
0, 0, 97, 3, 0, 0, 0, 0,
0, 0, 0, 0, 5, 0, 0, 0,
97, 3, 0, 0, 0, 0, 0, 0,
0, 97, 3, 0, 100, 3, 0, 1,
0, 53, 0, 0, 51, 0, 0, 51,
0, 0, 0, 0, 97, 3, 0, 37,
35, 39, 0, 45, 41, 49, 43, 47,
0, 0, 0, 82, 3, 3, 0, 85,
3, 3, 0, 91, 3, 3, 0, 94,
3, 3, 0, 9, 9, 9, 9, 9,
0, 7, 7, 7, 7, 7, 103, 0,
0, 0, 82, 3, 3, 0, 85, 3,
3, 0, 91, 3, 3, 0, 94, 3,
3, 0, 9, 9, 9, 9, 9, 0,
7, 7, 7, 7, 7, 103, 0, 0,
0, 82, 3, 3, 0, 85, 3, 3,
0, 88, 3, 3, 0, 55, 55, 55,
55, 55, 0, 0, 0, 82, 3, 3,
0, 85, 3, 3, 0, 88, 3, 3,
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, 29, 0, 0, 0, 27,
0, 0, 0, 25, 0, 0, 0, 33,
0, 0, 0, 31, 0, 0, 0, 27,
0, 0, 0, 25, 0, 0, 0, 51,
0, 0, 23, 0, 0, 0, 21, 0,
0, 0, 19, 0, 0, 0, 17, 0,
0, 0, 15, 0, 0, 0, 0, 0,
0, 0, 13, 0, 0, 0, 11, 0,
0, 0, 0, 0
3, 0, 88, 3, 3, 0, 55, 55,
55, 55, 55, 0, 0, 0, 82, 3,
3, 0, 85, 3, 3, 0, 88, 3,
3, 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, 29, 0, 0, 0,
27, 0, 0, 0, 25, 0, 0, 0,
33, 0, 0, 0, 31, 0, 0, 0,
27, 0, 0, 0, 25, 0, 0, 0,
51, 0, 0, 51, 0, 0, 0, 0,
61, 3, 3, 0, 64, 3, 3, 0,
0, 0, 0, 0, 67, 3, 3, 0,
70, 3, 3, 0, 73, 3, 3, 0,
76, 3, 3, 0, 79, 3, 3, 0,
23, 0, 0, 0, 21, 0, 0, 0,
19, 0, 0, 0, 17, 0, 0, 0,
15, 0, 0, 0, 0, 0, 0, 0,
13, 0, 0, 0, 11, 0, 0, 0,
0, 0
};
static const int control_parser_start = 1;
@ -240,7 +243,7 @@ static const int control_parser_error = 0;
static const int control_parser_en_main = 1;
#line 128 "control_parser.rl"
#line 133 "control_parser.rl"
static int control_parser_has_error(context *ctx) {
return ctx->cs == control_parser_error;
@ -253,11 +256,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 257 "control_parser.c"
#line 260 "control_parser.c"
{
( ctx->cs) = control_parser_start;
}
#line 140 "control_parser.rl"
#line 145 "control_parser.rl"
ctx->buffer = g_string_sized_new(0);
ctx->tmp = g_string_sized_new(0);
ctx->mark = -1;
@ -267,14 +270,14 @@ void control_parser_new(trial *t) {
void control_parser_reset(trial *t) {
context *ctx = t->parse_ctx;
#line 271 "control_parser.c"
#line 274 "control_parser.c"
{
( ctx->cs) = control_parser_start;
}
#line 149 "control_parser.rl"
#line 154 "control_parser.rl"
g_string_truncate(ctx->tmp, 0);
ctx->mark = -1;
ctx->pos = 0;
/* fprintf(stderr, "Parser reset\n"); */
}
void control_parser_free(trial *t) {
@ -295,7 +298,7 @@ run_t control_parse(trial *t) {
/* fprintf(stderr, "Parsing '%s' (len=%zu)\n", p, wehave); */
#line 299 "control_parser.c"
#line 302 "control_parser.c"
{
int _klen;
unsigned int _trans;
@ -370,24 +373,29 @@ _match:
{
case 0:
#line 34 "control_parser.rl"
{ {p++; goto _out; } t->alive = 0; }
{
t->alive = 0;
/* fprintf(stderr, "Run finished\n"); */
{p++; goto _out; }
}
break;
case 1:
#line 35 "control_parser.rl"
#line 39 "control_parser.rl"
{ ctx->mark = p - ctx->buffer->str; }
break;
case 2:
#line 36 "control_parser.rl"
#line 40 "control_parser.rl"
{ ctx->tm = telemetry_new(); }
break;
case 3:
#line 37 "control_parser.rl"
#line 41 "control_parser.rl"
{
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;
gettimeofday(&t->started, NULL);
/* fprintf(stderr, "New run\n"); */
} else {
/* fprintf(stderr, "time difference [ms]: %i\n", getcurts(t) - ctx->tm->ts); */
}
@ -397,7 +405,7 @@ _match:
}
break;
case 4:
#line 50 "control_parser.rl"
#line 55 "control_parser.rl"
{
ctx->tm->ts = ctx->ts;
ctx->tm->vehicle.x = ctx->x;
@ -412,115 +420,115 @@ _match:
}
break;
case 5:
#line 67 "control_parser.rl"
#line 72 "control_parser.rl"
{ t->map.dx = extract_double(ctx, p); }
break;
case 6:
#line 68 "control_parser.rl"
#line 73 "control_parser.rl"
{ t->map.dy = extract_double(ctx, p); }
break;
case 7:
#line 69 "control_parser.rl"
#line 74 "control_parser.rl"
{ t->map.min_sensor = extract_double(ctx, p); }
break;
case 8:
#line 70 "control_parser.rl"
#line 75 "control_parser.rl"
{ t->map.max_sensor = extract_double(ctx, p); }
break;
case 9:
#line 71 "control_parser.rl"
#line 76 "control_parser.rl"
{ t->map.max_speed = extract_double(ctx, p); }
break;
case 10:
#line 72 "control_parser.rl"
#line 77 "control_parser.rl"
{ t->map.max_turn = extract_double(ctx, p); }
break;
case 11:
#line 73 "control_parser.rl"
#line 78 "control_parser.rl"
{ t->map.max_hard_turn = extract_double(ctx, p); }
break;
case 12:
#line 77 "control_parser.rl"
#line 82 "control_parser.rl"
{ ctx->x = extract_double(ctx, p); }
break;
case 13:
#line 78 "control_parser.rl"
#line 83 "control_parser.rl"
{ ctx->y = extract_double(ctx, p); }
break;
case 14:
#line 79 "control_parser.rl"
#line 84 "control_parser.rl"
{ ctx->r = extract_double(ctx, p); }
break;
case 15:
#line 80 "control_parser.rl"
#line 85 "control_parser.rl"
{ ctx->dir = extract_double(ctx, p); }
break;
case 16:
#line 81 "control_parser.rl"
#line 86 "control_parser.rl"
{ ctx->speed = extract_double(ctx, p); }
break;
case 17:
#line 83 "control_parser.rl"
#line 88 "control_parser.rl"
{ ctx->tm->vehicle.accel = ACCEL; }
break;
case 18:
#line 84 "control_parser.rl"
#line 89 "control_parser.rl"
{ ctx->tm->vehicle.accel = ROLL; }
break;
case 19:
#line 85 "control_parser.rl"
#line 90 "control_parser.rl"
{ ctx->tm->vehicle.accel = BREAK; }
break;
case 20:
#line 87 "control_parser.rl"
#line 92 "control_parser.rl"
{ ctx->tm->vehicle.turn = TURN_HARD_LEFT; }
break;
case 21:
#line 88 "control_parser.rl"
#line 93 "control_parser.rl"
{ ctx->tm->vehicle.turn = TURN_LEFT; }
break;
case 22:
#line 89 "control_parser.rl"
#line 94 "control_parser.rl"
{ ctx->tm->vehicle.turn = TURN_STRAIGHT; }
break;
case 23:
#line 90 "control_parser.rl"
#line 95 "control_parser.rl"
{ ctx->tm->vehicle.turn = TURN_RIGHT; }
break;
case 24:
#line 91 "control_parser.rl"
#line 96 "control_parser.rl"
{ ctx->tm->vehicle.turn = TURN_HARD_RIGHT; }
break;
case 25:
#line 93 "control_parser.rl"
#line 98 "control_parser.rl"
{ ctx->ts = extract_ts(ctx, p); }
break;
case 26:
#line 94 "control_parser.rl"
#line 99 "control_parser.rl"
{ printf("Score %u\n", extract_ts(ctx, p)); }
break;
case 27:
#line 96 "control_parser.rl"
#line 101 "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 100 "control_parser.rl"
#line 105 "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 105 "control_parser.rl"
#line 110 "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 524 "control_parser.c"
#line 532 "control_parser.c"
}
}
@ -532,7 +540,7 @@ _again:
_test_eof: {}
_out: {}
}
#line 172 "control_parser.rl"
#line 177 "control_parser.rl"
ctx->pos = p - ctx->buffer->str;
if (ctx->mark == -1) {
@ -548,7 +556,7 @@ _again:
}
if (control_parser_has_error(ctx)) {
fprintf(stderr, "Parse error\n");
fprintf(stderr, "Parse error: '%s'\n", ctx->buffer->str + ctx->pos);
shutdown(t->socket, SHUT_RDWR);
close(t->socket);
exit(126);

View File

@ -31,7 +31,11 @@ static timestamp extract_ts(context *ctx, char *fpc) {
machine control_parser;
variable cs ctx->cs;
action done { fbreak; t->alive = 0; }
action done {
t->alive = 0;
/* fprintf(stderr, "Run finished\n"); */
fbreak;
}
action mark { ctx->mark = fpc - ctx->buffer->str; }
action telemetrystart { ctx->tm = telemetry_new(); }
action telemetrystop {
@ -40,6 +44,7 @@ static timestamp extract_ts(context *ctx, char *fpc) {
t->vehicle.accel = ctx->tm->vehicle.accel;
t->vehicle.turn = ctx->tm->vehicle.turn;
gettimeofday(&t->started, NULL);
/* fprintf(stderr, "New run\n"); */
} else {
/* fprintf(stderr, "time difference [ms]: %i\n", getcurts(t) - ctx->tm->ts); */
}
@ -121,7 +126,7 @@ static timestamp extract_ts(context *ctx, char *fpc) {
End = "E" SP timestamp SP score SP ";";
main := init (telemetry | Boulder)* (Crater | Kill | Success)? End @ done;
main := init? (telemetry | Boulder)* (Crater | Kill | Success)? End @ done;
}%%
%% write data;
@ -148,7 +153,7 @@ void control_parser_reset(trial *t) {
%% write init;
g_string_truncate(ctx->tmp, 0);
ctx->mark = -1;
ctx->pos = 0;
/* fprintf(stderr, "Parser reset\n"); */
}
void control_parser_free(trial *t) {
@ -184,7 +189,7 @@ run_t control_parse(trial *t) {
}
if (control_parser_has_error(ctx)) {
fprintf(stderr, "Parse error\n");
fprintf(stderr, "Parse error: '%s'\n", ctx->buffer->str + ctx->pos);
shutdown(t->socket, SHUT_RDWR);
close(t->socket);
exit(126);

View File

@ -15,6 +15,7 @@ void trial_loop(trial *t) {
path_execute(t,p);
if (-1 == trial_check_input(t)) return;
}
trial_reset_run(t);
path_free(p);
} while (!t->finished);
}

View File

@ -16,6 +16,13 @@ void command_free(command* c){
g_slice_free(command, c);
}
double angle_for_rot(double from, double to) {
double a = to - from;
if (a > 180) a = -360 + a;
else if (a < -180) a = 360 + a;
return a;
}
path *path_new(map* m,vehicle *v){
command* tmp;
path* res;
@ -27,23 +34,24 @@ path *path_new(map* m,vehicle *v){
/* Turn towards origin, take shorter direction*/
angle = atan2(-v->y,-v->x)*180/M_PI;
stop = abs(angle - v->dir)/m->max_turn*1000;
angle = angle_for_rot(v->dir, angle);
stop = abs(angle)/m->max_hard_turn*1000;
printf("Angle: %f stop: %f\n",angle,stop);
if(angle - v->dir > 0){
if(angle > 0){
/*clockwise/left turn*/
tmp = command_new(0,BREAK,TURN_LEFT);
tmp = command_new(0,BREAK,TURN_HARD_LEFT);
g_queue_push_tail(res->commands,tmp);
} else {
/*counterclockwise/right turn*/
tmp = command_new(0,BREAK,TURN_RIGHT);
tmp = command_new(0,BREAK,TURN_HARD_RIGHT);
g_queue_push_tail(res->commands,tmp);
}
tmp = command_new(stop,BREAK,TURN_STRAIGHT);
tmp = command_new(stop,ACCEL,TURN_STRAIGHT);
g_queue_push_tail(res->commands,tmp);
/*start driving*/
tmp = command_new(stop,ACCEL,TURN_STRAIGHT);
g_queue_push_tail(res->commands,tmp);
// tmp = command_new(stop,ACCEL,TURN_STRAIGHT);
// g_queue_push_tail(res->commands,tmp);
return res;
}