public void AStarPathFindServiceUnitTests_ShouldFindOptimalPath_From00To04()
        {
            // Arrange
            var start   = new Vector2Int(0, 0);
            var end     = new Vector2Int(0, 4);
            var options = new PathFindingOptions()
            {
                Start = start,
                End   = end
            };

            var graph           = new MatrixFullGraph(5, 5, 0);
            var neighborService = new GraphGridNeighborsService(1);
            var astar_finder    = new AStarPathFindService(neighborService);

            // Act
            var result = astar_finder.Find(graph, options);

            // Assert
            var expected = new GraphPath()
            {
                Path = new List <Vector2Int>()
                {
                    start,
                    new Vector2Int(0, 1),
                    new Vector2Int(0, 2),
                    new Vector2Int(0, 3),
                    end
                }
            };

            Assert.True(Enumerable.SequenceEqual(expected.Path, result.Path));
        }
Exemple #2
0
        public void MatrixGraphUnitTests_ShouldGetTransition()
        {
            // Arrange
            var graph = new MatrixFullGraph(1, 2, 1f);

            // Act
            var transition = graph.GetTransition(new Vector2Int(0, 0), new Vector2Int(1, 0));

            // Assert
            Assert.AreEqual(1f, transition);
        }
Exemple #3
0
        public void MatrixGraphUnitTests_ShouldGetTransitionInCorners(int x, int y)
        {
            // Arrange
            var graph = new MatrixFullGraph(2, 2, 1f);

            // Act
            var transition = graph.GetTransition(new Vector2Int(0, 0), new Vector2Int(x, y));

            // Assert
            Assert.AreEqual(1f, transition);
        }
Exemple #4
0
        void Update()
        {
            if (!(Application.isEditor && !Application.isPlaying))
            {
                return;
            }

            if (isInit)
            {
                return;
            }

            var graph    = new MatrixFullGraph(options.GraphWidth, options.GraphHeight);
            var neighbor = new GraphGridNeighborsService(options.MaxNotWalkableCost);

            var navGrid = GetComponent <NavigationActionGrid>();

            navGrid.Graph            = graph;
            navGrid.NeighborsService = neighbor;

            isInit = true;
        }