From 5a63b053bdabcc465c3c44b339fac152d34bda86 Mon Sep 17 00:00:00 2001 From: Filip Chochol Date: Tue, 31 Mar 2026 19:40:08 +0200 Subject: [PATCH] push --- du4/snake.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/du4/snake.c b/du4/snake.c index 2bbacb8..9d81e9c 100644 --- a/du4/snake.c +++ b/du4/snake.c @@ -6,12 +6,13 @@ struct snake* add_snake(struct snake* snake, int x, int y) { nova_cast->x = x; nova_cast->y = y; nova_cast->next = snake; - return snake; + return nova_cast; } struct snake* remove_snake(struct snake* hlava) { if (hlava == NULL) return NULL; if (hlava->next == NULL) { + free(hlava); return NULL; } hlava->next = remove_snake(hlava->next); @@ -20,7 +21,7 @@ struct snake* remove_snake(struct snake* hlava) { int is_snake(struct snake* snake, int x, int y) { for (struct snake* this = snake; this != NULL; this = this->next) { - if (this->x = x && this->y == y) return 1; + if (this->x == x && this->y == y) return 1; } return 0; } @@ -28,6 +29,7 @@ int is_snake(struct snake* snake, int x, int y) { void free_snake(struct snake* sn) { if (sn == NULL) return; free_snake(sn->next); + free(sn); } int step_state(struct state* st) { @@ -56,6 +58,6 @@ int step_state(struct state* st) { } st->snake = add_snake(st->snake, nova_x, nova_y); - remove_snake(st->snake); + st->snake = remove_snake(st->snake); return END_CONTINUE; }