diff --git a/src/main.c b/src/main.c index e89515a..505174c 100644 --- a/src/main.c +++ b/src/main.c @@ -18,9 +18,9 @@ int main(int argc, char **argv) { } /*create trivial path towards the origin*/ - p = path_new(&t->map,&t->vehicle); trial_wait_for_start(t); + p = path_new(&t->map,&t->vehicle); while(t->alive){ trial_wait_for_input(t); path_execute(t,p); diff --git a/src/path.c b/src/path.c index 81e97cc..26a821a 100644 --- a/src/path.c +++ b/src/path.c @@ -32,15 +32,13 @@ path *path_new(map* m,vehicle *v){ /*clockwise/left turn*/ tmp = command_new(0,BREAK,TURN_LEFT); g_queue_push_tail(res->commands,tmp); - tmp = command_new(stop,BREAK,TURN_RIGHT); - g_queue_push_tail(res->commands,tmp); } else { /*counterclockwise/right turn*/ tmp = command_new(0,BREAK,TURN_RIGHT); g_queue_push_tail(res->commands,tmp); - tmp = command_new(stop,BREAK,TURN_LEFT); - g_queue_push_tail(res->commands,tmp); } + tmp = command_new(stop,BREAK,TURN_STRAIGHT); + g_queue_push_tail(res->commands,tmp); /*start driving*/ tmp = command_new(stop,ACCEL,TURN_STRAIGHT); @@ -51,8 +49,15 @@ path *path_new(map* m,vehicle *v){ void path_execute(trial* t,path* p){ command* tmp; tmp = (command*) g_queue_peek_head(p->commands); + if(tmp == NULL){ + fprintf(stderr,"warning: cannot execute empty path\n"); + } + if(t == NULL){ + fprintf(stderr,"trial is null\n"); + return; + } /*magic number for latency, send messages that much earlier*/ - while(tmp->ts - t->last_ts < 20){ + while(tmp != NULL && tmp->ts - t->last_ts < 20){ tmp = (command*) g_queue_pop_head(p->commands); switch(tmp->turn){ case TURN_HARD_LEFT: vehicle_hard_left(t); break;