private void CalculateCorrectPosition(Board board, List<IAnimal> animals, IAnimal animal) { adderForXPosition = Program.Random.Next(-1, 2); adderForYPosition = Program.Random.Next(-1, 2); while (board.OutOfBounds(adderForXPosition, adderForYPosition, board.Layout, animal) || PlaceIsNotFree(animal, animals) || DidntMove()) { adderForXPosition = Program.Random.Next(-1, 2); adderForYPosition = Program.Random.Next(-1, 2); } }
private void RunAway(List<IAnimal> animals, IEnumerable<IAnimal> lionsAround, Board board, Antilope antilope) { IEnumerable<IAnimal> enumeratedLionsAround = lionsAround as IList<IAnimal> ?? lionsAround.ToList(); for (int y = -1; y <= 1; y++) { for (int x = -1; x <= 1; x++) { if (board.OutOfBounds(x, y, board.Layout, antilope) || !SpaceIsFree(animals, x, y, antilope) || !IsSafePlaceToGo(enumeratedLionsAround, x, y, antilope)) { continue; } MoveTo(x, y, antilope); return; } } }