Pig the dice game/Player: Difference between revisions
Content added Content deleted
Line 2,016: | Line 2,016: | ||
strategy::Pair |
strategy::Pair |
||
end |
end |
||
randomchoicetostop(player, group) = rand(Bool) |
randomchoicetostop(player, group) = rand(Bool) |
||
variablerandtostop(player, group) = any(x -> x.score > player.score, group) ? rand() < 0.1 : rand(Bool) |
variablerandtostop(player, group) = any(x -> x.score > player.score, group) ? rand() < 0.1 : rand(Bool) |
||
overtwentystop(player, group) = player.ante > 20 |
overtwentystop(player, group) = player.ante > 20 |
||
over20unlesslosingstop(player, group) = player.ante > 20 && all(x -> x.score < 80, group) |
over20unlesslosingstop(player, group) = player.ante > 20 && all(x -> x.score < 80, group) |
||
const strategies = ("random choice to stop" => randomchoicetostop, "variable rand to stop" => variablerandtostop, |
const strategies = ("random choice to stop" => randomchoicetostop, "variable rand to stop" => variablerandtostop, |
||
"roll to 20" => overtwentystop, "roll to 20 then if not losing stop" => over20unlesslosingstop) |
"roll to 20" => overtwentystop, "roll to 20 then if not losing stop" => over20unlesslosingstop) |
||
const players = [Player(0, 0, 0, 0, s) for s in strategies] |
const players = [Player(0, 0, 0, 0, s) for s in strategies] |
||
const dice = collect(1:6) |
const dice = collect(1:6) |
||
function turn(player, verbose=false) |
function turn(player, verbose=false) |
||
playernum = findfirst(p -> p == player, players) |
playernum = findfirst(p -> p == player, players) |
||
Line 2,039: | Line 2,039: | ||
return false |
return false |
||
elseif player.strategy[2](player, players) |
elseif player.strategy[2](player, players) |
||
⚫ | |||
player.score += player.ante |
player.score += player.ante |
||
⚫ | |||
return true |
|||
end |
end |
||
end |
end |
||
Line 2,047: | Line 2,047: | ||
true |
true |
||
end |
end |
||
function rungames(N) |
function rungames(N) |
||
for i in 1:N |
for i in 1:N |
||
Line 2,066: | Line 2,066: | ||
end |
end |
||
end |
end |
||
rungames(1000000) |
rungames(1000000) |
||
</lang>{{out}} |
</lang>{{out}} |