From 46b34817d273560b13e0f8955d86b3d7e9853e66 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 16 Aug 2024 17:36:37 +0300 Subject: [PATCH] snake: Remove random goto statements when regenerating apple's position --- userspace/programs/snake/main.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/userspace/programs/snake/main.cpp b/userspace/programs/snake/main.cpp index b289a73124..1cef6e317f 100644 --- a/userspace/programs/snake/main.cpp +++ b/userspace/programs/snake/main.cpp @@ -65,13 +65,16 @@ Point get_random_point() void update_apple() { -regenerate: - g_apple = get_random_point(); - if (g_head == g_apple) - goto regenerate; - for (auto point : g_tail) - if (point == g_apple) - goto regenerate; + for (;;) + { + g_apple = get_random_point(); + if (g_head == g_apple) + continue; + for (auto point : g_tail) + if (point == g_apple) + continue; + break; + } set_grid_tile(g_apple, "\e[31mO"); }