Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Complete the Matlab function craps.m I have written a skeleton function. See the comments in the function for specific directions Craps Rules (1 Game): 1.
Complete the Matlab function craps.m
I have written a \skeleton" function. See the comments in the function for specific directions
Craps Rules (1 Game): 1. Make an initial roll of two sided dice and take sum: Possibilities are 2,3,4,5,6,7,8,9,10,11,12 If initial roll is 7 or 11, you win! Game over. If initial roll is 2,3, or 12, you lose! Game over. If initial roll is one of 4,5,6,8,9,10, move to second phase: 2. Keep rolling the dice indefinitely until one of two things occurs: If new roll is 7, you lose! Game over. If new roll initial rool, then you win! Game over. If new roll is neither 7, nor equal to your initial roll, then roll again === Here is an examplet of 25 games of craps ... Game 1: initialRoll=6; Keep Rolling... 4,6, Win Game 2: initialRoll=7; Win Game 3: initialRoll=6; Keep Rolling... 3,7, Lose! Game 4: initialRoll=9; Keep Rolling... 8,4,8,3,8,11,5,9, Win Game 5: initialRoll=12; Lose! function [winPct,wins, losses]=craps (numbGames) 18 craps simulation input argument: numbGames (Number of Games to be played) output arguments: wins (number of wins) losses (number of losses) winPct. (estimated probability of winning the game) Example Usage WP=craps (25) [WP, W,L]=craps (10000) wins=0; losses=0; & play a bunch of games of craps for k-1:numbGames inilRoll-rolldice(); $ roll the dice lo slart the game! fprintf('Game Sd: Initial Roll: $d ', k,initroll); % delete print statements in final version $ PSEUDO CODE to complete game 8 T. if initroll is 7 or 11, then add to the win total $ II. if initRoll is 2,3,12, then add to the loss total % III. if neither of I or II occurs, then you need to make a while & loop to complete the game (new rolls until you get a 7 or you malch $ your init roll end winPct-(winsumbGames) *100; nested functions are possible in matlab function result=rollDice () dicel-ceil (6*rand()); & random integer 1,2,3,4,5,6 (uniform probability) dice2-ceil (6*rand()); % random integer 1,2,3,4,5,6 (uniform probability) result-dicelldicc2; end endStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started