private int GetTokensEarnedForEquation(MathTimeEquation eq) { /* * For single digit equations: * - 3 token for < 4 seconds * - 2 token for 4->7 seconds * - 1 token for > 7 seconds * * For triple digit equations: * - 5 tokens for < 5 seconds * - 3 tokens for 5->8 seconds * - 2 tokens for > 8 seconds */ int tokensEarned = 0; int seconds = (int)(((TimeSpan)(eq.equationEndTime - eq.equationStartTime)).TotalSeconds); if (eq.DigitLength <= 1) { if (seconds < 4) tokensEarned = 3; else if (seconds < 7) tokensEarned = 2; else tokensEarned = 1; } else if (eq.DigitLength <= 3) { if (seconds < 5) tokensEarned = 5; else if (seconds < 8) tokensEarned = 3; else tokensEarned = 2; } return tokensEarned; }
/* private bool ParseDataFile(String fileName, bool splitEquations, int maxRandomEquations) { try { TextReader reader = new StreamReader(fileName); String line = reader.ReadLine(); while (line != null) { // we expect each line to be something in the form of xxx+yyy int plusIndex = line.IndexOf('+'); if ((plusIndex != -1) && (plusIndex > 0) && (plusIndex < (line.Length - 1))) { String leftSide = line.Substring(0, plusIndex); String rightSide = line.Substring(plusIndex + 1); if ((leftSide != null) && (rightSide != null)) { MathTimeEquation eq = new MathTimeEquation(); eq.topValue = Int32.Parse(leftSide); eq.bottomValue = Int32.Parse(rightSide); equationsForSession.Add(eq); } } line = reader.ReadLine(); } reader.Close(); // reduce the input set to the right number of equations Random random = new Random(); while (equationsForSession.Count > maxRandomEquations) { int indexToDelete = random.Next(equationsForSession.Count); equationsForSession.RemoveAt(indexToDelete); } if (splitEquations) { foreach (MathTimeEquation eq in equationsForSession) { String leftSide = String.Format("{0:d}", eq.topValue); String rightSide = String.Format("{0:d}", eq.bottomValue); // make sure the lengths are the same, zero prefixing the shorter int maxLen = Math.Max(leftSide.Length, rightSide.Length); while (leftSide.Length < maxLen) leftSide = "0" + leftSide; while (rightSide.Length < maxLen) rightSide = "0" + rightSide; while (maxLen > 0) { String leftSideDigitStr = leftSide.Substring(maxLen - 1, 1); String rightSideDigitStr = rightSide.Substring(maxLen - 1, 1); MathTimeEquation singleDigitEq = new MathTimeEquation(); singleDigitEq.topValue = Int32.Parse(leftSideDigitStr); singleDigitEq.bottomValue = Int32.Parse(rightSideDigitStr); equationsForSession.Add(singleDigitEq); maxLen--; } } } return true; } catch (System.IO.IOException) { MessageBox.Show("There was an error starting the session. Possibly could not find the data file. Exiting!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return false; }*/ private void GenerateEquations(int minValue, int maxValue, bool splitEquations, int maxEquations) { Random random = new Random(); while (this.equationsForSession.Count < maxEquations) { MathTimeEquation eq = new MathTimeEquation(); eq.topValue = random.Next(minValue, maxValue); eq.bottomValue = random.Next(minValue, maxValue); this.equationsForSession.Add(eq); } if (splitEquations) { List<MathTimeEquation> originalEquations = new List<MathTimeEquation>(); originalEquations.AddRange(this.equationsForSession); this.equationsForSession.Clear(); foreach (MathTimeEquation eq in originalEquations) { String leftSide = String.Format("{0:d}", eq.topValue); String rightSide = String.Format("{0:d}", eq.bottomValue); // make sure the lengths are the same, zero prefixing the shorter int maxLen = Math.Max(leftSide.Length, rightSide.Length); while (leftSide.Length < maxLen) leftSide = "0" + leftSide; while (rightSide.Length < maxLen) rightSide = "0" + rightSide; int highPDigitsUsed = 0; while ((maxLen > 0) && (highPDigitsUsed < MainWindow.MaxHighPRequestCount)) { String leftSideDigitStr = leftSide.Substring(maxLen - 1, 1); String rightSideDigitStr = rightSide.Substring(maxLen - 1, 1); MathTimeEquation singleDigitEq = new MathTimeEquation(); singleDigitEq.topValue = Int32.Parse(leftSideDigitStr); singleDigitEq.bottomValue = Int32.Parse(rightSideDigitStr); this.equationsForSession.Add(singleDigitEq); highPDigitsUsed++; maxLen--; } this.equationsForSession.Add(eq); } } }