Beispiel #1
0
        static private void GetProblemsFromSeed()
        {
            string seedPath = SeedFilePath();

            byte []      seedContents = System.IO.File.ReadAllBytes(seedPath);
            MemoryStream seedStream   = new MemoryStream(seedContents);

            if (seedContents.Length == 0)
            {
                ThinksyPlugin.ShowEmergencyWindow("The seed file is empty! (" + seedPath + ")");
                throw new Exception("The seed file is empty!");
            }
            //Message.Problem.ProblemGetResponse problemGet = Message.Problem.ProblemGetResponse.ParseFrom (seedContents);
            //Message.Problem.ProblemGetResponse problemGet = ProtoBuf.Serializer.Deserialize<Message.Problem.ProblemGetResponse> (seedStream);

            ThinksyProtosSerializer customSerializer = new ThinksyProtosSerializer();

            Message.Problem.ProblemGetResponse problemGet =
                customSerializer.Deserialize(seedStream, null, typeof(Message.Problem.ProblemGetResponse))
                as Message.Problem.ProblemGetResponse;


            for (int i = 0; i < problemGet.problems.Count; i++)
            {
                Message.Problem.ProblemData problem = problemGet.problems[i];
                ProblemKeeper.AddProblemsToProblemQueue(problem);
            }
        }
Beispiel #2
0
        static public bool CheckAnswer(Message.Problem.ProblemData answeredProblemData, Answer answer)
        {
            bool correct = true;

            //get correct answer IDs
            Message.Problem.AnswerIdentifier correctIDList = new Message.Problem.AnswerIdentifier();
            foreach (Senseix.Message.Atom.Atom atom in answeredProblemData.answer.answers)
            {
                correctIDList.uuid.Add(atom.uuid);
            }

            //bail out if we have the wrong number of answers
            List <string> answerIDStrings = new List <string>(answer.GetAnswerIDs());

            if (answerIDStrings.Count != correctIDList.uuid.Count)
            {
                return(false);
            }

            //sort the lists to eliminate order discrepencies
            correctIDList.uuid.Sort();
            answerIDStrings.Sort();

            //check given answers against correct answers
            for (int i = 0; i < answerIDStrings.Count; i++)
            {
                correct = correct && (correctIDList.uuid[i] == (string)answerIDStrings[i]);
            }

            return(correct);
        }
Beispiel #3
0
        static public bool SubmitAnswer(Message.Problem.ProblemData answeredProblemData, Answer answer, bool correct)
        {
            Message.Problem.ProblemPost problem = new Message.Problem.ProblemPost();
            problem.correct = correct;

            //set Problem's answers to given ones
            string[] answerIDStrings = answer.GetAnswerIDs();
            Senseix.Message.Problem.AnswerIdentifier givenAnswerIDs = new Senseix.Message.Problem.AnswerIdentifier();
            foreach (string answerID in answerIDStrings)
            {
                givenAnswerIDs.uuid.Add(answerID);
            }

            problem.problem_id            = answeredProblemData.uuid;
            problem.answer_ids            = givenAnswerIDs;
            problem.player_id             = SenseixSession.GetCurrentPlayerID();
            problem.answered_at_unix_time = UnixTimeNow();
            AddAnsweredProblem(problem, answer);
            return(correct);
        }
 static public bool SubmitAnswer(Message.Problem.ProblemData Problem, Answer answer, bool correct)
 {
     return(ProblemKeeper.SubmitAnswer(Problem, answer, correct));
 }
 static public bool CheckAnswer(Message.Problem.ProblemData Problem, Answer answer)
 {
     return(ProblemKeeper.CheckAnswer(Problem, answer));
 }
Beispiel #6
0
 public static void AddProblemsToProblemQueue(Message.Problem.ProblemData problem)
 {
     //Debug.Log ("Added a Problem to queue, queue length now " + newProblems.Count);
     newProblems.Enqueue(problem);
 }