Poker hand analyser: Difference between revisions

Added AutoHotkey
(Added Scala)
(Added AutoHotkey)
Line 66:
joker 2♦ 2♠ joker q♦: four-of-a-kind
<br><br>
 
=={{header|AutoHotkey}}==
<lang AutoHotkey>PokerHand(hand){
StringUpper, hand, hand
Sort, hand, FCardSort D%A_Space%
cardSeq := RegExReplace(hand, "[^2-9TJQKA]")
Straight:= InStr("23456789TJQKA", cardSeq) || (cardSeq = "2345A") ? true : false
hand := cardSeq = "2345A" ? RegExReplace(hand, "(.*)\h(A.)", "$2 $1") : hand
Royal := InStr(hand, "A") ? "Royal": "Straight"
return (hand ~= "[2-9TJQKA](.)\h.\1\h.\1\h.\1\h.\1") && (Straight) ? hand "`t" Royal " Flush"
: (hand ~= "([2-9TJQKA]).*?\1.*?\1.*?\1") ? hand "`tFour of a Kind"
: (hand ~= "^([2-9TJQKA]).\h\1.\h(?!\1)([2-9TJQKA]).\h\2.\h\2.$") ? hand "`tFull House" ; xxyyy
: (hand ~= "^([2-9TJQKA]).\h\1.\h\1.\h(?!\1)([2-9TJQKA]).\h\2.$") ? hand "`tFull House" ; xxxyy
: (hand ~= "[2-9TJQKA](.)\h.\1\h.\1\h.\1\h.\1") ? hand "`tFlush"
: (Straight) ? hand "`tStraight"
: (hand ~= "([2-9TJQKA]).*?\1.*?\1") ? hand "`tThree of a Kind"
: (hand ~= "([2-9TJQKA]).\h\1.*?([2-9TJQKA]).\h\2") ? hand "`tTwo Pair"
: (hand ~= "([2-9TJQKA]).\h\1") ? hand "`tOne Pair"
: hand "`tHigh Card"
}</lang>
Examples:<lang AutoHotkey>hands =
(join`r`n
2♥ 2♦ 2♣ k♣ q♦
2♥ 5♥ 7♦ 8♣ 9♠
a♥ 2♦ 3♣ 4♣ 5♦
2♥ 3♥ 2♦ 3♣ 3♦
2♥ 3♥ 2♦ 2♣ 3♦
2♥ 7♥ 2♦ 3♣ 3♦
2♥ 7♥ 7♦ 7♣ 7♠
T♥ j♥ q♥ a♥ K♥
T♥ j♥ q♥ 9♥ K♥
4♥ 4♠ k♠ 5♦ T♠
q♣ T♣ 7♣ 6♣ 4♣
)
loop, parse, hands, `n, `r
res .= PokerHand(A_LoopField) "`n"
MsgBox, 262144, , % res
return</lang>
Outputs:<pre>2♦ 2♣ 2♥ Q♦ K♣ Three of a Kind
2♥ 5♥ 7♦ 8♣ 9♠ High Card
A♥ 2♦ 3♣ 4♣ 5♦ Straight
2♦ 2♥ 3♣ 3♦ 3♥ Full House
2♣ 2♦ 2♥ 3♦ 3♥ Full House
2♦ 2♥ 3♣ 3♦ 7♥ Two Pair
2♥ 7♦ 7♣ 7♠ 7♥ Four of a Kind
T♥ J♥ Q♥ K♥ A♥ Royal Flush
9♥ T♥ J♥ Q♥ K♥ Straight Flush
4♠ 4♥ 5♦ T♠ K♠ One Pair
4♣ 6♣ 7♣ T♣ Q♣ Flush</pre>
 
=={{header|C}}==
299

edits