From aecf3afa81302a6e8dd7abff38fd0199b7d912fb Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 18 Dec 2020 22:24:01 -0600 Subject: [PATCH] implement problem.enabled config values, fix repeated appearance of same problem through retrying --- src/arithmetic.js | 2 +- src/problems.js | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/arithmetic.js b/src/arithmetic.js index 879a1a2..77270cb 100644 --- a/src/arithmetic.js +++ b/src/arithmetic.js @@ -236,7 +236,7 @@ export default { style: 'is-danger' } ], - method: self.methods.square, + method: self.methods.square_root, enabled: true, current: 0 } diff --git a/src/problems.js b/src/problems.js index 5a5e18f..9ac21df 100644 --- a/src/problems.js +++ b/src/problems.js @@ -2,14 +2,32 @@ import arithmetic from "@/arithmetic"; import utils from "@/utils"; export default { + computed: { + availableProblems() { + return this.problems.filter(problem => problem.enabled); + } + }, methods: { getProblem() { - let problem = this.problems[utils.methods.getRandomInt(0, this.problems.length)]; - return problem.method(problem.difficulties[problem.current].options); + let problemType = this.availableProblems[utils.methods.getRandomInt(0, this.availableProblems.length)]; + let problem = null; + + // Begin looking for a 'unique'ish problem + for (let i = 0; i < 5; i++) { + // Generate a problem + problem = problemType.method(problemType.difficulties[problemType.current].options); + // Check that there was a previous problem and that the text doesn't match + if (this.previousProblem == null || problem.text !== this.previousProblem.text) + break; + } + + this.previousProblem = problem; + return problem; } }, data() { return { + previousProblem: null, problems: arithmetic.data().problems } }