step from head to tail_fill zero *food path finding
This commit is contained in:
parent
857e32e5fe
commit
f6e3792cb1
1 changed files with 22 additions and 24 deletions
46
src/Mono.cs
46
src/Mono.cs
|
@ -16,7 +16,6 @@ static class Mono
|
|||
public const int SD_X = 2, SD_Y = 1, SD_Z = 2;
|
||||
public static SpatialArray<int>
|
||||
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);
|
||||
|
||||
public static XYZi[] snake = new XYZi[
|
||||
|
@ -187,39 +186,38 @@ static class Mono
|
|||
|
||||
static void Feed()
|
||||
{
|
||||
head_fill.Clear(-1);
|
||||
Gas(head_fill, snake[0]);
|
||||
|
||||
// handle out of the box exception on tail
|
||||
// [!] handle out of the box exception on tail
|
||||
// by making the spatial arrays encapsulate the layer outside of the box
|
||||
tail_fill.Clear(-1);
|
||||
Gas(tail_fill, snake[snake_len - 1]);
|
||||
|
||||
XYZi farthest_cell = new XYZi(0, 0, 0);
|
||||
int farthest_dist = 0;
|
||||
// [*] design configurable (we basically want it to be as far away as it can reasonably be)
|
||||
const int max_dist = 6;
|
||||
// [!] given how it loops over the space it directionally biases the results
|
||||
for (int sx = -s_array.Xslen; s_array.InX(sx); sx++)
|
||||
// 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
|
||||
XYZi cell = snake[0];
|
||||
for (int step = 0; step < 5; step++)
|
||||
{
|
||||
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);
|
||||
int dist = head_fill[sv];
|
||||
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;
|
||||
}
|
||||
min_dist = tail_dist;
|
||||
min_cell = dir_cell;
|
||||
}
|
||||
}
|
||||
cell = min_cell;
|
||||
// if (min_dist <= 1)
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
food = farthest_cell;
|
||||
food = cell;
|
||||
}
|
||||
|
||||
// space fill algorithm
|
||||
|
|
Loading…
Add table
Reference in a new issue