40 lines
691 B
Go
40 lines
691 B
Go
|
package pokercore
|
||
|
|
||
|
import "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, fmt.Errorf("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)
|
||
|
}
|