mirror of
https://github.com/Xevion/power-math.git
synced 2025-12-06 01:15:48 -06:00
implement problem.enabled config values, fix repeated appearance of same problem through retrying
This commit is contained in:
@@ -236,7 +236,7 @@ export default {
|
|||||||
style: 'is-danger'
|
style: 'is-danger'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
method: self.methods.square,
|
method: self.methods.square_root,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
current: 0
|
current: 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,32 @@ import arithmetic from "@/arithmetic";
|
|||||||
import utils from "@/utils";
|
import utils from "@/utils";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
computed: {
|
||||||
|
availableProblems() {
|
||||||
|
return this.problems.filter(problem => problem.enabled);
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getProblem() {
|
getProblem() {
|
||||||
let problem = this.problems[utils.methods.getRandomInt(0, this.problems.length)];
|
let problemType = this.availableProblems[utils.methods.getRandomInt(0, this.availableProblems.length)];
|
||||||
return problem.method(problem.difficulties[problem.current].options);
|
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() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
previousProblem: null,
|
||||||
problems: arithmetic.data().problems
|
problems: arithmetic.data().problems
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user