Skip to content

Instantly share code, notes, and snippets.

@ShogunPanda
Created September 7, 2024 07:10
Show Gist options
  • Save ShogunPanda/9310bd92023d57ee7ed797140c64fbf9 to your computer and use it in GitHub Desktop.
Save ShogunPanda/9310bd92023d57ee7ed797140c64fbf9 to your computer and use it in GitHub Desktop.
International Kids Coding Challenge

Quick Poker

Your challenge is to create a little poker game using any technology of your choice.

Don't worry if you don't know poker, the next paragraph is your best friend.

Rules of the game.

The deck

The game is played using standard 52 deck cards.

Each card has a suit, which can be Spades (S), Clubs (C), Diamonds (D) and Hearts (H).

Each card has also a value, which can be one of the following categories:

  • Numeric value, ranging from 2 to 10. From now on, 10 will be abbreviated as T.
  • Jack (J)
  • Queen (Q)
  • King (K)
  • Ace (A)

Suits and value above are listed in reversed order of importance: a Hearts card has higher point than a Diamonds card and a Ace card has higher point than a Queen card.

From now on, a card will be referred using the value letter and the suit letter. For instance:

  • AS: Ace of Spades
  • TH: Ten of Hearts
  • 3D: Three of Diamonds

The combinations

Each player draws 5 cards, which is then called its hand.

From now on a hand can be referred as the sequence of the cards values or the list of cards joined by commas, For instance:

  • 2457A (when suits don't matter)
  • 2S,3D,5C,7D,AS (when suit matter)

Each hand forms one or more of the following combinations:

  • High Card: All cards have different values.
  • One pair: Two cards have the same value.
  • Two pairs: Two card have a value, two other cards have another value.
  • Three of a kind: Three cards have the same value.
  • Straight: The cards have a sequential order of values.
  • Flush: All the card have the same suit.
  • Full house: Three cards have a value, the other two cards have another value.
  • Four of a kind: Four cards have the same value.
  • Straight flush: Like straight, but all the cards have the same suit.

The combinations above are listed in reversed order of importance: a "Flush" has higher importance of a "Two pairs" and so forth.

Each combination has a ranking, which is the value of the highest card included in the combination. For instance, the ranking of 2233A is 3.

Each combination has a suite, which is the highest suit of the cards included in the combination. For instance, the suit of 2S,3D,3C,3D,AS is D.

Following up is a table with some example of combinations

Combination Example
High Card 2457A
One pair 2278A
Two pairs 3355K
Three of a kind AAAT6
Straight TJQKA or 23456
Flush 2S,4S,7S,8S,AS
Full house TTT22
Four of a kind AAAA2
Straight flush TS,JS,QS,KS,AS or 2S,3S,4S,5S,6S

Play the game

  1. Generate a standard deck of 52 cards, identified with the two-letters notation explained above.
  2. Shuffle the deck. Any randomization tecnique is acceptable. You can modify the original deck in place if you want.
  3. Generate a game by drawing two hands of 5 cards by removing cards from the top or bottom of the deck. Cards must be assigned to each player in alternative order.
  4. Choose the highest possible combination for each hand. Compute the rank of each hand. Print all these info.
  5. Choose the winning hand. Look at the combination first, then the ranking.
  6. Print which player wins the game of if there is a draw.

Bonus variant

  • Compute and evaluate the suit of each hand to eventually break a tie.

Note about drawing hands

Once a hand is drawn in step 3, the cards are removed from the decks and cannot appear in subsequent games generated using the same deck.

You can, depending on the programming language chosen, to either return the unextracted cards as the new deck or to modify the original deck in place.

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