4 kyu

Ranking Poker Hands

1,271 of 3,493FrankK

Description:

A famous casino is suddenly faced with a sharp decline of their revenues. They decide to offer Texas hold'em also online. Can you help them by writing an algorithm that can rank poker hands?

Task

Create a poker hand that has a method to compare itself to another poker hand:

Result PokerHand.CompareWith(PokerHand hand);
PokerHand.compareWith: hand: PokerHand -> Result
Result PokerHand.compareWith(PokerHand hand);
PokerHand.prototype.compareWith = function(hand){...};
Result compare (Hand* player, Hand* opponent);
Result compare (const PokerHand &player, const PokerHand &opponent);
compare_with(self, other_hand)
compare_with(other_hand)
PokerHand.compare(String player, String opponent)

A poker hand has a constructor that accepts a string containing 5 cards:

PokerHand hand = new PokerHand("KS 2H 5C JD TD");
let hand = PokerHand("KS 2H 5C JD TD")
PokerHand hand = new PokerHand("KS 2H 5C JD TD");
var hand = new PokerHand("KS 2H 5C JD TD");
Hand *hand = PokerHand ("KS 2H 5C JD TD");
PokerHand hand ("KS 2H 5C JD TD");
PokerHand("KS 2H 5C JD TD")
PokerHand.new("KS 2H 5C JD TD")
# no constructor in elixir, pass the string into the compare
"KS 2H 5C JD TD"

The characteristics of the string of cards are:

  • Each card consists of two characters, where
  • The first character is the value of the card: 2, 3, 4, 5, 6, 7, 8, 9, T(en), J(ack), Q(ueen), K(ing), A(ce)
  • The second character represents the suit: S(pades), H(earts), D(iamonds), C(lubs)
  • A space is used as card separator between cards

The result of your poker hand compare can be one of these 3 options:

public enum Result 
{ 
    Win, 
    Loss, 
    Tie 
}
type Result =
| Win = 0 
| Loss = 1
| Tie = 2
public enum Result
{
    WIN,
    LOSS,
    TIE
}
var Result = 
{
    "win": 1,
    "loss": 2,
    "tie": 3
}
typedef enum { Win, Loss, Tie } Result;
enum class Result { Win, Loss, Tie };
[ "Win", "Tie", "Loss" ]
[ "Win", "Tie", "Loss" ]
@result %{win: 1, loss: 2, tie: 3}

Notes

  • Apply the Texas Hold'em rules for ranking the cards.
  • Low aces are valid in this kata.
  • There is no ranking for the suits.

If you finished this kata, you might want to continue with Sortable Poker Hands

Games
Algorithms
Object-oriented Programming

More By Author:

Check out these other kata created by FrankK

Stats:

CreatedMay 16, 2016
PublishedMay 16, 2016
Warriors Trained26966
Total Skips10636
Total Code Submissions46790
Total Times Completed3493
C# Completions482
Java Completions574
F# Completions33
JavaScript Completions670
C Completions118
C++ Completions274
Python Completions1271
Elixir Completions32
Ruby Completions93
Total Stars1153
% of votes with a positive feedback rating92% of 721
Total "Very Satisfied" Votes629
Total "Somewhat Satisfied" Votes72
Total "Not Satisfied" Votes20
Total Rank Assessments8
Average Assessed Rank
4 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • FrankK Avatar
  • anter69 Avatar
  • Dentzil Avatar
  • kazk Avatar
  • B1ts Avatar
  • Blind4Basics Avatar
  • nomennescio Avatar
  • Voile Avatar
  • richkotze Avatar
  • hobovsky Avatar
  • Kacarott Avatar
  • Harold2017 Avatar
  • Just4FunCoder Avatar
Ad