fix subslice instead of copy when dealing initial hand

This commit is contained in:
mappu 2024-01-07 16:06:39 +13:00
parent 5d7b6bfbfb
commit 253ef9ce0a
2 changed files with 5 additions and 4 deletions

View File

@ -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])

View File

@ -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) {