Ejemplo n.º 1
0
        public void TestAStarLinearPath()
        {
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var astar = new AStarPathFinder();

            var watch = new Stopwatch();
            watch.Start();
            var path = astar.FindPath(world, new BoundingBox(),
               new Coordinates3D(0, 4, 0), new Coordinates3D(5, 4, 0));
            watch.Stop();
            DrawGrid(path, world);
            Console.WriteLine(watch.ElapsedMilliseconds + "ms");

            var expected = new[]
            {
                new Coordinates3D(0, 4, 0),
                new Coordinates3D(1, 4, 0),
                new Coordinates3D(2, 4, 0),
                new Coordinates3D(3, 4, 0),
                new Coordinates3D(4, 4, 0),
                new Coordinates3D(5, 4, 0)
            };
            for (int i = 0; i < path.Waypoints.Count; i++)
                Assert.AreEqual(expected[i], path.Waypoints[i]);
        }
Ejemplo n.º 2
0
 public void TestAStarDiagonalPath()
 {
     var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
     var astar = new AStarPathFinder();
     var start = new Coordinates3D(0, 4, 0);
     var end = new Coordinates3D(5, 4, 5);
     var path = astar.FindPath(world, new BoundingBox(), start, end);
     DrawGrid(path, world);
     // Just test the start and end, the exact results need to be eyeballed
     Assert.AreEqual(start, path.Waypoints[0]);
     Assert.AreEqual(end, path.Waypoints[path.Waypoints.Count - 1]);
 }
Ejemplo n.º 3
0
        public void TestAStarExitRoom()
        {
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var astar = new AStarPathFinder();
            var start = new Coordinates3D(0, 4, 0);
            var end = new Coordinates3D(5, 4, 0);

            // North wall
            for (int x = -4; x < 4; x++)
                world.SetBlockID(new Coordinates3D(x, 4, -4), 1);
            // East wall
            for (int z = -4; z < 4; z++)
                world.SetBlockID(new Coordinates3D(3, 4, z), 1);
            // South wall
            for (int x = -4; x < 4; x++)
                world.SetBlockID(new Coordinates3D(x, 4, 4), 1);

            var path = astar.FindPath(world, new BoundingBox(), start, end);
            DrawGrid(path, world);

            // Just test the start and end, the exact results need to be eyeballed
            Assert.AreEqual(start, path.Waypoints[0]);
            Assert.AreEqual(end, path.Waypoints[path.Waypoints.Count - 1]);
        }
Ejemplo n.º 4
0
        public void TestAStarImpossible()
        {
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var astar = new AStarPathFinder();
            var start = new Coordinates3D(0, 4, 0);
            var end = new Coordinates3D(5, 4, 0);

            world.SetBlockID(start + Coordinates3D.East, 1);
            world.SetBlockID(start + Coordinates3D.West, 1);
            world.SetBlockID(start + Coordinates3D.North, 1);
            world.SetBlockID(start + Coordinates3D.South, 1);

            var path = astar.FindPath(world, new BoundingBox(), start, end);
            Assert.IsNull(path);
        }
Ejemplo n.º 5
0
 public WanderState()
 {
     IdleChance = 20;
     Distance   = 25;
     PathFinder = new AStarPathFinder();
 }
Ejemplo n.º 6
0
 public WanderState()
 {
     IdleChance = 5;
     Distance = 16;
     PathFinder = new AStarPathFinder();
 }
Ejemplo n.º 7
0
        public override void Handle(IRemoteClient client, string alias, string[] arguments)
        {
            if (arguments.Length != 1)
            {
                Help(client, alias, arguments);
                return;
            }

            int id;
            if (!int.TryParse(arguments[0], out id))
            {
                Help(client, alias, arguments);
                return;
            }

            var manager = client.Server.GetEntityManagerForWorld(client.World);
            var entity = manager.GetEntityByID(id) as MobEntity;
            if (entity == null)
            {
                client.SendMessage(ChatColor.Red + "An entity with that ID does not exist in this world.");
                return;
            }

            Task.Factory.StartNew(() =>
            {
                var astar = new AStarPathFinder();
                var path = astar.FindPath(client.World, entity.BoundingBox, (Coordinates3D)entity.Position, (Coordinates3D)client.Entity.Position);
                if (path == null)
                {
                    client.SendMessage(ChatColor.Red + "It is impossible for this entity to reach you.");
                    return;
                }
                entity.CurrentPath = path;
            });
        }
Ejemplo n.º 8
0
 public WanderState()
 {
     IdleChance = 20;
     Distance = 25;
     PathFinder = new AStarPathFinder();
 }
Ejemplo n.º 9
0
        public void TestAStarObstacle()
        {
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var astar = new AStarPathFinder();
            var start = new Coordinates3D(0, 4, 0);
            var end = new Coordinates3D(5, 4, 0);
            world.SetBlockID(new Coordinates3D(3, 4, 0), 1); // Obstacle

            var watch = new Stopwatch();
            watch.Start();
            var path = astar.FindPath(world, new BoundingBox(), start, end);
            watch.Stop();
            DrawGrid(path, world);
            Console.WriteLine(watch.ElapsedMilliseconds + "ms");

            // Just test the start and end, the exact results need to be eyeballed
            Assert.AreEqual(start, path.Waypoints[0]);
            Assert.AreEqual(end, path.Waypoints[path.Waypoints.Count - 1]);
            Assert.IsFalse(path.Waypoints.Contains(new Coordinates3D(3, 4, 0)));
        }
Ejemplo n.º 10
0
        public void TestAStarImpossible()
        {
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var astar = new AStarPathFinder();
            var start = new Coordinates3D(0, 4, 0);
            var end = new Coordinates3D(5, 4, 0);

            world.SetBlockID(start + Coordinates3D.East, 1);
            world.SetBlockID(start + Coordinates3D.West, 1);
            world.SetBlockID(start + Coordinates3D.North, 1);
            world.SetBlockID(start + Coordinates3D.South, 1);

            var watch = new Stopwatch();
            watch.Start();
            var path = astar.FindPath(world, new BoundingBox(), start, end);
            watch.Stop();
            Console.WriteLine(watch.ElapsedMilliseconds + "ms");

            Assert.IsNull(path);
        }
Ejemplo n.º 11
0
 public WanderState()
 {
     Distance   = 25;
     PathFinder = new AStarPathFinder();
 }