Exemplo n.º 1
0
        public void ObstructedPath()
        {
            var adapter = BuildGraph(3, 2);
            var left    = adapter.GetNode(1, 1);
            var right   = adapter.GetNode(2, 1);

            adapter.Graph.RemoveTwoWayLink(left, right);

            var start = adapter.GetNode(0, 1);
            var goal  = adapter.GetNode(2, 1);

            var path = Astar.FindPath(adapter, start, goal);

            path.Count.Should().Be(5);
            path[0].x.Should().Be(0);
            path[0].y.Should().Be(1);
            path[1].x.Should().Be(1);
            path[1].y.Should().Be(1);
            path[2].x.Should().Be(1);
            path[2].y.Should().Be(0);
            path[3].x.Should().Be(2);
            path[3].y.Should().Be(0);
            path[4].x.Should().Be(2);
            path[4].y.Should().Be(1);
        }
Exemplo n.º 2
0
        public void DirectPath_Diagonal()
        {
            var adapter = BuildGraph(4, 4);

            var start = adapter.GetNode(0, 0);
            var goal  = adapter.GetNode(3, 3);
            var path  = Astar.FindPath(adapter, start, goal);

            path.Count.Should().Be(7);
            path[0].x.Should().Be(0);
            path[0].y.Should().Be(0);
            // The actual path taken will depend on the implementation of the priority queue and how it handles equal priority items. Heaps are unstable
            path[6].x.Should().Be(3);
            path[6].y.Should().Be(3);
        }
Exemplo n.º 3
0
        public void DirectPath_Vertical()
        {
            var adapter = BuildGraph(7, 7);

            var start = adapter.GetNode(3, 5);
            var goal  = adapter.GetNode(3, 1);
            var path  = Astar.FindPath(adapter, start, goal);

            path.Count.Should().Be(5);
            for (var i = 0; i < 5; i++)
            {
                path[i].x.Should().Be(3);
                path[i].y.Should().Be(5 - i);
            }
        }