2024-05-19 00:33:15 +00:00
|
|
|
package pokercore
|
|
|
|
|
2024-05-19 03:26:08 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
)
|
2024-05-19 00:33:15 +00:00
|
|
|
|
|
|
|
type HandScore int
|
|
|
|
|
|
|
|
const (
|
|
|
|
ScoreHighCard = HandScore(iota * 100_000_000_000)
|
|
|
|
ScorePair
|
|
|
|
ScoreTwoPair
|
|
|
|
ScoreThreeOfAKind
|
|
|
|
ScoreStraight
|
|
|
|
ScoreFlush
|
|
|
|
ScoreFullHouse
|
|
|
|
ScoreFourOfAKind
|
|
|
|
ScoreStraightFlush
|
|
|
|
ScoreRoyalFlush
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c Card) Score() HandScore {
|
|
|
|
return HandScore(c.Rank.Score())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Cards) PokerHandScore() (HandScore, error) {
|
|
|
|
if len(c) != 5 {
|
2024-05-19 03:26:08 +00:00
|
|
|
return 0, errors.New("hand must have 5 cards to be scored as a poker hand")
|
2024-05-19 00:33:15 +00:00
|
|
|
}
|
|
|
|
ph, err := c.PokerHand()
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
//fmt.Println(ph)
|
|
|
|
return ph.Score, nil
|
|
|
|
}
|
|
|
|
func (x HandScore) String() string {
|
|
|
|
return fmt.Sprintf("<HandScore %d>", x)
|
|
|
|
//return scoreToName(x)
|
|
|
|
}
|