decimal getScore(Logic.Question.IQuestion q) { decimal totalScore = 0; foreach (var n in q.Numbers) { totalScore += System.Math.Abs(n.Number) * (n.Number < 0 ? 1 : 2); } return(totalScore); }
public Logic.Question.IQuestion Fire(decimal level) { var constraint = getConstraintByLevel(level); System.Random random = new System.Random(System.Guid.NewGuid().GetHashCode()); int totalTries = 0; while (true) { Logic.Question.IQuestion q = generateQuestion(constraint); if (q.IsValid() && constraintPasses(constraint, q)) { return(q); } totalTries++; if (totalTries > Constants.Constants.MAX_CYLINDER_TRIES) { throw new System.Exception($"Could create a question within a constraint for level {level}"); } } }
bool constraintPasses(SequentialConstraints constraint, Logic.Question.IQuestion q) { decimal score = getScore(q); return(score <= constraint.MaxScore || score >= constraint.MinScore); }
bool constraintPasses(SimpleDivisionConstraint constraint, Logic.Question.IQuestion q) { decimal score = getScore(q); return(score <= constraint.MaxScore || score >= constraint.MinScore); }
bool constraintPasses(MultiplicationConstraints constraint, Logic.Question.IQuestion q) { decimal score = getScore(q); return(score <= constraint.MaxScore || score >= constraint.MinScore); }