13
THE MATHEMATICAL ANALYSIS OF SNAKES AND LADDERS. BY: ITZEL VALDÉS, CARLA RIVAS, DANIA RODRIGUEZ, NICOLE CASTRO. Before Monopily, Jenga, Preguntados and all the modern games, the “clasic” ones where very popular and most of them still being, in particular one:”Snakes and Ladders” which origin can be traced back to the 16th century; a simple game you probably have tried at least once and if you haven´t after you read this article you may try. Many of us have spent hours playing it, but… Have you asked yourself how long does an average game really last?. Let us explain the mathematic behind this game that can give an answer fot this and more questions. Rules are simple, the game is play it on a board with 10 x 10 grid numbered from 1 to 100. Yo can play with one or two dice, you move the number of squares that te die or the dice say, but if you fall in a square with a snake,then you have to move back to the square where the tail of the snake is and if you fall in a square with a ladder then you move to the square where the end of the ladder is. Finally to win you have to arrive to the square number 100 before other players do, if you are near to it ,for example in square 1 For this analysis we used this 10 x 10 Snakes and Ladders game board.

The Mathematical Analysis of Snakes and Ladders

  • Upload
    dania30

  • View
    231

  • Download
    0

Embed Size (px)

DESCRIPTION

un trabajo acerca del proceso estocastico de serpientes y escaleras

Citation preview

Page 1: The Mathematical Analysis of Snakes and Ladders

THE MATHEMATICAL ANALYSIS OF SNAKES AND LADDERS.BY: ITZEL VALDÉS, CARLA RIVAS, DANIA RODRIGUEZ, NICOLE CASTRO.Before Monopily, Jenga, Preguntados and all the modern games, the “clasic” ones where very popular and most of them still being, in particular one:”Snakes and Ladders” which origin can be traced back to the 16th century; a simple game you probably have tried at least once and if you haven´t after you read this article you may try. Many of us have spent hours playing it, but… Have you asked yourself how long does an average game really last?. Let us explain the mathematic behind this game that can give an answer fot this and more questions.

Rules are simple, the game is play it on a board with 10 x 10 grid numbered from 1 to 100. Yo can play with one or two dice, you move the number of squares that te die or the dice say, but if you fall in a square with a snake,then you have to move back to the square where the tail of the snake is and if you fall in a square with a ladder then you move to the square where the end of the ladder is. Finally to win you have to arrive to the square number 100 before other players do, if you are near to it ,for example in square 98 you need exactly 2 in the die to win, if you get any other number you can´t move until you get a 2, the exact

number you need to reach the square 100.

Analysis

1

For this analysis we used this 10 x 10 Snakes and Ladders game board.

Page 2: The Mathematical Analysis of Snakes and Ladders

For this step we made use of the simulation tool, making a simple code in BVA that simulate a Snake and Ladders game playing with only a die and assuming that only one person is playing the game. This program plot the number of trials neded to finish each game. For game 1,for game 2, for game 3, and so on until game n the program give a new answer, “n” is given by the user and defined as the number of times the user want to play the game. The code of the source program is the following:

Option Explicit

Public Sub snake()

Dim n As DoubleDim x As DoubleDim i As DoubleDim t As DoubleDim dado As DoubleDim aleatorio1 As DoubleDim aleatorio2 As DoubleDim A() As Double

n = InputBox("How many times you want to play?")ReDim A(1 To n)

For i = 1 To nx = 0t = 0 Do Until x = 100 aleatorio1 = rndz(1, 6) aleatorio2 = rndz(1, 6) dado = aleatorio1 + aleatorio2 t = t + 1 x = x + dado Select Case x Case 4 x = 14 Case 9

x = 31 Case 28 x = 84

Case 21 x = 42 Case 36 x = 44 Case 51 x = 67 Case 71 x = 91 Case 80 x = 100 Case 98 x = 78 Case 95 x = 75 Case 93 x = 73 Case 87 x = 24 Case 64 x = 60 Case 62 x = 19 Case 56 x = 53 Case 47 x = 26

2

Page 3: The Mathematical Analysis of Snakes and Ladders

Case 49 x = 11 Case 16 x = 6 Case Is > 100 x = 100 - dado Case Else x = x End Select Loop A(i) = tNext i

imprimir_matriz A

End Sub

Public Function rndz(ByVal A As Integer, ByVal b As Integer) As Integer

Randomizerndz = Int(Rnd() * b - A + 1) + AEnd Function

Public Sub imprimir_matriz(ByRef A() As Double)Dim L1 As DoubleDim U1 As DoubleDim i As Double

L1 = LBound(A, 1)U1 = UBound(A, 1)

For i = L1 To U1Worksheets("Hoja1").Cells(i, 1).Value = A(i)Next i

End Sub

We simulated 10,000 times the game obtaining 10,000 answers for the question we propose at the beginning. To

present to the reader a complete idea of the results we prepared an statistical analysis.

Statistical analysis

Máximum 139Mínimum 5

Rank 134Average 25.7824

Mode 12Median 22

Percentile 25 14Percentile 75 32

Variance 250.2072502Standard desviation

15.81794077

3

Page 4: The Mathematical Analysis of Snakes and Ladders

By this data we can know that in average,we expect 25 tosses of a die in a regular Snakes and ladders game,this result is really certain if we consider the number of experiments realized (10,000 in this case).

We can observe this data inthe following graphic that ilustrates de dispersion of the obtained results in the simulation and the frecuency with which each one is obtained:

0 20 40 60 80 100 120 1400

100200300400500

Absolute Frequency

Number of moves

Freq

uenc

yIn this graphic is easy to observe the minimun,the maximun, mode,median and the percentiles.

Talking know about probability we can obtain the cumulative distribution function since the previous results, we used the same ones of the statistical analysis. Fisrt we divide the data in intervals, then calculated the absolute and relative frecuency of each interval and finally sum the relative frecuency of each interval to obtain the cumulative one.

Interval Absolute Frequency Relative Frequency Cummulative Probability0 0 0 0 00 20 4195 0.4195 0.4195

20 40 4267 0.4267 0.846240 60 1117 0.1117 0.957960 80 311 0.0311 0.98980 100 88 0.0088 0.9978

100 120 13 0.0013 0.9991120 140 9 0.0009 1

TOTAL 10000 1  

With this table we graphed the cumulative distribution function for the experiment:

4

Page 5: The Mathematical Analysis of Snakes and Ladders

0 20 40 60 80 100120 1400

0.5

1

1.5

Cummulative Probability

Number of moves

Cum

mul

uati

ve P

roba

bi-

lity

This is a very easy way to observe the fast growing of the cumulative probability in the first intervals near the average value: 25.7824 tosses of a die; and then gradually tends to 1.To finish this statistical analysis we present the frequency histogram obtained of the data including the absolute frequency of each interval in the histogram, where we can observe the maximum and the mode in the numbers near the average of the results.

0-20

20-40

40-60

60-80

80-100

100-

120

120-

140

04000

Histogram and Absolute Fre-

quency

Interval

Freq

uenc

y

And the cumulative distributions of the histogram´s intervals, where

we can observe clearly the interval that quickly accumulates probability, again near the average.

0-20

20-40

40-60

60-80

80-100

100-

120

120-

140

00.40.81.2

Histogram and Cummulative Probability

Interval

Prob

abili

ty

Limitations

Simulation is a powerfull tool that help us finding answers or solutions to

5

Page 6: The Mathematical Analysis of Snakes and Ladders

problems that analytically would be difficult or impossible to find, but in many sometimes the software, the algorithm or other external factors influence in the results of the simulation, that can made the analysis a little imprecise.

If you want to corroborate the functionality of the previusly exposed source program, you only have to open a new book in excell, press Alt+F11,insert a new module, copy the program and run it, but the reader need to consider the limitations it has.

In our analysis case, the limitations we had were:

1.- The generator of random numbers of the BVA software, which weren´t real “good” uniform random numbers, this deficiency will give a bias in the result.

2.- The simulation is alleged for only one player, the game contunues until this unique player reaches the 100 square, removing the probability that the game ends before if one of the other players win.

3.- The program only plot the matrix with the number of tosses of a die needed to win the for each game played applied by the user, all the statistics, the graphs and the final numbers we presented in this analysis the reader will have to make use uf the tools in excel to obtain them.

Markov chain analysis

Games like Snakes and Ladders are ideal candidates for Markov chain analysis because, at any time, the

probabilities of events that will happen in the future are unaffected by what happened in the past.

If a player is at grid square G when he rolls, one of six things could happen (with equal probability), and based on these probabilities the player would advance to one of the next squares. These probabilities can be represented as a sparse matrix which records the probability of moving from position i on the game board to position j. This matrix is called a Transition Matrix.

An entry in row-i and column-j of the transition matrix gives the probability of moving from location i to location j on the next move.

There are still six possible outcomes with equal probability of 1/6, but this time, rather than being consecutive, they sometimes record the locations that would be jumped to if the player lands on a snake or a ladder. There are just a couple of other scenarios we need to correctly address and we’ll be able to construct a full stochastic transition matrix for our game.

6

Page 7: The Mathematical Analysis of Snakes and Ladders

The first is a

condition in which it is possible to land in a location by more than one means from a single roll. The second condition that interests us is the boundary scenario in which the player is close to the finish. Since an exact roll is not needed, there are multiple ways to get to square 100.

Transition matrix

After the stochastic probabilities for each square are entered, the result is a transition matrix that is a 101 x 101 grid, because prior to their first rolls, players begin the game with their tokens off the board as ifthere were a square 0, is sparse in nature. These squares don’t need to be defined as separate states since landing on one of them instantly transports the player to the other end. In the 101 x 101 matrixthese rows and columns are full of redundant zeros.

To ilustrate this idea, we present the relevant parts of the transitionmatrix that we constructed:

1.- The start of the game:START 1 2 3 4 5 6 7 8

1     0     1/6  1/6 0     1/6  1/6 0     0    2     0     0     1/6 0     1/6  1/6  1/6  1/63     0     0     0       1/6  1/6  1/6  1/64     0     0     0     0     1/6  1/6  1/6  1/65     0     0     0     0     0     1/6  1/6  1/66     0     0     0     0     0     0     1/6  1/6

7     0     0     0     0     0     0     0     1/68     0     0     0     0     0     0     0     0    9     0     0     0     0     0     0     0     0    

10     0     0     0     0     0     1/6 0     0    11     0     0     0     0     0     1/6 0     0    12     0     0     0     0     0     1/6 0     0    13     0     0     0     0     0     1/6 0     0    14     0     0     0     0     0     1/6 0     0    15     0     0     0     0     0     1/6 0     0    

2.- The intermediate parts of the transition matrix:

START 17 18 19 20 21 22 23 24 11      1/6 0     0     0     0     0     0     0    12      1/6  1/6 0     0     0     0     0     0    13      1/6  1/6  1/6 0     0     0     0     0    14      1/6  1/6  1/6  1/6 0     0     0     0    15      1/6  1/6  1/6  1/6 0     0     0     0    16      1/6  1/6  1/6  1/6 0      1/6 0     0    17     0      1/6  1/6  1/6 0      1/6  1/6 0    18     0     0      1/6  1/6 0      1/6  1/6  1/619     0     0     0      1/6 0      1/6  1/6  1/620     0     0     0     0     0      1/6  1/6  1/621     0     0     0     0     0      1/6  1/6  1/622     0     0     0     0     0     0      1/6  1/623     0     0     0     0     0     0     0      1/624     0     0     0     0     0     0     0     0    25     0     0     0     0     0     0     0     0    

START 37 38 39 40 41 42 43 44

15     0     0     0     0     0      1/6 0     0    16     0     0     0     0     0      1/6 0     0    17     0     0     0     0     0      1/6 0     0    18     0     0     0     0     0      1/6 0     0    19     0     0     0     0     0      1/6 0     0    20     0     0     0     0     0      1/6 0     0    30     0     0     0     0     0     0     0      1/631      1/6 0     0     0     0     0     0      1/632      1/6  1/6 0     0     0     0     0      1/633      1/6  1/6  1/6 0     0     0     0      1/634      1/6  1/6  1/6  1/6 0     0     0      1/635      1/6  1/6  1/6  1/6  1/6 0     0      1/636      1/6  1/6  1/6  1/6  1/6  1/6 0     0    37     0      1/6  1/6  1/6  1/6  1/6  1/6 0    38     0     0      1/6  1/6  1/6  1/6  1/6  1/639     0     0     0      1/6  1/6  1/6  1/6  1/6

7

Page 8: The Mathematical Analysis of Snakes and Ladders

40     0     0     0     0      1/6  1/6  1/641     0     0     0     0     0      1/6  1/642     0     0     0     0     0     0      1/643     0     0     0     0     0     0     0    

3.-The parts in the trasition matrix that you have more probability to reach during the game:START 58 59 60 61 62 63 64 65

54      1/6  1/6  1/6 0     0     0     0     0    55      1/6  1/6  1/6  1/6 0     0     0     0    56      1/6  1/6  1/6  1/6 0     0     0     0    57      1/6  1/6  1/6  1/6 0      1/6 0     0    58     0      1/6  1/3  1/6 0      1/6 0     0    59     0     0      1/3  1/6 0      1/6 0      1/660     0     0      1/6  1/6 0      1/6 0      1/661     0     0      1/6 0     0      1/6 0      1/662     0     0      1/6 0     0      1/6 0      1/6

63     0     0      1/6 0     0     0     0      1/664     0     0     0     0     0     0     0      1/665     0     0     0     0     0     0     0     0    66     0     0     0     0     0     0     0     0    

4.-The finall parts of the matrix that include the probability of winning the game (the columns and rows that don´t appear ore the ones with redundant zeros): START 91 92 94 96 97 99 100

65      1/6 0     0     0     0     0     0    66      1/6 0     0     0     0     0     0    67      1/6 0     0     0     0     0     0    68      1/6 0     0     0     0     0     0    69      1/6 0     0     0     0     0     0    70      1/6 0     0     0     0     0     0    74     0     0     0     0     0     0      1/675     0     0     0     0     0     0      1/676     0     0     0     0     0     0      1/677     0     0     0     0     0     0      1/678     0     0     0     0     0     0      1/679     0     0     0     0     0     0      1/685      1/6 0     0     0     0     0     0    86      1/6  1/6 0     0     0     0     0    87      1/6  1/6 0     0     0     0     0    88      1/6  1/6  1/6 0     0     0     0    89      1/6  1/6  1/6 0     0     0     0    90      1/6  1/6  1/6  1/6 0     0     0    91     0      1/6  1/6  1/6  1/6 0     0    92     0     0      1/6  1/6  1/6 0     0    93     0     0      1/6  1/6  1/6  1/6 0    94     0     0     0      1/6  1/6  1/6  1/695     0     0     0      1/6  1/6  1/6  1/696     0     0     0     0      1/6  1/6  1/697     0     0     0     0     0      1/6  1/698     0     0     0     0     0      1/6  1/699     0     0     0     0     0     0      1/6

100     0     0     0     0     0     0     0    

You can corroborate this transition matrix checking it with the Snakes and Ladders board presented on page 1.

To determine the probabilities of what is going to happen on the next roll, we use the output of the first roll as the input for the second roll. We do this by multiplying by the transition matrix

8

Page 9: The Mathematical Analysis of Snakes and Ladders

again. The resulting output is the superposition of the probabilities from each of the starting locations.

We calculate the probability of being in a

space on the board depending on the starting point of each

turn, we simulate

this rolls in our program

described on page 2 and 3, we watched that is

likely to occupy behaves the different

spaces on the board, so each room has a different probability depending on the number of roll being used.

The darker squares represent the regions of higher probability, while the white squares represent regions of zero probability. There are six shaded squares, each with equal probability, representing the squares that would have been achieved with each distinct roll of the die.You can see that two of the rolls resulted in the use of ladders.

The resulting output is the superposition of the probabilities from each of the starting locations

Shows three rolls

Shows four rolls

Shows five rolls

9

Page 10: The Mathematical Analysis of Snakes and Ladders

Shows six rolls

It shows the probability distribution after 20 movesThese spaces are more likely to be occupied after two rolls because of the multiple ways to get there.

Results

The results of the Markov chains analysis are ilustrated in a simple colored matrix, where the reader can observe with more color saturation the squares that have more probability to reach depending the one that you are. This will give us an idea of the most probably path the game will take and the square you wouldvisit with more

certainly.

Conclusions

It’s possible to use quite simple math to model outcomes of seemingly complex games. If you can represent your game as some form of “memoryless” finite state machine then, through the use of Markov chain analysis,

you can exactly calculate the probability distribution of future states.

If a non-exact solution is all that is needed, or you don’t understand the subtleties of the probabilities, then a simulation model is any software with the appropriate number of experiments can produce perfectly acceptable approximations without eliminating its limitations.

10