-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
144 lines (135 loc) · 3.55 KB
/
main.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const game = require("./game.js");
const p = require("./player.js");
const readline = require('readline');
const dm = require("./data-miner.js");
/**
* Some things to consider:
* Player strategies - random vs if others are playing 'perfectly', if they tend to hit more, etc
*/
// gen stack of cards
// start game
// draw from top of pile
// dealer and player
// player 4 options
//here are my choices (do both):
// 1. run each option for every turn
// 2. pick an option at random for every turn and that's it
// 3. there's gotta be more
// DESIGN!!!!!!!!!!!!!
// after all this, run tons of games based on results and see percentage win (and do this vs online stuff)
/**
* Spitballin:
* 1.
* run to find out best move for any possible turn
* (just turn-based ? )
* Options:
* turn-based: give points
* what do we mean by the 'best' move?
* best move to do to win current hand
* or best move to do to not lose
* or best move to do to win big later
*
*/
function askQuestion(query) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
return new Promise(resolve => rl.question(query, ans => {
rl.close();
resolve(ans);
}))
}
var g = new game.Game(6);
var player = new p.Player(false);
async function main()
{
console.log(g.shoe);
g.playerJoin(0, player);
g.beginGame();
let stop = false;
while (!stop)
{
console.log("\n");
g.placeBets();
g.dealCards();
let hNum = 0;
while (!stop)
{
console.log("cb",player.currentBet);
console.log("prr",player.prevRoundResults);
hNum = -1;
for (let i = 0; i < 4; i++)
{
if (!player.handComplete[i])
{
hNum = i;
break;
}
}
if (hNum === -1)
{
//test
finishRound();
break;
}
game.printPlayerHand(player);
console.log("Dealer hand:\n", game.cardtoString(g.getDealerTopCard()));
//playerAction('s', hNum);
let ans = await askQuestion("What do you want to do? (on hand number " + hNum + ")\n");
console.log("\n");
try
{
playerAction(ans, hNum);
}
catch (e)
{
console.log(e);
}
}
}
}
function finishRound()
{
console.log("Finishing the round.");
g.dealerTurn();
console.log("Results:");
console.log("Dealer's Hand:");
game.printHand(g.dealerHand);
game.printPlayerHand(player);
console.log("RoundGainz:");
console.log(player.prevRoundResults);
console.log("The count is at",g.count,"and the real count is",g.realCount());
g.endOfRound();
console.log("Shoe size",g.shoe.length,"total cards (shouldnt change):",g.shoe.length + g.discards.length, "discards len:",g.discards.length);
}
function playerAction(ans, handNum)
{
if (ans === 'h')
{
g.playerHit(player, handNum);
}
else if (ans === 's')
{
g.playerStand(player, handNum);
}
else if (ans === 'd')
{
g.playerDouble(player, handNum);
}
else if (ans === 'p')
{
g.playerSplit(player, handNum);
}
else if (ans === 'u')
{
g.playerSurrender(player);
}
else
{
throw new Error("Please enter a valid option ([h]it, [s]tand, [d]ouble, s[p]lit, s[u]rrender");
}
}
dm.analyze(8000);
return;
main();