public bool Tunnel(NodePtr from, NodePtr to) { Node fromNode = this[from]; Node toNode = this[to]; int dx = (int)to.x - (int)from.x; int dy = (int)to.y - (int)from.y; // Ugly wall breaking code if (dx == 0 && dy == -1) { fromNode.Walls ^= (ushort)NodeWall.North; toNode.Walls ^= (ushort)NodeWall.South; } else if (dx == 1 && dy == 0) { fromNode.Walls ^= (ushort)NodeWall.East; toNode.Walls ^= (ushort)NodeWall.West; } else if (dx == 0 && dy == 1) { fromNode.Walls ^= (ushort)NodeWall.South; toNode.Walls ^= (ushort)NodeWall.North; } else if (dx == -1 && dy == 0) { fromNode.Walls ^= (ushort)NodeWall.West; toNode.Walls ^= (ushort)NodeWall.East; } else { throw new ArgumentException(); } // Should never happen return(true); }
public bool IsPointValid(NodePtr startPoint) { if (startPoint.x < 0 || startPoint.x > this.Width - 1 || startPoint.y < 0 || startPoint.y > this.Height - 1) { return(false); } return(true); }
public override bool Equals(object obj) { if (!(obj is NodePtr)) { return(false); } NodePtr otherPtr = (NodePtr)obj; return(this.x == otherPtr.x && this.y == otherPtr.y); }
public Node this[NodePtr ptr] { get { return(this[ptr.x, ptr.y]); } set { this[ptr.x, ptr.y] = value; } }
public bool IsPassable(NodePtr startPoint, NodePtr endPoint) { var distance = ((int)startPoint.x - endPoint.x) + ((int)startPoint.y - endPoint.y); if (Math.Abs(distance) != 1) { return(false); // i.e. if not cardinal neighbour, then false } var start = (NodeWall)this[startPoint].Walls; var end = (NodeWall)this[endPoint].Walls; if ((int)startPoint.y - endPoint.y == -1) // South { if ((start & NodeWall.South) != NodeWall.South && (end & NodeWall.North) != NodeWall.North) { return(true); } } if ((int)startPoint.y - endPoint.y == 1) // North { if ((start & NodeWall.North) != NodeWall.North && (end & NodeWall.South) != NodeWall.South) { return(true); } } if ((int)startPoint.x - endPoint.x == -1) // East { if ((start & NodeWall.East) != NodeWall.East && (end & NodeWall.West) != NodeWall.West) { return(true); } } if ((int)startPoint.x - endPoint.x == 1) // West { if ((start & NodeWall.West) != NodeWall.West && (end & NodeWall.East) != NodeWall.East) { return(true); } } return(false); }
public NodePtr?[] GetNeighbours(uint x, uint y) { NodePtr?[] neighbours = new NodePtr?[9]; int arrayPosition = 0; for (int h = ((int)y - 1); h <= y + 1; h++) // Column { for (int i = ((int)x - 1); i <= x + 1; i++) // Row { if ((arrayPosition == 4) || (i < 0 || i >= Width || h < 0 || h >= Height)) { /* * Return null for this position if it lands outside of * valid array bound, or, if it is not a neigbour * i.e. itself, the middle position * * + + + * + x + <--- x is the node whose neighbours we want * + + + * * When iterating over the results, it will allow the calling * code to have a static array length that can skip nulls * in the event of recursion. */ neighbours[arrayPosition] = null; } else { neighbours[arrayPosition] = new NodePtr((uint)i, (uint)h); } ++arrayPosition; } } return(neighbours); }
public NodePtr?[] GetNeighbours(NodePtr node) { return(GetNeighbours(node.x, node.y)); }
public double DistanceBetween(NodePtr a, NodePtr b) { return(Math.Sqrt((a.x - b.x) ^ 2 + (a.y - b.y) ^ 2)); }
public bool IsNodeVisited(NodePtr ptr) { return(this[ptr].Visited); }