/// <summary> /// Implementation of IMovementAlgorithm interface. /// Provides a direction of movement for the given enemy. /// </summary> /// <param name="enemy">The enemy that should be moved.</param> /// <returns>The suggested direction of movement for the given enemy.</returns> public Direction ProvideDirection(Enemy enemy) { int start = _width * (int)enemy.X + (int)enemy.Y; int end = _width * (int)_player.X + (int)_player.Y; int solution; int m = _graph.AStar(start, end, out solution); if (m - start == -1) { return(Direction.Left); } if (m - start == 1) { return(Direction.Right); } if (m - start < 0) { return(Direction.Up); } if (m - start > 0) { return(Direction.Down); } return(Direction.None); }
private void AStarAlghorithTest(int s, int e, int solution) { int sol; _graph1.AStar(s, e, out sol); Assert.Equal(solution, sol); }