private static Point GetClosestEnemyPosition(BattleNetClient client, List <List <Point> > checkedPoints, List <List <Movement> > movements, List <Point> currentRangePoints, out List <Movement> road) { if (client.IsAnyOfEnemyAt(currentRangePoints)) { for (int index = 0; index < currentRangePoints.Count; index++) { if (client.IsEnemyAt(currentRangePoints[index])) { road = new List <Movement>(movements[index]); return(currentRangePoints[index]); } } } var iterationMap = MapUtility.IterationMap; var nextRangePoints = new List <Point>(); var nextMovements = new List <List <Movement> >(); var nextCheckedPoints = new List <List <Point> >(); for (int index = 0; index < movements.Count; index++) { foreach (var iteration in iterationMap) { var nextPosition = iteration.Value(currentRangePoints[index]); var movement = iteration.Key.ToMovement(); if (checkedPoints[index].Exists(x => x.X == nextPosition.X && x.Y == nextPosition.Y)) { continue; } if (client.IsOutOf(nextPosition) || client.IsObstacleAt(nextPosition)) { continue; } nextRangePoints.Add(nextPosition); var move = new List <Movement>(movements[index]); move.Add(iteration.Key.ToMovement()); nextMovements.Add(move); var nextChecked = new List <Point>(checkedPoints[index]); nextChecked.Add(currentRangePoints[index]); nextCheckedPoints.Add(nextChecked); } } checkedPoints.Clear(); checkedPoints.AddRange(nextCheckedPoints); movements.Clear(); movements.AddRange(nextMovements); currentRangePoints.Clear(); currentRangePoints.AddRange(nextRangePoints); road = new List <Movement>(); return(PointUtility.CreateNegativePoint()); }