private void AddEquationForm(eEquationType eqForm, int minRange, int maxRange, eOperandBias operandBias) { switch (eqForm) { case eEquationType.compexity1: //a+b=c, a*b=c, etc... { int inputA = 0, inputB = 0, resultC = 0; bool validData = false; while (validData == false) { inputA = UnityEngine.Random.Range(minRange, maxRange); inputB = UnityEngine.Random.Range(minRange, maxRange); validData = true; if (operandBias == eOperandBias.forceMult || operandBias == eOperandBias.forceDivide) { //we don't want to many 1 * n equations int chance = UnityEngine.Random.Range(0, 100); if (chance < 75) //25% chance of 1*n or 1/n getting through { if (inputA == 1 || inputB == 1) { validData = false; } } } } if (operandBias == eOperandBias.forcePlus) { resultC = inputA + inputB; Debug.Log(resultC + " = " + inputA + " + " + inputB); AddFormulaToken((int)MathBall.eOperator.Plus, MathBall.eFunction.Operand); } else if (operandBias == eOperandBias.forceMinus) { int resultX = inputA + inputB; resultC = inputA; inputA = resultX; Debug.Log(resultC + " = " + inputA + " - " + inputB); AddFormulaToken((int)MathBall.eOperator.Minus, MathBall.eFunction.Operand); } else if (operandBias == eOperandBias.forceMult) { resultC = inputA * inputB; Debug.Log(resultC + " = " + inputA + " * " + inputB); AddFormulaToken((int)MathBall.eOperator.Multiply, MathBall.eFunction.Operand); } else if (operandBias == eOperandBias.forceDivide) { int resultX = inputA * inputB; resultC = inputA; inputA = resultX; Debug.Log(resultC + " = " + inputA + " / " + inputB); AddFormulaToken((int)MathBall.eOperator.Divide, MathBall.eFunction.Operand); } else if (operandBias == eOperandBias.forcePower) { int resultX = (int)Math.Pow(inputA, inputB); resultC = inputA; inputA = resultX; Debug.Log(resultC + " = " + inputA + " ^ " + inputB); AddFormulaToken((int)MathBall.eOperator.Power, MathBall.eFunction.Operand); } convertDigitsToFormulaTokens(inputA); convertDigitsToFormulaTokens(inputB); convertDigitsToFormulaTokens(resultC); AddFormulaToken((int)MathBall.eOperator.Equals, MathBall.eFunction.Operand); } break; case eEquationType.compexity2: //a*b=c/d, etc... { int inputA = UnityEngine.Random.Range(minRange, maxRange); } break; } }
public void AddEquation(int level, int minRange, int maxRange, eOperandBias operandBias) { //use level to adjust values AddEquationForm(eEquationType.compexity1, minRange, maxRange, operandBias); }