-
Notifications
You must be signed in to change notification settings - Fork 6
/
example.js
executable file
·64 lines (53 loc) · 1.73 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
"use strict";
let MonteCarlo = require("./index.js"); // Use "monte-carlo" outside this repo
let _ = require("underscore");
class ImpossibleQuizSimulator extends MonteCarlo.Simulator {
before(results) {
results.add("wins", new MonteCarlo.Results.Counter());
results.add("payout", new MonteCarlo.Results.PayoutStandardDeviationCounter());
}
createGameState(rules) {
let questions = _.map(_.range(rules.questions), () => {
return {possible: this.randomDouble() > rules.chanceOfImpossibleQuestion};
});
return {
questions: questions
}
}
game(rules, gameState, results, skillOutcome) {
let lost = false;
while (!lost && gameState.questions.length) {
let question = gameState.questions.pop();
if (!question.possible || !skillOutcome()) {
lost = true;
}
}
if (!lost) {
if (rules.amountsToBeWon) {
results.payout.increase(this.shuffle(rules.amountsToBeWon)[0]);
} else {
results.payout.increase(this.random(rules.amountToBeWonMin, rules.amountToBeWonMax));
}
results.wins.increase();
}
}
}
let simulator = new ImpossibleQuizSimulator({ N: 10000 });
simulator.run("10 questions", {
chanceOfImpossibleQuestion: 0.05,
questions: 10,
amountToBeWonMin: 50,
amountToBeWonMax: 100
});
simulator.run("8 questions", {
chanceOfImpossibleQuestion: 0.05,
questions: 8,
amountToBeWonMin: 25,
amountToBeWonMax: 50
});
simulator.run("8 questions, fixed amounts", {
chanceOfImpossibleQuestion: 0.05,
questions: 8,
amountsToBeWon: [1, 10, 25, 50, 100]
});