Browse Source

analyze max hand bugfix

master
tangmingyou 4 years ago
parent
commit
9286e84301
  1. 14
      cmd/main.go
  2. 37
      internal/game/hand.go

14
cmd/main.go

@ -21,4 +21,18 @@ func startServer() {
func main() {
startServer()
//hand := [2]*game.Card{
// {Dot: game.PokerK, Suit: game.Diamond},
// {Dot: game.Poker10, Suit: game.Heart},
//}
//public := [5]*game.Card{
// {Dot: game.Poker4, Suit: game.Diamond},
// {Dot: game.Poker9, Suit: game.Club},
// {Dot: game.PokerJ, Suit: game.Diamond},
// {Dot: game.Poker2, Suit: game.Diamond},
// {Dot: game.Poker2, Suit: game.Spade},
//}
//maxHand, err := game.AnalyzeMaxHand(hand, public)
//fmt.Println(err, maxHand)
}

37
internal/game/hand.go

@ -53,12 +53,12 @@ func (h *Hand) GetPoint() int {
type CardType int
func (ct CardType) String() string {
f, _ := strconv.ParseFloat(strconv.Itoa(int(ct)>>13), 32)
return cardTypeNames[int(math.Log2(f))]
return ct.NameZh()
}
func (ct CardType) Name() string {
return ct.String()
f, _ := strconv.ParseFloat(strconv.Itoa(int(ct)>>13), 32)
return cardTypeNames[int(math.Log2(f))]
}
func (ct CardType) NameZh() string {
@ -108,17 +108,26 @@ func AnalyzeMaxHand(handCards [2]*Card, publicCards [5]*Card) (*Hand, error) {
return new(Hand).Init(cards), nil
}
// 查找最大分数组合
// tempCards := allCards[:5]
copy(cards[:], allCards[:5])
maxHand := new(Hand).Init(cards)
for i := 0; i < len(cards); i++ {
for j := 5; j < len(allCards); j++ {
var tempCards = cards
tempCards[i] = allCards[j]
h := new(Hand).Init(tempCards)
if h.point > maxHand.point {
maxHand = h
cardsLen := len(allCards)
tempCards := [5]*Card{}
var maxHand *Hand
// 遍历和公共牌的所有组合
for i := 0; i < cardsLen; i++ {
tempCards[0] = allCards[i]
for j := i + 1; j < cardsLen; j++ {
tempCards[1] = allCards[j]
for k := j + 1; k < cardsLen; k++ {
tempCards[2] = allCards[k]
for m := k + 1; m < cardsLen; m++ {
tempCards[3] = allCards[m]
for n := m + 1; n < cardsLen; n++ {
tempCards[4] = allCards[n]
tempHand := new(Hand).Init(tempCards)
if maxHand == nil || tempHand.point > maxHand.point {
maxHand = tempHand
}
}
}
}
}
}

Loading…
Cancel
Save