From 253ef9ce0aedee1bb3ec0feb2a7c4231f2c338d1 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 7 Jan 2024 16:06:39 +1300 Subject: [PATCH] fix subslice instead of copy when dealing initial hand --- game.go | 3 ++- game_test.go | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/game.go b/game.go index 895b5bc..0b15457 100644 --- a/game.go +++ b/game.go @@ -55,7 +55,8 @@ func NewRound(round, numPlayers int, entropy *rand.Rand) *Round { r.hands = make([][]Card, numPlayers) for p := 0; p < numPlayers; p++ { - r.hands[p] = r.d[0:round] // Deal from the bottom (0) + r.hands[p] = make([]Card, round, round+1) + copy(r.hands[p], r.d[0:round]) // Deal from the bottom (0) r.d = r.d[round:] fmt.Printf("P%d starting hand: %v\n", p, r.hands[p]) diff --git a/game_test.go b/game_test.go index c03da56..1ddede3 100644 --- a/game_test.go +++ b/game_test.go @@ -15,7 +15,7 @@ func TestPlayRound(t *testing.T) { nextPlayer, scores := rr.Play(0) assert.EqualValues(t, 0, nextPlayer) - assert.EqualValues(t, []int{0, 28, 6, 6}, scores) + assert.EqualValues(t, []int{0, 36, 6, 26}, scores) } func TestPlayRound2(t *testing.T) { @@ -25,8 +25,8 @@ func TestPlayRound2(t *testing.T) { rr := NewRound(3, 4, entropy) nextPlayer, scores := rr.Play(0) - assert.EqualValues(t, 0, nextPlayer) - assert.EqualValues(t, []int{0, 28, 6, 6}, scores) + assert.EqualValues(t, 1, nextPlayer) + assert.EqualValues(t, []int{21, 0, 16, 26}, scores) } func TestDrawDiscard(t *testing.T) {