public void AStarEuclidian_CorrectPathFound_OneCorrectPath()
    {
        List <ILevelTile> expected = new List <ILevelTile>()
        {
            graphProvider.GetTileAtPos(new Vector2Int(2, 5)),
            graphProvider.GetTileAtPos(new Vector2Int(1, 5)),
            graphProvider.GetTileAtPos(new Vector2Int(1, 6)),
            graphProvider.GetTileAtPos(new Vector2Int(1, 7)),
            graphProvider.GetTileAtPos(new Vector2Int(2, 7)),
            graphProvider.GetTileAtPos(new Vector2Int(3, 7)),
            graphProvider.GetTileAtPos(new Vector2Int(4, 7)),
            graphProvider.GetTileAtPos(new Vector2Int(4, 6)),
            graphProvider.GetTileAtPos(new Vector2Int(4, 5)),
            graphProvider.GetTileAtPos(new Vector2Int(4, 4)),
            graphProvider.GetTileAtPos(new Vector2Int(5, 4)),
            graphProvider.GetTileAtPos(new Vector2Int(6, 4))
        };

        IPathFindingAlgorithm algo   = new AStarAlgorithm(graphProvider, new EuclidianHeuristic());
        ILevelTile            from   = graphProvider.GetTileAtPos(new Vector2Int(2, 5));
        ILevelTile            to     = graphProvider.GetTileAtPos(new Vector2Int(6, 4));
        IList <ILevelTile>    result = algo.CalculatePath(from, to);

        NUnit.Framework.Assert.IsTrue(result.Count == expected.Count);
        for (int i = 0; i < result.Count; ++i)
        {
            NUnit.Framework.Assert.IsTrue(result[i].Equals(expected[i]));
        }
    }
    public void AStarEuclidian_NoPathExistent()
    {
        IPathFindingAlgorithm algo   = new AStarAlgorithm(graphProvider, new EuclidianHeuristic());
        ILevelTile            from   = graphProvider.GetTileAtPos(new Vector2Int(6, 7));
        ILevelTile            to     = graphProvider.GetTileAtPos(new Vector2Int(1, 1));
        IList <ILevelTile>    result = algo.CalculatePath(from, to);

        NUnit.Framework.Assert.IsNull(result);
    }
    public void AStarEuclidian_StartSameAsEnd()
    {
        IPathFindingAlgorithm algo   = new AStarAlgorithm(graphProvider, new EuclidianHeuristic());
        ILevelTile            from   = graphProvider.GetTileAtPos(new Vector2Int(1, 1));
        ILevelTile            to     = graphProvider.GetTileAtPos(new Vector2Int(1, 1));
        IList <ILevelTile>    result = algo.CalculatePath(from, to);

        NUnit.Framework.Assert.IsTrue(result.Count == 1);
    }
    public void AStarEuclidian_CorrectPathFound_MultipleCorrectPaths()
    {
        IPathFindingAlgorithm algo   = new AStarAlgorithm(graphProvider, new EuclidianHeuristic());
        ILevelTile            from   = graphProvider.GetTileAtPos(new Vector2Int(2, 5));
        ILevelTile            to     = graphProvider.GetTileAtPos(new Vector2Int(0, 1));
        IList <ILevelTile>    result = algo.CalculatePath(from, to);

        NUnit.Framework.Assert.IsTrue(result.Count == 23);

        float pathLength = 0f;

        for (int i = 1; i < result.Count; ++i)
        {
            pathLength += Vector2.Distance(result[i - 1].Pos, result[i].Pos);
        }
        NUnit.Framework.Assert.AreEqual(pathLength, 22f, 0.1f);
    }
Пример #5
0
        public void TestUpdateChasePath2()
        {
            Game   game   = new Game();
            Blinky blinky = (Blinky)game.Ghosts[0];
            Player pacman = game.Player;

            pacman.IsPassedLeftTunnel = true;

            blinky.UpdateChasePath();

            IPathfindingAlgorithm algorithm = new AStarAlgorithm();
            List <Cell>           path      = algorithm.CalculatePath(blinky.CurrentCell(), game.Level.Map[0, 15], game.Level.Map);

            Assert.AreEqual(blinky.TargetCell, game.Level.Map[32, 15]);
            Assert.IsFalse(pacman.IsPassedLeftTunnel);
            CollectionAssert.AreEqual(blinky.ChasePath, path);
        }
Пример #6
0
        public void TestUseStupidPath()
        {
            Game   game   = new Game();
            Player pacman = game.Player;
            Clyde  clyde  = (Clyde)game.Ghosts[3];

            clyde.SetX(4);
            clyde.SetY(4);
            pacman.SetX(28);
            pacman.SetY(3);
            IPathfindingAlgorithm algorithm = new AStarAlgorithm();
            List <Cell>           path      = algorithm.CalculatePath(clyde.CurrentCell(), pacman.CurrentCell(), game.Level.Map).GetRange(0, 3);

            clyde.UseStupidPath();

            Assert.AreEqual(clyde.ChasePath.Count, 3);
        }
Пример #7
0
        public void TestDoChasing2()
        {
            Game  game  = new Game();
            Ghost ghost = game.Ghosts[0];

            ghost.SetX(ghost.StartCell.GetX());
            ghost.SetY(ghost.StartCell.GetY());
            ghost.Behaviour = Behaviour.Chase;
            ghost.ChaseTime = 0.0f;

            for (int i = 0; i < 10; i++)
            {
                ghost.DoChasing();
            }
            IPathfindingAlgorithm algorithm = new AStarAlgorithm();

            CollectionAssert.AreEqual(ghost.ReturnPath, algorithm.CalculatePath(ghost.CurrentCell(), ghost.StartCell, game.Level.Map));
            Assert.AreEqual(ghost.Behaviour, Behaviour.Return);
        }
Пример #8
0
        public void TestDoChasing1()
        {
            Game  game  = new Game();
            Ghost ghost = game.Ghosts[0];

            ghost.SetX(ghost.StartCell.GetX());
            ghost.SetY(ghost.StartCell.GetY());
            ghost.Behaviour = Behaviour.Chase;
            ghost.ChaseTime = 1.0f;
            IPathfindingAlgorithm algorithm = new AStarAlgorithm();

            ghost.ChasePath = algorithm.CalculatePath(ghost.CurrentCell(), game.Player.CurrentCell(), game.Level.Map);

            for (int i = 0; i < 10; i++)
            {
                ghost.DoChasing();
            }

            Assert.AreEqual(ghost.CurrentCell().GetX(), 26);
            Assert.AreEqual(ghost.CurrentCell().GetY(), 2);
        }
Пример #9
0
        public void TestCalculatePath3()
        {
            Game game = new Game();

            Cell[,] map = game.Level.Map;
            Cell        start        = game.Ghosts[0].HomeCell;
            Cell        end          = game.Ghosts[0].StartCell;
            List <Cell> expectedPath = new List <Cell>
            {
                map[17, 14],
                map[17, 13],
                map[17, 12],
                map[18, 12],
                map[18, 11],
                map[18, 10],
                map[18, 9],
                map[19, 9],
                map[20, 9],
                map[21, 9],
                map[21, 8],
                map[21, 7],
                map[21, 6],
                map[22, 6],
                map[23, 6],
                map[24, 6],
                map[24, 5],
                map[24, 4],
                map[24, 3],
                map[24, 2],
                map[25, 2],
                map[26, 2],
                map[27, 2]
            };

            IPathfindingAlgorithm algorithm = new AStarAlgorithm();
            List <Cell>           path      = algorithm.CalculatePath(start, end, map);

            CollectionAssert.AllItemsAreNotNull(path);
            CollectionAssert.AllItemsAreUnique(path);
        }
Пример #10
0
        public void TestCalculatePath2()
        {
            Game game = new Game();

            Cell[,] map = game.Level.Map;
            Cell        start        = map[21, 14];
            Cell        end          = map[27, 27];
            List <Cell> expectedPath = new List <Cell>
            {
                map[21, 14],
                map[21, 15],
                map[21, 16],
                map[21, 17],
                map[21, 18],
                map[21, 19],
                map[21, 20],
                map[21, 21],
                map[22, 21],
                map[23, 21],
                map[24, 21],
                map[24, 22],
                map[24, 23],
                map[24, 24],
                map[24, 25],
                map[24, 26],
                map[24, 27],
                map[25, 27],
                map[26, 27],
                map[27, 27]
            };

            IPathfindingAlgorithm algorithm = new AStarAlgorithm();
            List <Cell>           path      = algorithm.CalculatePath(start, end, map);

            CollectionAssert.AllItemsAreNotNull(path);
            CollectionAssert.AllItemsAreUnique(path);
            CollectionAssert.AreEqual(expectedPath, path);
        }