Hello Guys,
I would like to get help in some shorts question about foreach loop.
In the code below, there is a command that say
if (newMovementCostToNeighbour < neighbour.gCost || !openSet.Contains(neighbour)) {
the command refer to a single and a certain “neighbour” from the list or any of them ?
Thank you in advance.
foreach (Node neighbour in grid.GetNeighbours(currentNode))
{
if (!neighbour.walkable || closeSet.Contains(neighbour))
{
continue;
}
int newMovementCostToNeighbour = currentNode.gCost + GetDistance(currentNode, neighbour);
if (newMovementCostToNeighbour < neighbour.gCost || !openSet.Contains(neighbour)) {
neighbour.gCost = newMovementCostToNeighbour;
neighbour.hCost = GetDistance(neighbour, targetNode);
neighbour.parent = currentNode;
if (!openSet.Contains(neighbour))
openSet.Add(neighbour);
}
}