Ejemplo n.º 1
0
        public void TestBAddNodeLookItUp()
        {
            DirectedGraph <int, string> g = new DirectedGraph <int, string>();
            bool before = g.ContainsNode(0);

            g.AddNode(0);
            Assert.Multiple(() =>
            {
                Assert.That(before, Is.False);
                Assert.That(g.ContainsNode(0), Is.True);
            });
        }
        /// <summary>
        /// Gets a graph representing the given maze. The Direction associated with each edge
        /// is the direction from the source to the destination.
        /// </summary>
        /// <param name="maze">The maze to be represented.</param>
        /// <returns>The graph representation.</returns>
        private DirectedGraph <Cell, Direction> GetGraph(Maze maze)
        {
            DirectedGraph <Cell, Direction> graph = new DirectedGraph <Cell, Direction>();

            for (int i = 0; i < maze.MazeHeight; i++)
            {
                for (int j = 0; j < maze.MazeWidth; j++)
                {
                    Cell cell = new Cell(i, j);
                    if (!graph.ContainsNode(cell))
                    {
                        graph.AddNode(cell);
                    }
                    for (Direction d = Direction.North; d <= Direction.West; d++)
                    {
                        if (maze.IsClear(cell, d))
                        {
                            graph.AddEdge(cell, maze.Step(cell, d), d);
                        }
                    }
                }
            }
            return(graph);
        }