verbose = true
function pig(players)
n = length(players)
scores = zeros(Int, n)
while true
for i in 1:n
j = 1
score = 0
while true
if scores[i] + score >= 100 || !players[i](scores, i, j, score)
verbose && println("Player $i passes")
break
end
k = rand(1:6)
verbose && println("Player $i throws $k")
if k == 1
score = 0
verbose && println("=> Zero!")
break
end
score += k
j += 1
end
scores[i] += score
verbose && score != 0 && println(" Earned $score points => $(scores[i])")
if scores[i] >= 100
verbose && println("Final scores: $scores - Player $i wins")
return i
end
end
end
end
function test_players(players, iterations)
global verbose
old_verbose = verbose
verbose = false
scores = zeros(length(players))
for i in 1:iterations
j = pig(players)
scores[j] += 1
end
verbose = true
scores /= iterations
end
fivetimes(scores, i, j, current) = j <= 5
sixtimes(scores, i, j, current) = j <= 6
twentier(scores, i, j, current) = current < 20
twentyfourer(scores, i, j, current) = current < 24
function fighter(scores, i, j, current)
for k in 1:length(scores)
k != i && scores[k] > 75 && return j < 10
end
current < 24
end