Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm going to disagree with some of the earlier posters, and say that an object oriented approach is the wrong thing to do here, as it makes things more complicated. </p> <p>All you need is to track the position of each player, and a vector to represent the board. If the board position is empty of a chute or ladder, it is 0. If it contains a ladder, the board contains a positive number that indicates how many positions to move forward. If it contains a chute, it contains a negative number to move you back. Just track the number of turns and positions of each player. </p> <p>The actual simulation with this method is quite simple, and you could do it in nearly any programming language. I would suggest R or python, but only because those are the ones I use most these days.</p> <p>I don't have a copy of chutes and ladders, so I made up a small board. You'll have to put in the right board:</p> <pre><code>#!/usr/bin/python import random, numpy board = [0, 0, 0, 3, 0, -3, 0, 1, 0, 0] numplayers = 2 numruns = 100 def simgame(numplayers, board): winner = -1 winpos = len(board) pos = [0] * numplayers turns = 0 while max(pos) &lt; winpos: turns += 1 for i in range(0, numplayers): pos[i] += random.randint(1,6) if pos[i] &lt; winpos: pos[i] += board[pos[i]] if pos[i] &gt;= winpos and winner == -1: winner = i return (turns, winner) # simulate games, then extract turns and winners games = [simgame(numplayers, board) for x in range(numruns)] turns = [n for (n, w) in games] winner = [w for (t, w) in games] pwins = [len([p for p in winner if p == i]) for i in range(numplayers)] print "runs:", numruns print "mean(turns):", numpy.mean(turns) print "sd(turns):", numpy.std(turns) for i in range(numplayers): print "Player", (i+1), "won with proportion:", (float(pwins[i])/numruns) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload