public static void Check_Sample(Sample a, Combination Combo, combination_info Combo_info) { int A_needed = ally.carried_sample[a.sampleId].costA - Combo_info.availableA_inAlly - Combo_info.expertiseA; int B_needed = ally.carried_sample[a.sampleId].costB - Combo_info.availableB_inAlly - Combo_info.expertiseB; int C_needed = ally.carried_sample[a.sampleId].costC - Combo_info.availableC_inAlly - Combo_info.expertiseC; int D_needed = ally.carried_sample[a.sampleId].costD - Combo_info.availableD_inAlly - Combo_info.expertiseD; int E_needed = ally.carried_sample[a.sampleId].costE - Combo_info.availableE_inAlly - Combo_info.expertiseE; if (A_needed < 0) { A_needed = 0; } if (B_needed < 0) { B_needed = 0; } if (C_needed < 0) { C_needed = 0; } if (D_needed < 0) { D_needed = 0; } if (E_needed < 0) { E_needed = 0; } int needed_Tot = A_needed + B_needed + C_needed + D_needed + E_needed; if (A_needed <= availM[0] && B_needed <= availM[1] && C_needed <= availM[2] && D_needed <= availM[3] && E_needed <= availM[4] && needed_Tot <= 10 - Combo_info.storageTot) { //Molecules has enough materials or you alrdy have it //update info Combo_info.S_count++; Combo_info.storageTot += needed_Tot; availM[0] -= A_needed; availM[1] -= B_needed; availM[2] -= C_needed; availM[3] -= D_needed; availM[4] -= E_needed; Combo_info.availableA_inAlly = Get_Updated_Ally_Storage(A_needed, Combo_info.availableA_inAlly); Combo_info.availableB_inAlly = Get_Updated_Ally_Storage(B_needed, Combo_info.availableB_inAlly); Combo_info.availableC_inAlly = Get_Updated_Ally_Storage(C_needed, Combo_info.availableC_inAlly); Combo_info.availableD_inAlly = Get_Updated_Ally_Storage(D_needed, Combo_info.availableD_inAlly); Combo_info.availableE_inAlly = Get_Updated_Ally_Storage(E_needed, Combo_info.availableE_inAlly); Combo_info.Health_GainTot += ally.carried_sample[a.sampleId].health; if (a.gain == "A") { Combo_info.expertiseA++; } else if (a.gain == "B") { Combo_info.expertiseB++; } else if (a.gain == "C") { Combo_info.expertiseC++; } else if (a.gain == "D") { Combo_info.expertiseD++; } else if (a.gain == "E") { Combo_info.expertiseE++; } //Set Combo if (Combo.S1 == -1) { Combo.S1 = a.sampleId; } else if (Combo.S2 == -1) { Combo.S2 = a.sampleId; } else if (Combo.S3 == -1) { Combo.S3 = a.sampleId; } //Add to combinations //make new combination to get unique hashcode Combination combAdd = new Combination(); combAdd.S1 = Combo.S1; combAdd.S2 = Combo.S2; combAdd.S3 = Combo.S3; //Print Combination added Combo.Print_sampleIDs(); if (!Combinations.ContainsKey(combAdd)) { Combinations.Add(combAdd, Combo_info); } } }
public static void Find_Combinations() { //Find out if enemy will release some molecules for you int[] willbe_available_M = new int[5] { 0, 0, 0, 0, 0 }; int[] availableM = new int[5] { bank.A, bank.B, bank.C, bank.D, bank.E }; if (enemy.target == "LABORATORY") { //Find out what molecules WILL be available foreach (Sample a in enemy.carried_sample.Values) { int[] dM = new int[5] { a.costA - enemy.expertiseA, a.costB - enemy.expertiseB, a.costC - enemy.expertiseC, a.costD - enemy.expertiseD, a.costE - enemy.expertiseE }; if (enemy.storageA - dM[0] >= 0 && enemy.storageB - dM[1] >= 0 && enemy.storageC - dM[2] >= 0 && enemy.storageD - dM[3] >= 0 && enemy.storageE - dM[4] >= 0) { for (int i = 0; i < 5; i++) { //Enemy will use this sample willbe_available_M[i] += dM[i]; } } } } //Fill Combination List <int> ID_list = new List <int>(); foreach (Sample a in ally.carried_sample.Values) { ID_list.Add(a.sampleId); } foreach (Sample a in ally.carried_sample.Values) { Combination Combo = new Combination(); combination_info Combo_info = new combination_info(); Combo_info.storageTot = ally.storageTot; for (int i = 0; i < 5; i++) { //Initialize avail availM[i] = 0; //Then set availM availM[i] = willbe_available_M[i] + availableM[i]; } //Set values in convo info Combo_info.availableA_inAlly = ally.storageA; Combo_info.availableB_inAlly = ally.storageB; Combo_info.availableC_inAlly = ally.storageC; Combo_info.availableD_inAlly = ally.storageD; Combo_info.availableE_inAlly = ally.storageE; Console.Error.WriteLine("First sample" + a.sampleId); //Find the IDs of the other samples List <int> other_samples = new List <int>(); foreach (int b in ID_list) { if (b != a.sampleId) { other_samples.Add(b); Console.Error.WriteLine("OTHER SAMPLES" + b); } } //Check sample validity(S1) Check_Sample(a, Combo, Combo_info); //Check next 2 foreach (int b in other_samples) { Combination Combo2 = new Combination(); combination_info Combo_info2 = new combination_info(); Combo2.S1 = Combo.S1; Console.Error.WriteLine("SECOND SAMPLE: " + b + " Combo2.S1=" + Combo2.S1); Combo_info2.set_comb_info(Combo2, Combo_info.Health_GainTot, Combo_info.expertiseA, Combo_info.expertiseB, Combo_info.expertiseC, Combo_info.expertiseD, Combo_info.expertiseE, Combo_info.S_count, Combo_info.storageTot, Combo_info.availableA_inAlly, Combo_info.availableB_inAlly, Combo_info.availableC_inAlly, Combo_info.availableD_inAlly, Combo_info.availableE_inAlly); //Find 3rd sample int sample3_ID = -1; foreach (int c in other_samples) { if (c != b) { sample3_ID = c; } } //Try second sample Check_Sample(ally.carried_sample[b], Combo2, Combo_info2); Console.Error.WriteLine("Thrid SAMPLE: " + sample3_ID + " Combo2.S1=" + Combo2.S1 + "Combo.S2=" + Combo2.S2); //Then 3rd Check_Sample(ally.carried_sample[sample3_ID], Combo2, Combo_info2); } } }