Exemplo n.º 1
0
        private List <Point> FindAStarPath(Point currentPosition, Point targetPosition)
        {
            var graph = new AstarGridGraph(mover.collisionLayer);
            var path  = graph.search(currentPosition, targetPosition);

            return(path);
        }
        public void Search_BackwardPath_PathFound()
        {
            /*
             ##__
             * 10#_
             * 2#6_
             * 345_
             */
            var target = new AstarGridGraph(10, 10);

            target.Walls.Add(new Point(1, 2));
            target.Walls.Add(new Point(2, 1));
            target.Walls.Add(new Point(1, 0));
            target.Walls.Add(new Point(0, 0));
            var result = AStarPathfinder.Search(target, new Point(1, 1), new Point(2, 2));

            Assert.AreEqual(7, result.Count());
            Assert.AreEqual(new Point(1, 1), result[0]);
            Assert.AreEqual(new Point(0, 1), result[1]);
            Assert.AreEqual(new Point(0, 2), result[2]);
            Assert.AreEqual(new Point(0, 3), result[3]);
            Assert.AreEqual(new Point(1, 3), result[4]);
            Assert.AreEqual(new Point(2, 3), result[5]);
            Assert.AreEqual(new Point(2, 2), result[6]);
        }
        public void Search_ForwardPath_PathFound()
        {
            /*
             * ____
             * _01_
             * _#2_
             */
            var target = new AstarGridGraph(10, 10);

            target.Walls.Add(new Point(1, 2));
            var result = AStarPathfinder.Search(target, new Point(1, 1), new Point(2, 2));

            Assert.AreEqual(3, result.Count());
            Assert.AreEqual(new Point(1, 1), result[0]);
            Assert.AreEqual(new Point(2, 1), result[1]);
            Assert.AreEqual(new Point(2, 2), result[2]);
        }
        public void Search_NoWay_PathNull()
        {
            /*
             * _#__
             #0#_
             * _#x_
             * ____
             */
            var target = new AstarGridGraph(10, 10);

            target.Walls.Add(new Point(1, 2));
            target.Walls.Add(new Point(2, 1));
            target.Walls.Add(new Point(1, 0));
            target.Walls.Add(new Point(0, 1));
            var result = AStarPathfinder.Search(target, new Point(1, 1), new Point(2, 2));

            Assert.AreEqual(null, result);
        }
Exemplo n.º 5
0
        public Pathfinder(TmxMap tilemap)
        {
            _tilemap = tilemap;
            var layer = tilemap.GetLayer <TmxLayer>("main");

            _start = new Point(1, 1);
            _end   = new Point(10, 10);

            _gridGraph         = new UnweightedGridGraph(layer);
            _breadthSearchPath = _gridGraph.Search(_start, _end);

            _weightedGraph      = new WeightedGridGraph(layer);
            _weightedSearchPath = _weightedGraph.Search(_start, _end);

            _astarGraph      = new AstarGridGraph(layer);
            _astarSearchPath = _astarGraph.Search(_start, _end);

            Debug.DrawTextFromBottom = true;
        }
        public void Search_AllowDiagonal_PathFound()
        {
            /*
             ##__
             * _0#_
             * _#1_
             * ____
             */
            var target = new AstarGridGraph(10, 10, true);

            target.Walls.Add(new Point(1, 2));
            target.Walls.Add(new Point(2, 1));
            target.Walls.Add(new Point(1, 0));
            target.Walls.Add(new Point(0, 0));
            var result = AStarPathfinder.Search(target, new Point(1, 1), new Point(2, 2));

            Assert.AreEqual(2, result.Count());
            Assert.AreEqual(new Point(1, 1), result[0]);
            Assert.AreEqual(new Point(2, 2), result[1]);
        }
Exemplo n.º 7
0
 private void addNodes(TiledTileLayer collisionLayer)
 {
     astarGridGraph = new AstarGridGraph(collisionLayer);
 }
 public MagicProjectile(float theta, float velocity, float lifespan, TiledTileLayer collisionLayer) : base(theta, velocity, lifespan)
 {
     _grid  = new AstarGridGraph(collisionLayer);
     _count = 0;
 }