private Node AttachNeighborNodes(Node node) { int leftIndex = node.Col - 1; int rightIndex = node.Col + 1; int topIndex = node.Row - 1; int bottomIndex = node.Row + 1; if(leftIndex >= 0) node.WestNode = _matrix[node.Row, leftIndex]; else node.WestNode = null; if(rightIndex <= MAX_RIGHT) node.EastNode = _matrix[node.Row, rightIndex]; else node.EastNode = null; if(topIndex >=0) node.NorthNode = _matrix[topIndex, node.Col]; else node.NorthNode = null; if(bottomIndex <= MAX_BOTTOM) node.SouthNode = _matrix[bottomIndex, node.Col]; else node.SouthNode = null; return node; }
public Node Other(Node n) { if (n == a) return b; else return a; }
public float weight; // Specific to the maze generation algorithm used. Should we abstract this out? #endregion Fields #region Constructors public NodeLink(Node A, Node B) { a = A; b = B; visited = false; weight = 1; }
public void Replace(Node toReplace, Node replacement) { // Note: method does not update the relevant node link lists if (a == toReplace) { a = replacement; } else if(b == toReplace) { b = replacement; } }
public Matrix(int rows, int columns) { _rows = rows; _cols = columns; MAX_BOTTOM = rows - 1; MAX_RIGHT = columns - 1; _matrix = new Node[rows, columns]; for(int i = 0; i < rows; i++) for(int k = 0; k < columns; k++) _matrix[i, k] = new Node(i, k); LoadMatrix(rows, columns); }
protected void VisitNode(Node n) { if (n.visited) { return; } foreach (NodeLink link in n.LinkList) { if (link != null && !link.visited) { if (link.Other(n) != null && !link.Other(n).visited) { if (link.weight == 0) { unweightedLinks.Add(link); } else { weightedLinks.Add(link); } } } } n.visited = true; }