rwx-yxu / blackjack

A simple commandline black jack simulator written in Go
Apache License 2.0
0 stars 0 forks source link

Spec/Design #1

Closed rwx-yxu closed 1 year ago

rwx-yxu commented 1 year ago

Opening issue to track the specifications and design for a command line blackjack simulator written in Go.

Blackjack is a card game that allows for the player to draw 2 cards from a shuffled deck. The player may draw cards one at a time to get as close or match 21.

Win state: Sum of cards total 21.

Lose state: Sum of cards are above 21.

The simple work flow will be as follows:

rwx-yxu commented 1 year ago

Preliminary structs to create

type deck struct{

}

type card struct{

}

type blackjack struct{

}

type Player struct{

}
rwx-yxu commented 1 year ago

For blackjack, we only care about the card value. The type such as spade or diamond doesn't matter. Standard 52 card deck list:

rwx-yxu commented 1 year ago

Watched this video on blackjack to get an understanding how it is played: https://www.youtube.com/watch?v=PljDuynF-j0 Should have a "dealer" struct as well and have the player against the dealer. Might mean that I do not need the "blackjack" struct because the dealer is in control of the deck and dealing of cards.

rwx-yxu commented 1 year ago

Going to create the deck struct first that is populated by cards

rwx-yxu commented 1 year ago

Been thinking about how to populate a deck of cards such that there are four cards for each value. The cards have to be randomized before the game is playable. I could either randomly choose a card to add to check only if the cards of that type in deck are less than 4 in the deck or I could generate an in order deck list and then shuffle the deck by picking out random ones to populate a new "shuffled deck".

rwx-yxu commented 1 year ago

Generating the cards in order will require a shuffle method but should that be an explicit thing to made? Performance wise, it will be worse but a new deck of cards should be shuffled. Going back to the video, they play until the deck is done. The deck isn't shuffled after each round. Once the deck is finished, a new deck is taken out.

Overall point is that shuffle doesn't seem to be done after each round so going with option one seems to make more sense.

rwx-yxu commented 1 year ago

Should introduce a map variable to keep track of card type occurrences in the deck

var m map[string]int

Really leaning more towards making an enum list for each card mainly because I can then use the random methods to generate a random item to add to the deck provided that the occurrences are less than 4. This would then be passed into a switch statement for the enum to create the card struct matched with the values.

Since they will be enum types, I can also check for Ace as well if it is drawn.

rwx-yxu commented 1 year ago

Questions to answer: When program starts, what should be the output exactly? Is it better to show each draw happening or just show something like: "player cards: Ace, Ten" and under it, "Dealer cards: ?, Four" What should be the player options after being presented with the cards?

rwx-yxu commented 1 year ago

I think players will have the choice of to draw or stand with their cards. What should be out put if it is an ace? If I present them the cards, do I also need to show a points total as well? Spec says that the player chooses but looking at how blackjack is played, the Ace will be treated as the highest possible number unless the total goes over 21 which it is then valued at 1.

rwx-yxu commented 1 year ago

Decided that I should split the game into "Phases".

The first phase will be the initial drawing of cards for player and dealer.

The next phase is the player phase whereby they decide if they want to draw more or stand.

Final phase is dealer phase where the dealer card is revealed and they will draw if their total value is lower than player total.

rwx-yxu commented 1 year ago

Made a mistake. The ace value is 1 or 11... I have thought it was 10 which I defaulted to. Will fix tomorrow.

Reference for ace value: https://www.quora.com/When-is-an-ace-considered-as-1-or-11-in-Blackjack

rwx-yxu commented 1 year ago

Initial release completed. Closing issue.