Title: | Play and Analyse the Game of Snakes and Ladders |
---|---|
Description: | Plays the game of Snakes and Ladders and has tools for analyses. The tools included allow you to find the average moves to win, frequency of each square, importance of the snakes and the ladders, the most common square and the plotting of the game played. |
Authors: | Hector haffenden <[email protected]> |
Maintainer: | Hector Haffenden <[email protected]> |
License: | GPL-2 |
Version: | 2.1.0 |
Built: | 2024-11-28 06:47:40 UTC |
Source: | CRAN |
This function uses the function SnakesAndLaddersGame to estimate the average number of moves to win given any amount of players and allows you to change the number of trials used.
AverageMovesToWin(number.of.players = 2, number.of.trials = 1000)
AverageMovesToWin(number.of.players = 2, number.of.trials = 1000)
number.of.players |
A single numeric value that represents the number of players you wish to run the trial with |
number.of.trials |
A single numeric value that represents the number of trials you wish to run. The more trials the more accurate the estimation. |
Function uses a simple for loop to run many trials of the SnakesAndLaddersGame, counts the number of moves and outputs an average.
average.number.of.moves |
A numeric value which represents the average number of moves to win |
I have not put a limit on the amount of time that this function will run. This is to allow millions of trials.
Hector Haffenden [email protected]
AverageMovesToWin(1) AverageMovesToWin(100)
AverageMovesToWin(1) AverageMovesToWin(100)
This function uses the function SnakesAndLaddersGame to estimate the frequency of each square dependent on the number of players.
FrequencyOfSquaresByPercentage(number.of.players = 2, number.of.trials = 100, vector = FALSE)
FrequencyOfSquaresByPercentage(number.of.players = 2, number.of.trials = 100, vector = FALSE)
number.of.players |
A single numeric value that represents the number of players you wish to run the trial with. |
number.of.trials |
A single numeric value that represents the number of trials you wish to run. The more trials the more accurate the estimation. |
vector |
Takes values TRUE or FALSE, if TRUE will display results as a vector. This is sometimes a much nicer display of results. |
Function uses the SnakesAndLaddersGame function to find and display the frequency of how often a square is landed on, given a set number of players. it is also very useful to plot this data to see the distribution of how often a square is landed on.
Fequency.of.squares |
A numeric vector or matrix which represents how often a square is landed on in the game of Snakes and Ladders. |
I have not put a limit on the amount of time that this function will run. This is to allow many of trials.
Hector Haffenden [email protected]
FrequencyOfSquaresByPercentage(1) FrequencyOfSquaresByPercentage(10) x <- FrequencyOfSquaresByPercentage(2) plot(x)
FrequencyOfSquaresByPercentage(1) FrequencyOfSquaresByPercentage(10) x <- FrequencyOfSquaresByPercentage(2) plot(x)
This function uses the SnakesAndLaddersGame function to estimate the importence of the ladders dependent on the number of players by looking at which ladders the winners of each game lands on.
ImportenceOfTheLadders(number.of.players = 2)
ImportenceOfTheLadders(number.of.players = 2)
number.of.players |
A single numeric value that represents the number of players you wish to run the trial with. |
Function uses the SnakesAndLaddersGame function to find and display the ladders used by the winners. As the number of players increase we see a steady state forming of the same ladders. This results in us working out which ladders are key to land on if you want to win.
most.importent.ladders |
A data frame which shows an estimation of the most importent ladders. The higher the frequency the more importent the ladder. |
I have not put a limit on the amount of time that this function will run. This is to allow as many players as you want.
Hector Haffenden [email protected]
ImportenceOfTheLadders(1) ImportenceOfTheLadders(100) ImportenceOfTheLadders(1000)
ImportenceOfTheLadders(1) ImportenceOfTheLadders(100) ImportenceOfTheLadders(1000)
This function uses the SnakesAndLaddersGame function to estimate which snakes are the most powerful dependent on the number of players by looking at which snakes the losers of each game lands on.
ImportenceOfTheSnakes(number.of.players = 2)
ImportenceOfTheSnakes(number.of.players = 2)
number.of.players |
A single numeric value that represents the number of players you wish to run the trial with. |
Function uses the SnakesAndLaddersGame function to find and display the snakes used by the losers. As the number of players increase we see a steady state forming of the same snakes. This results in us working out which snakes are key to avoid if you want to win.
most.powerful.snakes |
A data frame which shows an estimation of the most powerful snakes. The higher the frequency the more powerful the snake. |
I have not put a limit on the amount of time that this function will run. This is to allow as many players as you want.
Hector Haffenden [email protected]
ImportenceOfTheSnakes(1) ImportenceOfTheSnakes(100) ImportenceOfTheSnakes(1000)
ImportenceOfTheSnakes(1) ImportenceOfTheSnakes(100) ImportenceOfTheSnakes(1000)
This function uses the SnakesAndLaddersGame function to estimate the most common square in a game of snakes and ladders.
MostCommonSquare(number.of.players = 2, number.of.trials = 500)
MostCommonSquare(number.of.players = 2, number.of.trials = 500)
number.of.players |
A single numeric value that represents the number of players you wish to run the trial with. |
number.of.trials |
A single numeric value tha represents the number of trials you wish to run. |
Function uses the SnakesAndLaddersGame function to find and display the most common square. The more trials the more accurate the estimate. There may be more than one if the trials are low enough.
most.common.square |
A print out of the most common squares landed on in a given number of trials. |
I have not put a limit on the amount of time that this function will run. This is to allow as many players and trials as you want.
Hector Haffenden [email protected]
MostCommonSquare(1) MostCommonSquare(100, 10)
MostCommonSquare(1) MostCommonSquare(100, 10)
This function plots the result from the SnakesAndLaddersGame Function.
PlotMyGame(output.from.SnakesAndLaddersGame.function, legend = TRUE)
PlotMyGame(output.from.SnakesAndLaddersGame.function, legend = TRUE)
output.from.SnakesAndLaddersGame.function |
The output from the SnakesAndLaddersGame function. |
legend |
Takes value TRUE or FALSE, if TRUE, displays the legend for the plot. |
Function that takes output from the SnakesAndLaddersGame function and plots it with an appropriate legend and nice colours to represent each players game. Only accepts number of players between 1 and 7.
A plot |
Plots the players position on each roll. |
Hector Haffenden [email protected]
PlotMyGame(SnakesAndLaddersGame(1)) PlotMyGame(SnakesAndLaddersGame(3)) PlotMyGame(SnakesAndLaddersGame(7))
PlotMyGame(SnakesAndLaddersGame(1)) PlotMyGame(SnakesAndLaddersGame(3)) PlotMyGame(SnakesAndLaddersGame(7))
This is a function that will run the game of snakes and ladders for as many players as you want.
SnakesAndLaddersGame(number.of.players = 2)
SnakesAndLaddersGame(number.of.players = 2)
number.of.players |
a single numeric value representing the number of players. Must be greater than 0. |
We use matrices here to make computations very fast and allowing millions of iterations.
game.output |
A matrix which displays the entire game of snakes and ladders. |
Do not put too many players in as your computer may crash. I have not put a limit on run time as people with more powerful computers will want to run it for longer.
An assumption that has been made is that everyone will get the same amount of rolls, irrespective of if someone has already won. This is to keep the game fair. This sometimes results in more than one player winning. This is rare when the player count is below 7 but as it grows the liklyhood of this increases dramatically. This is useful in some parts of the analysis.
The starting position for all players is 0.
The ladders used were:
1 to 38
4 to 14
9 to 31
21 to 42
28 to 84
36 to 44
51 to 67
71 to 91
80 to 100
The snakes used were:
16 to 6
47 to 26
49 to 11
56 to 53
62 to 19
64 to 60
87 to 24
93 to 73
95 to 75
98 to 78
The only check i have put in this function is to ensure that the number of players is greater than 0. This is because I want it to run at maximum efficieny and I have only included this check to ensure that the code does not go on for ever, which it would if number.of.players = 0 was inputted.
Hector Haffenden [email protected]
Sam Davies
Dr Andreas Artemiou: Programming and Statistics.
SnakesAndLaddersGame(1) SnakesAndLaddersGame(100) # Run some analysis on this, consistant, output. x <- SnakesAndLaddersGame(7)
SnakesAndLaddersGame(1) SnakesAndLaddersGame(100) # Run some analysis on this, consistant, output. x <- SnakesAndLaddersGame(7)