Skip to content

Commit

Permalink
bugfix: a single Ten is a burn
Browse files Browse the repository at this point in the history
  • Loading branch information
minaorangina committed Feb 22, 2021
1 parent 0a6a643 commit 4e2a82e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gamerules.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func getLegalMoves(pile, toPlay []deck.Card) []int {
}

func isBurn(pile []deck.Card) bool {
if len(pile) < burnNum {
if len(pile) == 0 {
return false
}

Expand All @@ -118,6 +118,10 @@ func isBurn(pile []deck.Card) bool {
return true
}

if len(pile) < burnNum {
return false
}

// Check for Three burn
numThrees := 0
for _, c := range pile[len(pile)-burnNum:] {
Expand Down
10 changes: 10 additions & 0 deletions gamerules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,16 @@ func TestGameIsBurn(t *testing.T) {
deck.NewCard(deck.Ten, deck.Hearts)),
true,
},
{
"handles an empty pile",
[]deck.Card{},
false,
},
{
"play a 10 on its own",
[]deck.Card{deck.NewCard(deck.Ten, deck.Spades)},
true,
},
{
"four of the same suit (Spades)",
[]deck.Card{
Expand Down

0 comments on commit 4e2a82e

Please sign in to comment.