-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.js
75 lines (62 loc) · 1.97 KB
/
game.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
65
66
67
68
69
var Stack = require('./stack')
var stacks = [];
var against = 0;
stacksNotFinished = () => {
var notfinished = false;
stacks.forEach(hand => {
if (!hand.isFinished()) {
notfinished = true;
}
});
return notfinished;
}
var self = module.exports = {
userMoney: 100,
play: function play() {
//get the dealer
stacks = [];
var dealerstack = new Stack(1);// = new Hand(1);
//create one stack and let it play
var playerstack = new Stack(2);// = new Hand(2);
stacks.push(playerstack);
while (stacksNotFinished()) {
stacks.forEach(stack => {
console.log('Dealer:');
dealerstack.cardShow();
stack.play(dealerstack.getSum());
});
stacks.forEach(stack => {
if (stack.isSplit()) {
var index = stacks.indexOf(stack);
if (index > -1) {
var splitStackArray = stacks.splice(index, 1);
var stackToSplit = splitStackArray[0];
var newStackArray = stackToSplit.splitStacks(); // MAGIC HAPPENS
newStackArray.forEach(element => {
stacks.push(element);
});
}
}
});
}
// play for dealer
this.summarize(dealerstack.wrapUp());
var outcome = {};
outcome.goodchoices = 100;
outcome.score = 5;
console.log('Good game!');
return outcome;
},
summarize: function summarize(against) {
// remove cost money, count winnings with dealer etc
console.log('Summarize:');
stacks.forEach(stack => {
if (stack.getSum() > against) {
console.log('Won: ' + stack.bet);
}
else {
console.log('Lost!');
}
});
}
}