linting and formatting updates
This commit is contained in:
parent
ab92f29a88
commit
6c66adf8d3
2
card.go
2
card.go
@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/logrusorgru/aurora/v4"
|
||||
aurora "github.com/logrusorgru/aurora/v4"
|
||||
)
|
||||
|
||||
type Card struct {
|
||||
|
||||
78
pokerhand.go
78
pokerhand.go
@ -62,13 +62,13 @@ func (c Cards) PokerHand() (*PokerHand, error) {
|
||||
return ph, nil
|
||||
}
|
||||
|
||||
func (ph PokerHand) ToSortedCards() Cards {
|
||||
func (ph *PokerHand) ToSortedCards() Cards {
|
||||
// I believe ph.Hand is already sorted, but in any case it's only 5
|
||||
// cards and sorting it costs ~nothing
|
||||
return ph.Hand.SortByRankAscending()
|
||||
}
|
||||
|
||||
func (ph PokerHand) Compare(other PokerHand) int {
|
||||
func (ph *PokerHand) Compare(other PokerHand) int {
|
||||
if ph.Score > other.Score {
|
||||
return 1
|
||||
}
|
||||
@ -78,74 +78,74 @@ func (ph PokerHand) Compare(other PokerHand) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (ph PokerHand) HighestRank() Rank {
|
||||
func (ph *PokerHand) HighestRank() Rank {
|
||||
return ph.Hand.HighestRank()
|
||||
}
|
||||
|
||||
func (ph PokerHand) String() string {
|
||||
func (ph *PokerHand) String() string {
|
||||
return fmt.Sprintf("<PokerHand: %s (%s)>", ph.Hand.String(), ph.Description())
|
||||
}
|
||||
|
||||
func (c PokerHand) Description() string {
|
||||
if c.Type == RoyalFlush {
|
||||
return fmt.Sprintf("a royal flush in %s", c.Hand[0].Suit)
|
||||
func (ph *PokerHand) Description() string {
|
||||
if ph.Type == RoyalFlush {
|
||||
return fmt.Sprintf("a royal flush in %s", ph.Hand[0].Suit)
|
||||
}
|
||||
if c.Hand.containsStraightFlush() {
|
||||
if c.Hand[3].Rank == FIVE && c.Hand[4].Rank == ACE {
|
||||
if ph.Hand.containsStraightFlush() {
|
||||
if ph.Hand[3].Rank == FIVE && ph.Hand[4].Rank == ACE {
|
||||
// special case for steel wheel
|
||||
return fmt.Sprintf("%s high straight flush in %s", c.Hand[3].Rank.WithArticle(), c.Hand[4].Suit)
|
||||
return fmt.Sprintf("%s high straight flush in %s", ph.Hand[3].Rank.WithArticle(), ph.Hand[4].Suit)
|
||||
}
|
||||
return fmt.Sprintf("%s high straight flush in %s", c.HighestRank().WithArticle(), c.Hand[4].Suit)
|
||||
return fmt.Sprintf("%s high straight flush in %s", ph.HighestRank().WithArticle(), ph.Hand[4].Suit)
|
||||
}
|
||||
if c.Hand.containsFourOfAKind() {
|
||||
return fmt.Sprintf("four %s with %s", c.Hand.fourOfAKindRank().Pluralize(), c.Hand.fourOfAKindKicker().Rank.WithArticle())
|
||||
if ph.Hand.containsFourOfAKind() {
|
||||
return fmt.Sprintf("four %s with %s", ph.Hand.fourOfAKindRank().Pluralize(), ph.Hand.fourOfAKindKicker().Rank.WithArticle())
|
||||
}
|
||||
if c.Hand.containsFullHouse() {
|
||||
return fmt.Sprintf("a full house, %s full of %s", c.Hand.fullHouseTripsRank().Pluralize(), c.Hand.fullHousePairRank().Pluralize())
|
||||
if ph.Hand.containsFullHouse() {
|
||||
return fmt.Sprintf("a full house, %s full of %s", ph.Hand.fullHouseTripsRank().Pluralize(), ph.Hand.fullHousePairRank().Pluralize())
|
||||
}
|
||||
if c.Hand.containsFlush() {
|
||||
return fmt.Sprintf("%s high flush in %s", c.HighestRank().WithArticle(), c.Hand[4].Suit)
|
||||
if ph.Hand.containsFlush() {
|
||||
return fmt.Sprintf("%s high flush in %s", ph.HighestRank().WithArticle(), ph.Hand[4].Suit)
|
||||
}
|
||||
if c.Hand.containsStraight() {
|
||||
if c.Hand[3].Rank == FIVE && c.Hand[4].Rank == ACE {
|
||||
if ph.Hand.containsStraight() {
|
||||
if ph.Hand[3].Rank == FIVE && ph.Hand[4].Rank == ACE {
|
||||
// special case for wheel straight
|
||||
return fmt.Sprintf("%s high straight", c.Hand[3].Rank.WithArticle())
|
||||
return fmt.Sprintf("%s high straight", ph.Hand[3].Rank.WithArticle())
|
||||
}
|
||||
return fmt.Sprintf("%s high straight", c.HighestRank().WithArticle())
|
||||
return fmt.Sprintf("%s high straight", ph.HighestRank().WithArticle())
|
||||
}
|
||||
if c.Hand.containsThreeOfAKind() {
|
||||
if ph.Hand.containsThreeOfAKind() {
|
||||
return fmt.Sprintf(
|
||||
"three %s with %s and %s",
|
||||
c.Hand.threeOfAKindTripsRank().Pluralize(),
|
||||
c.Hand.threeOfAKindFirstKicker().Rank.WithArticle(),
|
||||
c.Hand.threeOfAKindSecondKicker().Rank.WithArticle(),
|
||||
ph.Hand.threeOfAKindTripsRank().Pluralize(),
|
||||
ph.Hand.threeOfAKindFirstKicker().Rank.WithArticle(),
|
||||
ph.Hand.threeOfAKindSecondKicker().Rank.WithArticle(),
|
||||
)
|
||||
}
|
||||
if c.Hand.containsTwoPair() {
|
||||
if ph.Hand.containsTwoPair() {
|
||||
return fmt.Sprintf(
|
||||
"two pair, %s and %s with %s",
|
||||
c.Hand.twoPairBiggestPair().Pluralize(),
|
||||
c.Hand.twoPairSmallestPair().Pluralize(),
|
||||
c.Hand.twoPairKicker().Rank.WithArticle(),
|
||||
ph.Hand.twoPairBiggestPair().Pluralize(),
|
||||
ph.Hand.twoPairSmallestPair().Pluralize(),
|
||||
ph.Hand.twoPairKicker().Rank.WithArticle(),
|
||||
)
|
||||
}
|
||||
if c.Hand.containsPair() {
|
||||
if ph.Hand.containsPair() {
|
||||
return fmt.Sprintf(
|
||||
"a pair of %s with %s, %s, and %s",
|
||||
c.Hand.pairRank().Pluralize(),
|
||||
c.Hand.pairFirstKicker().Rank.WithArticle(),
|
||||
c.Hand.pairSecondKicker().Rank.WithArticle(),
|
||||
c.Hand.pairThirdKicker().Rank.WithArticle(),
|
||||
ph.Hand.pairRank().Pluralize(),
|
||||
ph.Hand.pairFirstKicker().Rank.WithArticle(),
|
||||
ph.Hand.pairSecondKicker().Rank.WithArticle(),
|
||||
ph.Hand.pairThirdKicker().Rank.WithArticle(),
|
||||
)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
// "ace high with an eight, a seven, a six, and a deuce"
|
||||
"%s high with %s, %s, %s, and %s",
|
||||
c.Hand[4].Rank,
|
||||
c.Hand[3].Rank.WithArticle(),
|
||||
c.Hand[2].Rank.WithArticle(),
|
||||
c.Hand[1].Rank.WithArticle(),
|
||||
c.Hand[0].Rank.WithArticle(),
|
||||
ph.Hand[4].Rank,
|
||||
ph.Hand[3].Rank.WithArticle(),
|
||||
ph.Hand[2].Rank.WithArticle(),
|
||||
ph.Hand[1].Rank.WithArticle(),
|
||||
ph.Hand[0].Rank.WithArticle(),
|
||||
)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user