Ha.nnes.dev


🎲

LiarsDice.jl

A simulation of Liar's Dice (Perudo) in Julia.

Language: Julia
Source code: GitHub

A WIP simulation of the game Liar's Dice, also known as Dudo or Perudo.

To simulate 100 games where five AIs play each other, run:

include("src/LiarsDice.jl")
strategies = [strategy_basic, strategy_basic, strategy_basic, strategy_basic, strategy_basic]
winners = [
    GameState(strategies; n_dice = 5, starting_player = mod(i, 1:length(strategies))) |> roll |> simulate for
    i = 1:100
]

# Plot the number of wins
using Plots: bar
bar(
    [count(winners .== i) for i = 1:length(strategies)];
    orientation = :h,
    yticks = (1:length(strategies), 1:length(strategies)),
    yflip = true
)

To play a game against two AIs, run:

include("src/LiarsDice.jl")
strategies = [strategy_human, strategy_basic, strategy_basic]
GameState(strategies; n_dice = 5, starting_player = 1) |> roll |> simulate