using Graphs how do I find and assign the direct neighbors of a MineSweeper cell
my logic so far was 1- prefab my Node script by attaching it to a cube so that it's visible and clickable 2- using nested for loops generate x*y grid of Nodes and store them linearly in a transform called grid 3- using for loop iterate through each Node within grid and for each node check if it has top, bottom, left and right and do the following
if (top)
{
script.setNeighbor(grid.GetChild(i + ySize).gameObject);
if (left)
{
script.setNeighbor(grid.GetChild(i + ySize - 1).gameObject);
}
if (right)
{
script.setNeighbor(grid.GetChild(i + ySize + 1).gameObject);
}
}
if (right)
{
script.setNeighbor(grid.GetChild(i + 1).gameObject);
}
if (left)
{
script.setNeighbor(grid.GetChild(i - 1).gameObject);
}
if (bottom)
{
script.setNeighbor(grid.GetChild(i - ySize).gameObject);
if (left)
{
script.setNeighbor(grid.GetChild(i - ySize + 1).gameObject);
}
if (right)
{
script.setNeighbor(grid.GetChild(i - ySize - 1).gameObject);
}
}
}
for some reason this feels inefficient and perhaps can be done in a better way, the reason why I set the neighbors of a Node to a list of GameObject because cells do need to know more that how many of it's neighboring cells have bombs for example in case non of a cells neighbor had bombs then I need to run a Breadthfirst Search and click on all of it's neighbors that are empty.
Your answer
Follow this Question
Related Questions
How to show blackboard in pbr graph 0 Answers
Customize the context menu of a GraphView's BlackboardField? 0 Answers
How to add grass to an imported plane. 2 Answers
SpeedTree detail texture on roots is disconnected from trunk 0 Answers
Terrain paint tree only places one tree in the middle of circle no matter the density. 1 Answer