fix: 修复 poker.CardPile.Reset 函数导致牌组只有大小王的问题

This commit is contained in:
kercylan98 2023-10-11 09:41:34 +08:00
parent e60e0a754a
commit fb60065ec1
2 changed files with 42 additions and 4 deletions

View File

@ -78,14 +78,12 @@ func (slf *CardPile[P, C, T]) Reset() {
slf.guid++ slf.guid++
card := slf.generateCard(slf.guid, point, color) card := slf.generateCard(slf.guid, point, color)
slf.cards[slf.guid] = card slf.cards[slf.guid] = card
cards = append(cards, card)
} }
} }
} }
} }
slf.pile = slf.pile[0:0] slf.pile = cards
for i := 0; i < slf.size; i++ {
slf.pile = append(slf.pile, cards...)
}
} }
// IsExclude 检查特定点数和花色是否被排除在外 // IsExclude 检查特定点数和花色是否被排除在外

View File

@ -0,0 +1,40 @@
package poker_test
import (
"github.com/kercylan98/minotaur/game/poker"
"testing"
)
type Card struct {
Guid int64
Point int32
Color int32
}
func (slf *Card) GetGuid() int64 {
return slf.Guid
}
func (slf *Card) GetPoint() int32 {
return slf.Point
}
func (slf *Card) GetColor() int32 {
return slf.Color
}
func TestCardPile_PullTop(t *testing.T) {
var pile = poker.NewCardPile[int32, int32, *Card](6,
[2]int32{14, 15},
[13]int32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
[4]int32{1, 2, 3, 4},
func(guid int64, point int32, color int32) *Card {
return &Card{Guid: guid, Point: point, Color: color}
},
)
pile.Shuffle()
for i := 0; i < 10; i++ {
t.Log(pile.PullTop())
}
}