private void GoToFinish(PathGridNode node) { while (node != null) { if (node.RightNode != null) { node.VisitedRight = true; node = node.RightNode; } else if (node.DownNode != null) { node.VisitedDown = true; node = node.DownNode; } else { path.Push(node); return; } path.Push(node); } }
public void Setup(int cols, int rows) { path.Clear(); if (cols <= 0 || rows <= 0) { throw new ArgumentOutOfRangeException(); } nodes = new PathGridNode[++cols * ++rows]; for (int i = 0; i < nodes.Length; i++) { nodes[i] = new PathGridNode(); } var p = 0; for (var r = 0; r < rows; r++) { for (var c = 0; c < cols; c++) { nodes[p].RightNode = c < cols - 1 ? nodes[p + 1] : null; nodes[p].DownNode = r < rows - 1 ? nodes[p + cols] : null; p++; } } }