Matlab- Dice game(plz help!)

Discussion in 'Programmer's Corner' started by wkywj1, Mar 6, 2012.

  1. wkywj1

    Thread Starter New Member

    Mar 6, 2012
    A particular game of chance is played by throwing a pair of 6-sided dice and observing the total
    number of spots showing on their top faces.
    • If the total T1 for the first throw is 7 or 11, the player wins immediately.
    • If T1= 2,3 or 12, the player loses immediately.
    • If the total is any other number x, then the player keeps throwing the dice, yielding totals
    T2, T3,…
    each time until either
    i) she throws a total of x again, in which case she wins, or
    ii) she throws a total of 7, in which case she loses.

    Write a MATLAB procedure or code that simulates the game, as described above. Your
    procedure should indicate when the player
    I) wins
    II) wins on the 4th throw, and
    III) wins and also threw a 5 on her 1st throw.

    Write a program that calls your MATLAB procedure from (g) n=10 times,
    and gives the fraction of times that the player
    I) wins
    II) wins on the 4th throw, and
    III) wins given that she threw a 5 on her first throw.
  2. evilclem


    Dec 20, 2011
    What's the question?

    Matlab has a very good in-built help on all it's functions.

    Start with random number generation for your dice. Two dice so you'll have a rand(2,1) or rand(1,2) function. This produces numbers between 0 and 1 so you'll need to multiply by 6 (6 sides to a die), floor to produce an integer, and add 1 as zero isn't a die option.

    twodice = floor(rand(2,1)*6)+1

    We need to see your code for any more help (and know what you need help with)!