diff --git a/cv9/snake.c b/cv9/snake.c index 7cad4c4..66a6b5e 100644 --- a/cv9/snake.c +++ b/cv9/snake.c @@ -9,7 +9,7 @@ struct snake* add_snake(struct snake* snake,int x,int y){ head->x = x; head->y = y; head->next = snake; - return snake; + return head; } struct snake* remove_snake(struct snake* snake){ @@ -40,11 +40,13 @@ void free_snake(struct snake* sn){ } int is_snake(struct snake* snake,int x,int y){ - if(snake == NULL) - return NULL; - if(x == snake->x && y == snake->y) - return 1; - return 0; + struct snake* this = snake; + while(this != NULL){ + if(this->x == x && this->y == y) + return 1; + this = this->next; + } + return 0; } int step_state(struct state* st){