The board has 100 fields. Players start on field 1. Whenever somebody's roll takes them to 100 or further, they land on 100, win, and the game is over.
# cd into repo directory
# then, in Julia:
using Pkg;Pkg.activate(".")
using SnakesAL
# Set up a Game by specifying a Board, vector of Players, and Dice
gg = Game(SnakesAL.NM0, # a pre-defined board, 100 fields, no shortcuts
[Player("April", [1])], # one player with name and starting field
Dice(6)) # an ordinary "d6"
runToEnd!(gg); # roll dice and move until we hit field 100
# How many rounds did it take?
gg.round
# Retrace a player's path
gg.players[1].position
Set up your own board, players, and dice:
myBoard = Board(100, [Snake(17, 7), Snake(54, 34), Ladder(3, 22), Ladder(40, 85)])
myGame = Game(myBoard, [Player("Bob", [1])], Dice(6))
runToEnd!(myGame);
myGame # show the game's state
Custom dice can be specified via WeightedDice
:
myDice = WeightedDice(6, [1,1,1,1,1,5]) # biased d6, 5 times more likely to roll a 6
# 2D6 comes predefined in SnakesAL, check out:
SnakesAL.TwoD6
Using Markov chain theory:
myBoard = SnakesAL.NM0 # again, the boring board no shortcuts
getMarkovTransitionExpectation(myBoard, Dice(6)) # depends on type of dice
getMarkovTransitionVariance(myBoard, Dice(6))
Using simulations
import StatsBase: mean, var
map(x-> runToEnd!(Game(myBoard, [Player("Bob", [1])], Dice(6))).round, 1:100000) |> mean
map(x-> runToEnd!(Game(myBoard, [Player("Bob", [1])], Dice(6))).round, 1:100000) |> var
# Should be very similar to theoretical values above.
Check out the function runWithReps
Not exported, but available via:
SnakesAL.<...> where <...> is any of the following:
NM0 NM10α
NM14G0 NM6U
NM7∆ NM8Ξ
Works, but uses slightly different rules ATM.
# cd into the project directory
using Pkg
Pkg.activate(".")
Pkg.instantiate()
using GameZero
rungame("src/frontend.jl")
# Hit SPACE to roll the die.