pokercore/scoring.go

43 lines
706 B
Go

package pokercore
import (
"errors"
"fmt"
)
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 {
return 0, errors.New("hand must have 5 cards to be scored as a poker hand")
}
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)
}