step from head to tail_fill zero *food path finding

This commit is contained in:
ethan merchant 2024-11-10 03:37:17 -05:00
parent 857e32e5fe
commit f6e3792cb1

View file

@ -16,7 +16,6 @@ static class Mono
public const int SD_X = 2, SD_Y = 1, SD_Z = 2; public const int SD_X = 2, SD_Y = 1, SD_Z = 2;
public static SpatialArray<int> public static SpatialArray<int>
s_array = new(SD_X, SD_Y, SD_Z, -1), s_array = new(SD_X, SD_Y, SD_Z, -1),
head_fill = new(SD_X, SD_Y, SD_Z, -1),
tail_fill = new(SD_X, SD_Y, SD_Z, -1); tail_fill = new(SD_X, SD_Y, SD_Z, -1);
public static XYZi[] snake = new XYZi[ public static XYZi[] snake = new XYZi[
@ -187,39 +186,38 @@ static class Mono
static void Feed() static void Feed()
{ {
head_fill.Clear(-1); // [!] handle out of the box exception on tail
Gas(head_fill, snake[0]); // by making the spatial arrays encapsulate the layer outside of the box
// handle out of the box exception on tail
tail_fill.Clear(-1); tail_fill.Clear(-1);
Gas(tail_fill, snake[snake_len - 1]); Gas(tail_fill, snake[snake_len - 1]);
XYZi farthest_cell = new XYZi(0, 0, 0); // step from head using directions towards the tail
int farthest_dist = 0; // and stop at either 1 cell away from the tail or 5 spaces away from the head
// [*] design configurable (we basically want it to be as far away as it can reasonably be) XYZi cell = snake[0];
const int max_dist = 6; for (int step = 0; step < 5; step++)
// [!] given how it loops over the space it directionally biases the results
for (int sx = -s_array.Xslen; s_array.InX(sx); sx++)
{ {
for (int sy = -s_array.Yslen; s_array.InY(sy); sy++) int min_dist = 100;
XYZi min_cell = new();
int[] dir_indices = GetShuffledIndices(directions);
for (int i = 0; i < directions.Length; i++)
{ {
for (int sz = -s_array.Zslen; s_array.InZ(sz); sz++) XYZi dir = directions[dir_indices[i]];
XYZi dir_cell = cell + dir;
int tail_dist = tail_fill[dir_cell];
if (tail_dist > 1 && tail_dist < min_dist)
{ {
XYZi sv = new XYZi(sx, sy, sz); min_dist = tail_dist;
int dist = head_fill[sv]; min_cell = dir_cell;
bool good_dist = dist > farthest_dist && dist < max_dist;
bool tail_access = tail_fill[sv] > 0; // help ensure completability
bool snake_free = s_array[sv] == -1;
if (good_dist && tail_access && snake_free)
{
farthest_dist = dist;
farthest_cell = sv;
}
} }
} }
cell = min_cell;
// if (min_dist <= 1)
// {
// break;
// }
} }
food = farthest_cell; food = cell;
} }
// space fill algorithm // space fill algorithm