예제 #1
0
        //Gets an task for the CPU
        public CCPUTask getTask()
        {
            CCPUTask task = tasks[tasks.Count - 1];

            tasks.RemoveAt(tasks.Count - 1);
            return(task);
        }
예제 #2
0
        //Function for an simple kioutput
        void CPUKi()
        {
            string   result              = "";
            CCPUTask task                = getTask();
            string   number1             = task.getNumber1();
            string   number2             = task.getNumber2();
            int      value1FromTaskAsInt = Convert.ToInt32(number1, 2);
            int      value2FromTaskAsInt = Convert.ToInt32(number2, 2);
            // Calculate the expected result.
            int expectedResult = value1FromTaskAsInt + value2FromTaskAsInt;

            result = expectedResult.ToString();
            outputNumbers.Add(result);
        }
예제 #3
0
        //Creates an task for the CPU
        public void createTask()
        {
            string calcOperator = "";
            string number1      = inputNumbers[inputNumbers.Count - 1];

            inputNumbers.RemoveAt(inputNumbers.Count - 1);
            string number2 = inputNumbers[inputNumbers.Count - 1];

            inputNumbers.RemoveAt(inputNumbers.Count - 1);

            System.Random random       = new System.Random();
            int           randomNumber = random.Next(0, 100);

            if (randomNumber > 49)
            {
                calcOperator = "+";
            }
            else
            {
                calcOperator = "-";
            }
            int value1FromTaskAsInt = Convert.ToInt32(number1, 2);
            int value2FromTaskAsInt = Convert.ToInt32(number2, 2);
            // Calculate the expected result.
            int expectedResult = 0;

            int  counter  = 0;
            bool returnOK = false;

            do
            {
                counter++;
                if (counter == 5)
                {
                    returnOK = true;
                }
                if (calcOperator.Equals("+"))
                {
                    expectedResult = value1FromTaskAsInt + value2FromTaskAsInt;
                }
                else
                {
                    expectedResult = value1FromTaskAsInt - value2FromTaskAsInt;
                }

                if (expectedResult > 15)
                {
                    value1FromTaskAsInt = value1FromTaskAsInt / 2;
                    value2FromTaskAsInt = value2FromTaskAsInt / 2;
                }

                if (expectedResult < 0)
                {
                    int temp = value1FromTaskAsInt;
                    value1FromTaskAsInt = value2FromTaskAsInt;
                    value2FromTaskAsInt = temp;
                }

                if (expectedResult < 15 && expectedResult > 0)
                {
                    returnOK = true;
                }
            } while (returnOK == false);

            number1 = value1FromTaskAsInt.ToString();
            number2 = value2FromTaskAsInt.ToString();
            if (counter < 5)
            {
                CCPUTask task = new CCPUTask();
                task.setNumber1(number1);
                task.setNumber2(number2);
                task.setCalcOperator(calcOperator);
                tasks.Add(task);
            }
        }