Dog[] chooseDogs(int numOfOpenSpots) { DogFactory factory = new DogFactory(hideGameObjects: true); Dog[] dogs = new Dog[numOfOpenSpots]; DogDescriptor[] inRoom = dataController.DogsInRoom(this.room); DogDescriptor[] available = dataController.AvailableDogs; for (int i = 0; i < numOfOpenSpots; i++) { int indexInAvailable = i - inRoom.Length; if (ArrayUtil.InRange(inRoom, i)) { dogs[i] = factory.Create(inRoom[i]); } else if (ArrayUtil.InRange(available, indexInAvailable)) { DogDescriptor availableDog = available[indexInAvailable]; dogs[i] = factory.Create(availableDog); dataController.EnterRoom(availableDog, this.room); } else { dogs[i] = factory.Create(DogDescriptor.Default()); } } return(dogs); }
public DogDescriptor[] GetInOrderDogList( int count, bool skipAdopted, int startIndex = 0, int maxMasterIndex = int.MaxValue) { DogDescriptor[] dogList = new DogDescriptor[count]; int endIndex = startIndex + count - ZERO_INDEX_OFFSET; int indexInMasterDogArr = startIndex; for (int i = startIndex; i <= endIndex; i++) { if (ArrayUtil.InRange(this.dogs, indexInMasterDogArr)) { do { if (indexInMasterDogArr < maxMasterIndex) { dogList[i] = this.dogs[indexInMasterDogArr]; } else { dogList[i] = DogDescriptor.Default(); } }while(skipAdopted && ArrayUtil.InRange(this.dogs, indexInMasterDogArr) && dataController.CheckIsAdopted(this.dogs[indexInMasterDogArr++])); } else { dogList[i] = DogDescriptor.Default(); } } return(dogList); }
public DogDescriptor RandomDog(bool mustBeUnadopted) { DogDescriptor dog; if (dataController.AllDogsAdopted(this) && mustBeUnadopted) { dog = DogDescriptor.Default(); } else { do { dog = randomizer.GetRandom(); }while(mustBeUnadopted && dataController.CheckIsAdopted(dog)); } return(dog); }
// Excludes already adopted dogs protected DogDescriptor[] getDailyRandomDogListFromBuffer( RandomBuffer <DogDescriptor> buffer, int count, int startIndex = 0) { buffer.Refresh(); DogDescriptor[] fullSequence = buffer.GetRandom(dogs.Length); DogDescriptor[] candidates = ArrayUtil.GetRange(fullSequence, startIndex, count); // Allows for faster lookup versus O(n) to check array HashSet <DogDescriptor> currentCandidates = new HashSet <DogDescriptor>(candidates); // -1 for zero offset int currentIndex = startIndex + count - ZERO_INDEX_OFFSET; int totalDogCount = fullSequence.Length; for (int i = 0; i < candidates.Length; i++) { while (currentIndex < totalDogCount && dataController.CheckIsAdopted(candidates[i])) { if (!dataController.CheckIsAdopted(fullSequence[currentIndex])) { if (!currentCandidates.Contains(fullSequence[currentIndex])) { // Remove the old dog from the Hash (because it's invalid) currentCandidates.Remove(candidates[i]); candidates[i] = fullSequence[currentIndex]; // Update the Hash w/ the new dog currentCandidates.Add(candidates[i]); } } currentIndex++; } currentIndex++; if (currentIndex >= totalDogCount && dataController.CheckIsAdopted(candidates[i])) { candidates[i] = DogDescriptor.Default(); } } return(candidates); }