Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a blackjack command to gamble #5821

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

TastyPumPum
Copy link
Contributor

Adds the blackjack game to the gamble command.
Allows players to win up to 2x their stake by beating the dealer/bot.

  • I have tested all my changes thoroughly.

Adds the blackjack game to the gamble command.
Allows players to win up to 2x their stake by beating the dealer/bot.
@TastyPumPum TastyPumPum changed the title Blackjack Add a blackjack command to gamble Apr 8, 2024
@AvariceBrah
Copy link

you madlad, i love it

@gc
Copy link
Collaborator

gc commented Apr 14, 2024

Big tip: Try to code this in a fully abstracted way, so that its a lot easier to test (which is important so we know exactly for a fact the odds/rates of this, and just generally to test it for bugs), e.g. such as how hunterActivity.ts is in bso. I like the blackjack idea

Copy link
Contributor

@themrrobert themrrobert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is still a work in progress, and I haven't gone thru all of it, but here are some good notes :)


// Function to shuffle the deck
function shuffleDeck(deck: Card[]): void {
for (let i = deck.length - 1; i > 0; i--) {
Copy link
Contributor

@themrrobert themrrobert Apr 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be i >=0 otherwise the loop where i = 0 is not executed, and you're just hoping the shuffle chooses card zero.

Basically if you don't do >=0, then the 0th card ends up unshuffled (2 of Hearts) a disproportionate amount of the time.

// Function to shuffle the deck
function shuffleDeck(deck: Card[]): void {
for (let i = deck.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use a nodeCrypto random, try cryptoRand() from util.ts, and you don't need to floor it.

Alternatively, randFloat() from util.ts also uses nodeCrypto, but why use two functions when you can use one? :D

}

// Function to shuffle the deck
function shuffleDeck(deck: Card[]): void {
Copy link
Contributor

@themrrobert themrrobert Apr 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shuffle looks pretty good, but I would still shuffle the deck at least 2-3 times. (either multiple calls to shuffle deck, or more likely just loop inside the function 2-3 times)

const dealerHand = [dealCard(deck), dealCard(deck)];

// Check for player blackjack
if (calculateHandValue(playerHand) === 21) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blackjack should pay 2.5x (1.5x their bet in profit).

Or a push if dealer also has blackjack.

You could get crazy with insurance, even-money on blackjack vs A, etc, but that's probably not necessary :D


// Define constants for suits and values
const suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades'];
const values = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King', 'Ace'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It MIGHT make formatting the game easier if you use a single char for card values (and suits?).

eg. 10 = 'T', J, K , Q, A

It would be REALLY cool to dynamically generate the result like slots. You don't have to draw the entire card, just a simple box around painted unicode letters, 3♠, A♥ etc. Paint spades/clubs black, and hearts/diamonds red. T♣

Look at slots for simple graphics stuff, and the bank code has examples of drawing text (including unicode symbols) onto canvas)

@TastyPumPum
Copy link
Contributor Author

I know this is still a work in progress, and I haven't gone thru all of it, but here are some good notes :)

Appreciate all the feedback, especially like the single char idea for card values.

Paying 2.5x for blakcjack, i didnt know if magna would be happy with the win % and that's also why i made it so you currently have to beat the dealer, and there is no pushes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants