public override void Play() { //create 200 units every wave var shop = GameObject.FindGameObjectWithTag("Shop").GetComponent <UnitShop>(); if (unitsWave < 200) { var availableUnits = shop.GetPurchasable(numCoins); /* AI methods */ aiSolver.infoCalc(availableUnits, numCoins); var unitsToPurchase = aiSolver.Resolve(); /* We buy the units */ for (var i = 0; i < unitsToPurchase.Count; i++) { var unit = unitsToPurchase[i]; if (shop.IsPurchasable(unit, numCoins)) { shop.Purchase(unit); unitsWave += 1; numCoins -= unit.purchaseCost; } } } else { if (GameObject.FindGameObjectsWithTag("Unit").Length == 0) { GameController.instance.notifyWaveClear(this); unitsWave = 0; } } }
public void ResolveTest() { var maxWeight = 6; var result = KnapsackProblem.Resolve(CreateThings(), maxWeight); var sumWeight = result.Sum(thing => thing.Weight); var sumValue = result.Sum(thing => thing.Value); Assert.IsTrue(sumWeight <= maxWeight); Console.WriteLine($"SumValue:{sumValue}, SumWeight:{sumWeight}, MaxWeight:{maxWeight}"); Console.WriteLine("Result[] = {"); foreach (var thing in result) { Console.WriteLine($" Value:{thing.Value}, Weight:{thing.Weight}"); } Console.WriteLine("}"); }