private Coordinate GetNextRandom() { while (true) { var randomRow = _shipDataGenerator.GetRand0To9(); var randomColumn = _shipDataGenerator.GetRand0To9(); if (!_alreadyGeneratedCoordinates.Select(x => x.Key) .Contains(Coordinate.FromIndex(randomRow, randomColumn))) { return(Coordinate.FromIndex(randomRow, randomColumn)); } } }
private Ship GetUniqueShip(int shipSize, List <Ship> insertedShips) { while (true) { var randomShipLocation = new RandomShipLocation { ShipSize = shipSize, IsVertical = _randomShipDataGenerator.GetIsVertical(), ConstantRowOrColumn = _randomShipDataGenerator.GetRand0To9(), StartShepPoint = _randomShipDataGenerator.GetStartShipPoint(shipSize) }; var shipForInsert = GetShip(randomShipLocation); if (CanInsertShip(insertedShips, shipForInsert)) { return(shipForInsert); } } }