diff --git a/game/poker/card_pile.go b/game/poker/card_pile.go index 17d9c17..e9a0421 100644 --- a/game/poker/card_pile.go +++ b/game/poker/card_pile.go @@ -78,14 +78,12 @@ func (slf *CardPile[P, C, T]) Reset() { slf.guid++ card := slf.generateCard(slf.guid, point, color) slf.cards[slf.guid] = card + cards = append(cards, card) } } } } - slf.pile = slf.pile[0:0] - for i := 0; i < slf.size; i++ { - slf.pile = append(slf.pile, cards...) - } + slf.pile = cards } // IsExclude 检查特定点数和花色是否被排除在外 diff --git a/game/poker/card_pile_test.go b/game/poker/card_pile_test.go new file mode 100644 index 0000000..1c76a60 --- /dev/null +++ b/game/poker/card_pile_test.go @@ -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()) + } +}