private void Act(Player player, Map map) { Point target = Position; if (GetDistanceToTarget(player.Position, Position) <= visibilityRadius) { if (GetDistanceToTarget(player.Position, Position) > attackRadius) { target = player.Position; } else { TryAttack(player); } } else { if (Position == Trajectory.Peek()) { Trajectory.Enqueue(Trajectory.Dequeue()); } target = Trajectory.Peek(); } var direction = DirectionFinder.FindDirectionToTarget(map, target, Position, Radius); if (direction != Direction.None) { Position = GetNextPosition(direction, Position); MovementTimer.Restart(); } }
public void FindDirection() { var textMap = "@@@@@\r\n@...@\r\n@.@.@\r\n@...@\r\n@@@@@"; var map = new Map(textMap, 10); var direction = DirectionFinder.FindDirectionToTarget(map, new Point { X = 25, Y = 13 }, new Point { X = 13, Y = 19 }, 5); Assert.AreEqual(direction, Direction.Right); }
public void BypassObstacleRight() { var textMap = "@@@@@\r\n@...@\r\n@.@.@\r\n@...@\r\n@@@@@"; var map = new Map(textMap, 10); var direction = DirectionFinder.FindDirectionToTarget(map, new Point { X = 32, Y = 30 }, new Point { X = 30, Y = 32 }, 5); Assert.AreEqual(direction, Direction.Right); }
public void BypassObstacleUp() { var textMap = "@@@@@\r\n@...@\r\n@.@.@\r\n@...@\r\n@@@@@"; var map = new Map(textMap, 10); var direction = DirectionFinder.FindDirectionToTarget(map, new Point { X = 25, Y = 13 }, new Point { X = 27, Y = 19 }, 5); Assert.AreEqual(direction, Direction.Up); }
public void ReturnNoneDirection() { var textMap = "@@@@@\r\n@.@.@\r\n@@@@@"; var map = new Map(textMap, 1); var direction = DirectionFinder.FindDirectionToTarget(map, new Point { X = 1, Y = 1 }, new Point { X = 3, Y = 1 }, 1); Assert.AreEqual(direction, Direction.None); }
public void CheckBfs() { var textMap = "@@@@@\r\n@...@\r\n@.@.@\r\n@...@\r\n@@@@@"; var map = new Map(textMap, 10); var direction = DirectionFinder.FindDirectionToTarget(map, new Point { X = 30, Y = 14 }, new Point { X = 30, Y = 34 }, 10); Assert.AreEqual(Direction.Left, direction); }