-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsim.js
46 lines (43 loc) · 1.45 KB
/
sim.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
'use strict';
var blackjack = require('./blackjack');
var strategy = require('./strategy');
var game = require('./game');
// setup
var gameOptions = {
printEmoji: true,
playerCount: 6,
rounds: 5,
//showLogs: [], // comment out this line to see full in-game logs
};
var aGame = new game.Game(gameOptions);
var players = aGame.play();
var payoutCumulative = 0;
for (var i = 0; i < players.length; ++i) {
var player = players[i];
var totalBet = 0;
var totalWinnings = 0;
var won = 0;
var lost = 0;
var pushed = 0;
for (var j = 0; j < player.history.length; ++j) {
var result = player.history[j];
totalBet += result.bet;
totalWinnings += result.winnings;
if (result.outcome === blackjack.outcomes.WIN) {
++won;
} else if (result.outcome === blackjack.outcomes.LOSE) {
++lost;
} else if (result.outcome === blackjack.outcomes.PUSH) {
++pushed;
} else {
throw "Unknown result: " + result.outcome;
}
}
var played = won + lost + pushed;
var payout = totalWinnings / totalBet;
payoutCumulative += payout;
console.log("Player " + (i+1) + ": ");
console.log("\tPlayed: " + played + ", Won: " + won + ", Pushed: " + pushed + ", Lost: " + lost);
console.log("\tBet: " + totalBet + ", Winnings: " + totalWinnings + ", Payout: " + payout);
}
console.log("\nAverage Payout: " + (payoutCumulative / players.length));