Fix looping runs, faster path

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

View File

@ -31,7 +31,11 @@ static timestamp extract_ts(context *ctx, char *fpc) {
machine control_parser; machine control_parser;
variable cs ctx->cs; 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 mark { ctx->mark = fpc - ctx->buffer->str; }
action telemetrystart { ctx->tm = telemetry_new(); } action telemetrystart { ctx->tm = telemetry_new(); }
action telemetrystop { action telemetrystop {
@ -40,6 +44,7 @@ static timestamp extract_ts(context *ctx, char *fpc) {
t->vehicle.accel = ctx->tm->vehicle.accel; t->vehicle.accel = ctx->tm->vehicle.accel;
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"); */
} else { } else {
/* fprintf(stderr, "time difference [ms]: %i\n", getcurts(t) - ctx->tm->ts); */ /* 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 ";"; 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; %% write data;
@ -148,7 +153,7 @@ void control_parser_reset(trial *t) {
%% write init; %% write init;
g_string_truncate(ctx->tmp, 0); g_string_truncate(ctx->tmp, 0);
ctx->mark = -1; ctx->mark = -1;
ctx->pos = 0; /* fprintf(stderr, "Parser reset\n"); */
} }
void control_parser_free(trial *t) { void control_parser_free(trial *t) {
@ -184,7 +189,7 @@ run_t control_parse(trial *t) {
} }
if (control_parser_has_error(ctx)) { 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); shutdown(t->socket, SHUT_RDWR);
close(t->socket); close(t->socket);
exit(126); exit(126);

View File

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

View File

@ -16,6 +16,13 @@ void command_free(command* c){
g_slice_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){ path *path_new(map* m,vehicle *v){
command* tmp; command* tmp;
path* res; path* res;
@ -27,23 +34,24 @@ path *path_new(map* m,vehicle *v){
/* Turn towards origin, take shorter direction*/ /* Turn towards origin, take shorter direction*/
angle = atan2(-v->y,-v->x)*180/M_PI; 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); printf("Angle: %f stop: %f\n",angle,stop);
if(angle - v->dir > 0){ if(angle > 0){
/*clockwise/left turn*/ /*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); g_queue_push_tail(res->commands,tmp);
} else { } else {
/*counterclockwise/right turn*/ /*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); 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); g_queue_push_tail(res->commands,tmp);
/*start driving*/ /*start driving*/
tmp = command_new(stop,ACCEL,TURN_STRAIGHT); // tmp = command_new(stop,ACCEL,TURN_STRAIGHT);
g_queue_push_tail(res->commands,tmp); // g_queue_push_tail(res->commands,tmp);
return res; return res;
} }