public void FillPool(IEventPool <GameEvent> pool, int amountOfEvents, string type) { //get discrete function for how to pick game events double[] eventProbability = Utils.DistributionFunction(GAME_DIFFICULTY_COUNT); int[] numberOfEvenetsFromEachLevel = new int[GAME_DIFFICULTY_COUNT]; for (int i = 0; i < GAME_DIFFICULTY_COUNT; i++) { numberOfEvenetsFromEachLevel[i] = (int)Math.Floor(eventProbability[i] * amountOfEvents); } for (int i = 0; i < eventProbability.Length; i++) { //factory give me from this pool of options an amount of events according to it's //specified distrub int amount = numberOfEvenetsFromEachLevel[i]; List <GameEvent> generatedEvents = GameEventFactory.GetIntance().GenerateMany(type, amount, i); EventPoolHolder <GameEvent> .AddToPool(pool, generatedEvents); } //choose from each type x the f(x) amount //for every object clone and send to pool //call it self in {level} time }
public void CollectFromPool(IEventPool <GameEvent> pool, int amountToCollect) { int amount = 0; int cnt1 = 0; int cnt2 = 0; while (amount < amountToCollect && ++cnt1 < 100) { if (cnt1 == 99) { Debug.Log("Error"); } List <GameEvent> .Enumerator iter = pool.GetEnumerator(); int averageCost = EventPoolUtil.GetAverageCost(pool); GiveMoney(averageCost); while (iter.MoveNext() && ++cnt2 < 100) { if (cnt2 == 99) { Debug.Log("Error"); } GameEvent ge = iter.Current; int cost = ge.GetCost(); if (mMoney >= cost) { mMoney -= cost; if (ge.GetEventType().Equals("Obstacles")) { mObstacles.Add(ge); } else if (ge.GetEventType().Equals("Goods")) { mGoods.Add(ge); } //mGameEventList.AddLast(ge); amount++; pool.Remove(iter.Current); break; } } } //I should also consider if to clear the list after every cycle }
public static int GetAverageCost(IEventPool <GameEvent> pool) { if (pool.GetSize() == 0) { return(0); } int sum = 0; foreach (GameEvent ge in pool.GetAll()) { sum += ge.GetCost(); } sum = (int)Math.Ceiling((float)sum / pool.GetSize()); return(sum); }
public static List <T> GetManyEventsFromPool(IEventPool <T> pool, int amount) { return(pool.GetManyEventsFromPool(amount)); }
// todo fix public static T GetEventFromPool(IEventPool <T> pool) { return(pool.GetEventFromPool()); }
public static void AddToPool(IEventPool <T> pool, List <T> toAdd) { pool.AddToPool(toAdd); }