diff --git a/src/Mono.cs b/src/Mono.cs index 5a4a3fa..be95363 100644 --- a/src/Mono.cs +++ b/src/Mono.cs @@ -190,7 +190,7 @@ static class Mono } } - static void Feed() + static (bool, XYZi) Feed() { // [!] handle out of the box exception on tail // by making the spatial arrays encapsulate the layer outside of the box @@ -199,6 +199,7 @@ static class Mono // step from head using directions towards the tail // and stop at either 1 cell away from the tail or 5 spaces away from the head + bool viable = false; XYZi cell = snake[0]; for (int step = 0; step < 5; step++) { @@ -214,6 +215,7 @@ static class Mono { min_dist = tail_dist; min_cell = dir_cell; + viable = true; } } cell = min_cell; @@ -223,7 +225,9 @@ static class Mono // } } - food = cell; + // [!] if can't find a viable cell try again next step + // (as it is possible to fence in the tail esp if you are eating) + return (viable, cell); } // space fill algorithm