void Start() { GameObject loader = GameObject.Find("Loader"); gameManager = loader.GetComponent <GameManager>(); captureSceneAudio = GetComponent <AudioSource>(); gameManager.SetAllBeastiesActive(false); PlaneManager.planesChanged += PlaceBeastieOnPlane; mathProblem = new MathProblem(); buttonA = GameObject.Find("ButtonA").GetComponent <Button>(); buttonB = GameObject.Find("ButtonB").GetComponent <Button>(); buttonC = GameObject.Find("ButtonC").GetComponent <Button>(); buttonD = GameObject.Find("ButtonD").GetComponent <Button>(); questionText = GameObject.Find("CaptureQuestionText").GetComponent <TextMeshProUGUI>(); answerAText = GameObject.Find("CaptureAnswerAText").GetComponent <TextMeshProUGUI>(); answerBText = GameObject.Find("CaptureAnswerBText").GetComponent <TextMeshProUGUI>(); answerCText = GameObject.Find("CaptureAnswerCText").GetComponent <TextMeshProUGUI>(); answerDText = GameObject.Find("CaptureAnswerDText").GetComponent <TextMeshProUGUI>(); correctStatusFront = GameObject.Find("CorrectStatusTextFront").GetComponent <TextMeshProUGUI>(); correctStatusShadow = GameObject.Find("CorrectStatusTextShadow").GetComponent <TextMeshProUGUI>(); // after getting button references, we deactivate the canvas questionAnswerCanvas.gameObject.SetActive(false); StartCoroutine(GetMathProblems()); }
public int?CalculateAnswerProblem(MathProblem problem) { int?result = null; switch (problem.Term) { case MathTerm.PLUS: result = problem.input1 + problem.input2; break; case MathTerm.MINUS: result = problem.input1 - problem.input2; break; case MathTerm.TIMES: result = problem.input1 * problem.input2; break; case MathTerm.DIVIDE: double r = (double)problem.input1 / (double)problem.input2; double r_to_int = Convert.ToDouble(Convert.ToInt32(r)); if (r - r_to_int == 0) { result = Convert.ToInt32(r_to_int); } break; } return(result); }
private MathProblem GenerateRandomEquation() { //1. Generate two random input numbers MathProblem problem = new MathProblem { input1 = GenerateLowInteger(), input2 = GenerateLowInteger() }; //2. Generate a random term do { int enumCount = Enum.GetNames(typeof(MathTerm)).Length; int answer_rand = Generator.Next(0, enumCount); problem.Term = (MathTerm)answer_rand; } while (problem.Term == MathTerm.EQUALS || problem.Term == MathTerm.NOTEQUALS); //3. Recalculate the generated question -> The answer has to be an positive integer. int?answer = CalculateAnswerProblem(problem); if (!answer.HasValue || answer.Value < 0) { return(GenerateRandomEquation()); } problem.output = answer.Value; return(problem); }
public bool OnQueueClearRequest(bool force) { if (!force) { return(false); } CurrentProblem = null; return(true); }
public void OnTagAdded(Sensors sensor, string TagIdentifier) { //Log to console Debug.WriteLine("Tag added: " + TagIdentifier); //1. Check if an answer is expected if (CurrentProblem != null) { //2. Check if given answer is expected if ((from a in CurrentProblem.ExpectedAnswer where a.name.Equals(TagIdentifier) select a.name).Any()) { //3a. Issue the 'well done' video TimeSpan waitTime = TriggerVideo(MathVideos.END_GOOD); //4. Issue the next math question CurrentProblem = null; Task.Run(async() => { await Task.Delay(waitTime); if (CurrentProblem == null) { StartupMathEngine(); //If no other question has been asked, ask again. } }); } else { //3b. Issue the 'oh no' video TriggerVideo(MathVideos.END_BAD); } } else { StartupMathEngine(); //Ask another question } }
private List <int> FindCorrectAnswersInput2(MathProblem problem) { List <int> answers = new List <int>(); int?correctSolution = CalculateAnswerProblem(problem); if (!correctSolution.HasValue) { return(answers); } for (int i = 0; i <= 10; i++) { MathProblem newProblem = problem; newProblem.input2 = i; int?newSolution = CalculateAnswerProblem(newProblem); if (newSolution.HasValue && newSolution.Value == correctSolution.Value) { answers.Add(i); } } return(answers); }
private List <MathTerm> FindCorrectTerms(MathProblem problem) { List <MathTerm> answers = new List <MathTerm>(); int?correctSolution = CalculateAnswerProblem(problem); if (!correctSolution.HasValue) { return(answers); } foreach (MathTerm term in Enum.GetValues(typeof(MathTerm))) { MathProblem newProblem = problem; newProblem.Term = term; int?newsolution = CalculateAnswerProblem(newProblem); if (newsolution.HasValue && newsolution.Value == correctSolution.Value) { answers.Add(term); } } return(answers); }
public MultiplicationQuest() { this.problem = createRndMultProblem(); options = createOptions(); }
public MathProblemTests() { _mathProblem = new MathProblem(); }
private async Task ShowMathProblem() { //1. Generate a valid equation. MathProblem problem = GenerateRandomEquation(); //2. Generate a question type double mpt_rand = Generator.NextDouble(); //3. Determine Answer if (mpt_rand > 0.9) { //a. Set question type problem.Type = MathProblemType.TermExpected; //b. Determine the term that needs to be eliminated List <MathTerm> answer = new List <MathTerm>(); double elim_rand = Generator.NextDouble(); if (elim_rand > 0.7) { //Eliminate the = sign. answer.Add(MathTerm.EQUALS); problem.Question = problem.input1 + MathProblem.TermString(problem.Term) + problem.input2 + " ? " + problem.output; } else { //Eliminate the + - * / signs problem.Question = problem.input1 + " ? " + problem.input2 + " = " + problem.output; answer = FindCorrectTerms(problem); } //c. Lookup the answer cube foreach (MathTerm t in answer) { foreach (Tag tag in Database.GiveTermTag(t)) { problem.ExpectedAnswer.Add(tag); } } } else if (mpt_rand > 0.45) { //a. Set question type problem.Type = MathProblemType.AnswerExpected; //b. Eliminate the answer problem.Question = problem.input1 + MathProblem.TermString(problem.Term) + problem.input2 + " = ?"; //c. Lookup the answer cube problem.ExpectedAnswer = Database.GiveNumberTag(problem.output); } else { //a. Set question type problem.Type = MathProblemType.QuestionExpected; //b. Determine the input that needs to be eliminated List <int> answer; double elim_rand = Generator.NextDouble(); if (elim_rand > 0.5) { //Eliminate the first input. problem.Question = " ? " + MathProblem.TermString(problem.Term) + problem.input2 + " = " + problem.output; answer = FindCorrectAnswersInput1(problem); } else { //Eliminate the second input. problem.Question = problem.input1 + MathProblem.TermString(problem.Term) + " ? = " + problem.output; answer = FindCorrectAnswersInput2(problem); } //c. Lookup the answer cube foreach (int i in answer) { foreach (Tag tag in Database.GiveNumberTag(i)) { problem.ExpectedAnswer.Add(tag); } } } //4. Check if the rendered question is possible to recreate with given blocks. (aka, is a tag found for asked answer. if (problem.ExpectedAnswer != null) { //5. Listen for the Expected answer CurrentProblem = problem; //6. Send the answer to the screen if allowed if (vplong) { Screen.OverlayManager(problem.Question); } } else { await ShowMathProblem(); //Keep retrying. } }