// Package yacht deals with yacht dice game.
package yacht
import (
"sort"
)
// Score count dice score.
func Score(dices []int, cat string) int {
switch cat {
case "ones":
return onesix(dices, 1)
case "twos":
return onesix(dices, 2)
case "threes":
return onesix(dices, 3)
case "fours":
return onesix(dices, 4)
case "fives":
return onesix(dices, 5)
case "sixes":
return onesix(dices, 6)
case "full house":
sort.Ints(dices)
if dices[0] != dices[1] || dices[3] != dices[4] &&
(dices[2] != dices[0] || dices[2] != dices[4]) ||
dices[0] == dices[4] {
return 0
}
ret := 0
for _, d := range dices {
ret += d
}
return ret
case "four of a kind":
sort.Ints(dices)
if dices[1] != dices[2] || dices[2] != dices[3] ||
dices[0] == dices[4] &&
dices[0] != dices[1] || dices[3] != dices[4] {
return 0
}
return 4 * dices[2]
case "little straight":
sort.Ints(dices)
for i, d := range dices {
if d != i+1 {
return 0
}
}
return 30
case "big straight":
sort.Ints(dices)
for i, d := range dices {
if d != i+2 {
return 0
}
}
return 30
case "choice":
ret := 0
for _, d := range dices {
ret += d
}
return ret
case "yacht":
for _, d := range dices {
if d != dices[0] {
return 0
}
}
return 50
default:
return 0
}
}
func onesix(dices []int, value int) int {
ret := 0
for _, d := range dices {
if d == value {
ret += value
}
}
return ret
}