コード例 #1
0
        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);
        }
コード例 #2
0
        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}");
                }
            }
        }
コード例 #3
0
        bool constraintPasses(SequentialConstraints constraint, Logic.Question.IQuestion q)
        {
            decimal score = getScore(q);

            return(score <= constraint.MaxScore || score >= constraint.MinScore);
        }
コード例 #4
0
        bool constraintPasses(SimpleDivisionConstraint constraint, Logic.Question.IQuestion q)
        {
            decimal score = getScore(q);

            return(score <= constraint.MaxScore || score >= constraint.MinScore);
        }
コード例 #5
0
        bool constraintPasses(MultiplicationConstraints constraint, Logic.Question.IQuestion q)
        {
            decimal score = getScore(q);

            return(score <= constraint.MaxScore || score >= constraint.MinScore);
        }