// WinningHands returns the highest ranking hands with the given sorting. func (h hands) winningHands(sorting hand.Sorting) hands { // copy all eligible hands (for Stud8 & Omaha8) handsCopy := hands(map[int]*hand.Hand{}) for seat, hand := range h { if hand != nil { handsCopy[seat] = hand } } if len(handsCopy) == 0 { return handsCopy } s := handsCopy.slice() s = hand.Sort(sorting, hand.DESC, s...) best := s[0] selected := map[int]*hand.Hand{} for seat, hand := range handsCopy { if best.CompareTo(hand) == 0 { selected[seat] = hand } } return hands(selected) }
func (g *holdemGame) FormHighHand(holeCards []*hand.Card, board []*hand.Card) *hand.Hand { if !g.IsOmaha { cards := append(board, holeCards...) return hand.New(cards) } opts := func(c *hand.Config) {} hands := omahaHands(holeCards, board, opts) hands = hand.Sort(hand.SortingHigh, hand.DESC, hands...) return hands[0] }
func (g *holdemGame) FormLowHand(holeCards []*hand.Card, board []*hand.Card) *hand.Hand { if !g.IsOmaha { return nil } hands := omahaHands(holeCards, board, hand.AceToFiveLow) hands = hand.Sort(hand.SortingLow, hand.DESC, hands...) if hands[0].CompareTo(eightOrBetter) <= 0 { return hands[0] } return nil }
"testing" "github.com/loganjspears/joker/hand" "github.com/loganjspears/joker/jokertest" ) var ( holdemFunc = func(holeCards []*hand.Card, board []*hand.Card) *hand.Hand { cards := append(board, holeCards...) return hand.New(cards) } omahaHiFunc = func(holeCards []*hand.Card, board []*hand.Card) *hand.Hand { opts := func(c *hand.Config) {} hands := omahaHands(holeCards, board, opts) hands = hand.Sort(hand.SortingHigh, hand.DESC, hands...) return hands[0] } omahaLoFunc = func(holeCards []*hand.Card, board []*hand.Card) *hand.Hand { hands := omahaHands(holeCards, board, hand.AceToFiveLow) hands = hand.Sort(hand.SortingLow, hand.DESC, hands...) if hands[0].CompareTo(eightOrBetter) <= 0 { return hands[0] } return nil } ) func TestPotJSON(t *testing.T) { t.Parallel()