A famous casino suddenly faces a huge decline in its revenue. So the casino decides to offer a new Poker online version. Can you help them write an algorithm to ranking the Poker hands?
Notes:
- A Poker hand is consists for 5 cards.
- Each card has a string with 2 (two) characters.
- The first character is the card value and it can have the values below, ranked from lowest to highest:
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- T (10)
- J (Jack)
- Q (Queen)
- K (King)
- A (Ace)
- The second character is the card suit and it can assume the values below.
- S (Spades)
- H (Hearts)
- D (Diamonds)
- C (Clubs)
- The first character is the card value and it can have the values below, ranked from lowest to highest:
- The rules for classifying Poker cards are listed below:
-
The challenge consists in create a class that represents a Poker hand called "PokerHand" and create a method to compare it with another Poker hand. The class "PokerHand" must have a constructor that accepts a string containing 5 (five) cards. A space will used as a separator for each card. Each card consists in 2 (two) characters as previously described. Let's see an example:
poker_hand_1 = PokerHand("KS 2H 5C JD TD") poker_hand_2 = PokerHand("9C 9H 5C 5H AC") result = poker_hand_1.compare_with(poker_hand_2) The result must be one enumerated with 2 (two) possible values that will represent the following states: WIN or LOSS.
-
The functioning of the solution must be guaranteed through unit tests.
The test cases can be verified in the jupyter notebook "I2A2 - Test N°1.ipynb". If you want to run the test cases in your console, download the file "I2A2_Test.py" and follow the instructions below:
In the console paste the following line:
python3.6 -m unittest -v I2A2_Test.TestPokerHand
In the console paste the following line:
python3.6 -m unittest I2A2_Test.TestPokercomparison