Пример #1
0
    private static SearchResult Search(Maze maze, IList <int> coordinate, int incomingDirection)
    {
        int dims = maze.Dimensions.Dimensionality;

        Maze.Walls cell     = maze[coordinate];
        var        result   = new SearchResult();
        int        openings = 0;

        for (int i = 0; i < 2 * maze.Dimensions.Dimensionality; ++i)
        {
            if (!cell[i])
            {
                ++openings;

                if (i != incomingDirection)
                {
                    result.Merge(Search(maze, Maze.GetNeighbor(coordinate, i), i < dims ? dims + i : i - dims));
                }
            }
        }

        if (result.Second == null && IsEdge(maze, coordinate))
        {
            result.Merge(new SearchResult {
                Best = new Path {
                    Coordinate = coordinate, DeadEnd = openings <= 1
                }
            });
        }

        if (openings > 2)
        {
            result.CommonMetric.Forks += openings - 1;
        }
        ++result.CommonMetric.Distance;

        return(result);
    }
Пример #2
0
 public Cell(Maze.Walls walls)
 {
     Subtree = this;
     Walls   = walls;
 }