コード例 #1
0
ファイル: TaskGenerator.cs プロジェクト: ondrosru/GameDev
        private List <ArithmeticExpression4> GetArithmetics4(int val1, int val2)
        {
            List <ArithmeticExpression4> arithmetics = new List <ArithmeticExpression4>();

            foreach (TOperation operation1 in Enum.GetValues(typeof(TOperation)))
            {
                foreach (TOperation operation2 in Enum.GetValues(typeof(TOperation)))
                {
                    ArithmeticExpression4 arithmetic = new ArithmeticExpression4();
                    arithmetic.val1 = val1;
                    arithmetic.val2 = val2;
                    arithmetic.op1  = operation1;
                    arithmetic.op2  = operation2;
                    for (int val3 = 1; val3 < 10; val3++)
                    {
                        arithmetic.val2 = val2;
                        arithmetic.val3 = val3;
                        float result = arithmetic.GetResult();
                        if (result <= 9 && result >= 0 && (result - Math.Round(result)) == 0)
                        {
                            arithmetics.Add(arithmetic);
                        }
                    }
                }
            }
            return(arithmetics);
        }
コード例 #2
0
ファイル: TaskGenerator.cs プロジェクト: ondrosru/GameDev
        public Arithmetic4x4 GenerateArithmetic4x4()
        {
            Random rand = new Random();
            int    num  = rand.Next(1, 9);
            List <ArithmeticExpression4> tempList;

            tempList = GetArithmetics4(num);
            ArithmeticExpression4 row1 = tempList[rand.Next(0, tempList.Count - 1)];

            tempList = GetArithmetics4(row1.val1);
            ArithmeticExpression4 col1 = tempList[rand.Next(0, tempList.Count - 1)];

            tempList = GetArithmetics4(row1.val2);
            ArithmeticExpression4 col2 = tempList[rand.Next(0, tempList.Count - 1)];

            tempList = GetArithmetics4(col1.val2, col2.val2);
            ArithmeticExpression4        row2    = tempList[rand.Next(0, tempList.Count - 1)];
            List <ArithmeticExpression4> rows3   = GetArithmetics4(col1.val3, col2.val3);
            List <ArithmeticExpression4> rows4   = GetArithmetics4((int)col1.GetResult(), (int)col2.GetResult());
            List <ArithmeticExpression4> cols3   = GetArithmetics4(row1.val3, row2.val3);
            List <ArithmeticExpression4> cols4   = GetArithmetics4((int)row1.GetResult(), (int)row2.GetResult());
            List <Arithmetic4x4>         results = new List <Arithmetic4x4>();

            foreach (ArithmeticExpression4 row3 in rows3)
            {
                foreach (ArithmeticExpression4 row4 in rows4)
                {
                    foreach (ArithmeticExpression4 col3 in cols3)
                    {
                        foreach (ArithmeticExpression4 col4 in cols4)
                        {
                            if (row3.val3 == col3.val3 && row3.GetResult() == col4.val3 &&
                                row4.val3 == col3.GetResult() && row4.GetResult() == col4.GetResult())
                            {
                                Arithmetic4x4 newArithmetic4x4 = new Arithmetic4x4();
                                newArithmetic4x4.rows    = new ArithmeticExpression4[4];
                                newArithmetic4x4.cols    = new ArithmeticExpression4[4];
                                newArithmetic4x4.rows[0] = row1;
                                newArithmetic4x4.rows[1] = row2;
                                newArithmetic4x4.rows[2] = row3;
                                newArithmetic4x4.rows[3] = row4;
                                newArithmetic4x4.cols[0] = col1;
                                newArithmetic4x4.cols[1] = col2;
                                newArithmetic4x4.cols[2] = col3;
                                newArithmetic4x4.cols[3] = col4;
                                results.Add(newArithmetic4x4);
                            }
                        }
                    }
                }
            }
            return(results[rand.Next(0, results.Count - 1)]);
        }