public void TestComputeMinWastedSpace() { Assert.AreEqual(4, Knapsack.ComputeMinWastedSpace(5, new int[] { 1 })); Assert.AreEqual(0, Knapsack.ComputeMinWastedSpace(5, new int[] { 1, 2, 3 })); Assert.AreEqual(1, Knapsack.ComputeMinWastedSpace(7, new int[] { 1, 2, 3 })); Assert.AreEqual(0, Knapsack.ComputeMinWastedSpace(6, new int[] { 3, 1, 2, 3 })); Assert.AreEqual(0, Knapsack.ComputeMinWastedSpace(8, new int[] { 3, 1, 2, 3 })); Assert.AreEqual(1, Knapsack.ComputeMinWastedSpace(4, new int[] { 3, 2, 5, 3 })); Assert.AreEqual(0, Knapsack.ComputeMinWastedSpace(6, new int[] { 3, 2, 5, 3 })); Assert.AreEqual(6, Knapsack.ComputeMinWastedSpace(6, new int[] { })); }
/// <summary> /// Get the minion wasted cost when use this /// </summary> /// <param name="id">The RockId</param> /// <returns>The cost</returns> public int GetMininWastedCost(int id) { int space = this.Scene.Self.Resources; List <int> values = new List <int>(); foreach (int value in this.costs.Values) { values.Add(value); } int ret = Knapsack.ComputeMinWastedSpace(space, values.ToArray()); foreach (RockCard handCard in this.Scene.Self.Cards) { if (handCard.CardId == "GAME_005") { return(Math.Min(ret, Knapsack.ComputeMinWastedSpace(space + 1, values.ToArray()))); } } return(ret); }