mirror of
https://github.com/Stone-Red-Code/se-poker.git
synced 2026-09-04 09:06:21 +02:00
Add tests
This commit is contained in:
@@ -182,4 +182,41 @@ func (h *Hand) Compare(other *Hand) int {
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// FindBestHand finds the best 5-card hand from 7 given cards.
|
||||
func FindBestHand(sevenCards []Card) (*Hand, error) {
|
||||
if len(sevenCards) != 7 {
|
||||
return nil, fmt.Errorf("expected 7 cards, got %d", len(sevenCards))
|
||||
}
|
||||
|
||||
var bestHand *Hand
|
||||
|
||||
// Generate all combinations of 5 cards from 7
|
||||
for i := 0; i < 7; i++ {
|
||||
for j := i + 1; j < 7; j++ {
|
||||
for k := j + 1; k < 7; k++ {
|
||||
for l := k + 1; l < 7; l++ {
|
||||
for m := l + 1; m < 7; m++ {
|
||||
currentCards := []Card{
|
||||
sevenCards[i], sevenCards[j], sevenCards[k], sevenCards[l], sevenCards[m],
|
||||
}
|
||||
currentHand := &Hand{Cards: currentCards}
|
||||
|
||||
if bestHand == nil {
|
||||
bestHand = currentHand
|
||||
} else {
|
||||
// Compare currentHand with bestHand
|
||||
// h.Compare(other) returns 1 if h wins, 2 if other wins, 0 for tie
|
||||
if currentHand.Compare(bestHand) == 1 {
|
||||
bestHand = currentHand
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bestHand, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user