A
~> npm install -g @nickgraffis/blackjack
~> blackjack
- Try to get the highest card total without going over 21.
- 2 - 9 is face value
- ['π', 'πΈ', 'π€΄'] are all 10
- 'A' is 11 or 1 if you bust
- 'A' + ['π', 'πΈ', 'π€΄'] is Black Jack! Automatic winner
- Dealer will not hit past 17
- Tie goes to the house :(
Pretty simple and straight forward, except the recursive design of the computers hand.
var computerAsyncHand = function() {![image](https://user-images.githubusercontent.com/27028689/142096251-23671a4a-0672-4996-a5ad-564153c46782.gif)
if (computerTurn < 2) {
computerHand.push(randomPoints());
computerTurn++;
computerHand.push(randomPoints());
computerTurn++;
console.log(dealCard(computerHand[0], randomInt(4)));
console.log(dealCard(computerHand[1], randomInt(4)));
console.log(computerHand.reduce((a, b) => a + b, 0));
sleep(1000);
}
if (computerHand.includes(11)) {
var Ace = computerHand.indexOf(11);
computerHand[Ace] = 1;
console.log('Dealer score is now ' + computerHand.reduce((a, b) => a + b, 0) + ', using the A as a 1!');
}
if (computerHand.reduce((a, b) => a + b, 0) > 17) {
//Game Over
return;
} else {
computerHand.push(randomPoints());
computerTurn++;
console.log(dealCard(computerHand[computerTurn - 1], randomInt(4)));
console.log(computerHand.reduce((a, b) => a + b, 0));
}
sleep(1000);
computerAsyncHand();
}