/// <summary> /// Creates a newly generated atom based on a weighted table /// </summary> /// <param name="solution">The answer number of the currently shown solution</param> /// <param name="eq">A new equation</param> /// <param name="atom_list">The list of current atoms from AtomHandler, for collision checking</param> /// <returns>A new atom, psuedo-randomly generated</returns> private int GetAtomNumber(int?solution, EquationManager eq, List <Bubble> atom_list) { //getting weights is only really valid when there is a solution available List <SolutionSet> all_solutions = new List <SolutionSet>(); List <int> current_solutions = new List <int>(); if (solution != null) { int sol = solution ?? 0; all_solutions = getAllSolutionSets(sol, eq.equation.operation); current_solutions = getCurrentSolutionNumbers(eq, sol); } int[] atom_count = getScreenAtomCount(atom_list); List <int> weight_table = getAtomWeightTable(all_solutions, current_solutions, atom_count); int NumberIndex = UnityEngine.Random.Range(0, weight_table.Count);//Get next Number within the weight table int NextAtom = weight_table[NumberIndex]; last_spawned_atom = NextAtom; return(NextAtom); }
protected void Start() { equation = transform.parent.gameObject.GetComponent <EquationManager>(); }
/// <summary> /// Gets all the solution sets based on the locked in numbers/numbers in equation /// </summary> /// <param name="eq">Current equation populated with the locked in numbers</param> /// <param name="solution">Current Solution</param> /// <returns>List of all possible solution numbers to what's provided</returns> private List <int> getCurrentSolutionNumbers(EquationManager eq, int solution) { List <int> ss = new List <int>(); if (eq.leftNumber != null || eq.rightNumber != null)//At least one of them has a number { Op op = eq.equation.operation; if (eq.leftNumber == null) { int num2 = eq.rightNumber ?? 0; for (int i = 1; i <= 9; i++) { switch (op) { case Op.Add: if (i + num2 == solution) { ss.Add(i); } break; case Op.Subtract: if (i - num2 == solution) { ss.Add(i); } break; case Op.Multiply: if (i * num2 == solution) { ss.Add(i); } break; case Op.Divide: if (i / num2 == solution) { ss.Add(i); } break; } } } else//Num2 is null { int num1 = eq.leftNumber ?? 0; for (int i = 1; i <= 9; i++) { switch (op) { case Op.Add: if (num1 + i == solution) { ss.Add(i); } break; case Op.Subtract: if (num1 - i == solution) { ss.Add(i); } break; case Op.Multiply: if (num1 * i == solution) { ss.Add(i); } break; case Op.Divide: if (num1 / i == solution) { ss.Add(i); } break; } } } } return(ss); }
protected void Awake() { equation = gameObject.GetComponent <EquationManager>(); }