private void Walk(Point p) { //< Get all the cardinal directions that need checking var pointsToCheck = GetPointsToCheck(p); foreach (var point in pointsToCheck) { if (this.PointMap.ContainsKey(point.Item1)) { continue; } //< Get the movement result and add that point to the PointMap var moveRes = MoveInDirection(point.Item2); this.PointMap.Add(point.Item1, moveRes); //< If non-zero movement result, handle if (moveRes != 0) { //< Walk new point, then take back the movement Walk(point.Item1); //< Get the opposite direction to our present movement, move that way var oppositeDir = CardinalDirections.GetOppositeDirection(point.Item2); MoveInDirection(oppositeDir); if (moveRes == 2) { PointMap[point.Item1] = 1; Target = new Point(point.Item1.X, point.Item1.Y); } } } }
private void FloodFill(Point start) { var toProc = new Stack <Point>(); toProc.Push(start); while (toProc.Count > 0) { var p = toProc.Pop(); var cardinals = CardinalDirections.GetCardinalPointsAround(p).Select(c => c.Item1); foreach (var point in cardinals) { if (Maze[point.Y, point.X] != 0) { //< If un-explored, fill it in if (Explored[point.Y, point.X] == false) { //< Set the flood value to 1 more than the the previous point FloodLevels[point.Y, point.X] = FloodLevels[p.Y, p.X] + 1; //< Add this point to be filled toProc.Push(point); } } } //< Set the current point as seen Explored[p.Y, p.X] = true; } }
private List <Tuple <Point, long> > GetPointsToCheck(Point p) { //< Get all the cardinal positions around this point var cardinals = CardinalDirections.GetCardinalPointsAround(p); //< Return those that ain't been explored return(cardinals.Where(c => IsUnexplored(c.Item1)).ToList()); }