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