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]); }
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]); }
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]); }
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); }
public WanderState() { IdleChance = 20; Distance = 25; PathFinder = new AStarPathFinder(); }
public WanderState() { IdleChance = 5; Distance = 16; PathFinder = new AStarPathFinder(); }
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; }); }
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))); }
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); }
public WanderState() { Distance = 25; PathFinder = new AStarPathFinder(); }