From fb60065ec1d1cc0d0890c6c1767dd82b2c28517e Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Wed, 11 Oct 2023 09:41:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20poker.CardPile.Rese?= =?UTF-8?q?t=20=E5=87=BD=E6=95=B0=E5=AF=BC=E8=87=B4=E7=89=8C=E7=BB=84?= =?UTF-8?q?=E5=8F=AA=E6=9C=89=E5=A4=A7=E5=B0=8F=E7=8E=8B=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/poker/card_pile.go | 6 ++---- game/poker/card_pile_test.go | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 game/poker/card_pile_test.go 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()) + } +}