Welcome to Poker Night with LARVIS. This is a basic Poker module written in Go to add Poker playing abilities into LARVIS.
- Unbiased deck shuffling.
- Random and secret card drawing.
- Tie resolution.
- No gambling.
Download and install Go latest version. Download Docker (optional)
- fmt - printing
- math/rand - for shuffling cards, generating random numbers and resetting time
- sort - sorting hand values in ascending order
- time - delay printing to add drama before starting the game and resolving ties
- Draw a deck of card with symbols = 23456789TJQKA and their ranks = 2,3,4,5,6,7,8,9,10,11,12,13,14
- Shuffle the Deck. One symbol shouldn't occur more than 4 times in a deck.
- Distribute 5 cards to each player- Hand1 and Hand2.
- Compare both Hands to check which hand has higher combination value as per these rules :-
Combinations and their Rank in order of value:
- 1= Four of a kind, like 77377
- 2= Full house, means 3 of a kind, and 2 of a kind, in the same hand, like KK2K2
- 3= Triple, like 32666
- 4= Two pairs, like 77332
- 5= A pair, like 43K9K
- 6= High card, when there’s none of the above, like 297QJ
- Creates frequency map of each symbol and how many times it occurs. eg. {J:4,3:1}
- Calculate length of the slice[] of symbols from frequency map. Switch(length value) to compare the following rules :-
- if len=2 and [4][1] or [1][4] : rank 1= Four of a kind
- if len=2 and [3][2] or[2][3] : rank 2= Full house
- if len=3 and [3][1][1],[1][3][1] and [1][1][3] : rank 3= Triple
- if len=3 and [2][2][1],[2][1][2] and [1][2][2] : rank 4=Two Pairs
- if len=4 and [2][1][1][1],[1][2][1][1],[1][1][2][1] and [1][1][1][2] : rank 4=A Pairs
- if len=5 and [1][1][1][1][1] : rank 6=High Card
- Compare rank of Hand1 vs Hand2 and declare winner
- In case of a tie, where both hands have same rank value, call resolveTie().
- Resolving a tie uses sortAndCompare() and findHighestCard()
- if frequency {4,1} or {1,4}, then compare rank of card which has frequency 4. the player with higher rank wins. There can't be more than 4 cards of the same suit in a deck in this case.
- if frequency {3,2} or {2,3} or {3,1,1} or {1,3,1} or {1,1,3} then compare rank of card which has frequency 3. the player with higher rank wins. Since there can't be more than 3 cards of same suit in a deck in this case.
- if frequency {2,2,1} or {2,1,2} or {1,2,2} then compare cards with rank of frequency 2.
- if frequency {2,1,1,1} or {1,2,1,1} or {1,1,2,1} or {1,1,1,2} then first compare cards with frequency 2 for higher card. If both ranks are also same, then sort the ranks of cards, compare both hands and decide winner on the basis of higher rank of cards with frequency 1.
- if frequency {1,1,1,1,1} then sort the hands on the basis of their ranks and declare winner on the basis of highest rank.
- Declare winner and show hands of both players.
- Unzip files.
- CD to the path of Poker_Night folder.
- go run pokernight.go
- Open a terminal and navigate to the directory where the Dockerfile is located.
- Run the following commands to build the Dockerfile and then run the program in a container in an interactive view.
- docker build --pull --rm -f "Dockerfile" -t pokernight:latest "."
- docker run -it --name poker-night pokernight
We have not incorporated Suits (heart,spades,ace and diamond)