implement problem.enabled config values, fix repeated appearance of same problem through retrying

This commit is contained in:
Xevion
2020-12-18 22:24:01 -06:00
parent aecc316aa0
commit aecf3afa81
2 changed files with 21 additions and 3 deletions

View File

@@ -236,7 +236,7 @@ export default {
style: 'is-danger'
}
],
method: self.methods.square,
method: self.methods.square_root,
enabled: true,
current: 0
}

View File

@@ -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
}
}