MATLAB What is the logic for winning money in this MATLAB dice game?

  • Thread starter Thread starter Judas543
  • Start date Start date
  • Tags Tags
    Dice Game Matlab
AI Thread Summary
The discussion centers around creating a Matlab script for a dice game simulation. The task involves rolling a die 12 times, generating random numbers between 1 and 6. The player wins $2 if they roll a "ONE" or "FIVE" at least six times, or $1 if they roll "THREE" exactly three times. The script must include a main function that calls another function, "diceGame," which processes the results of the rolls and calculates the winnings. Participants emphasize the need for a loop to fill an array with the dice results and to implement logic that counts occurrences of specific numbers. The final step involves checking the counts to determine the winnings based on the specified conditions.
Judas543
Messages
6
Reaction score
0
This script looks easy but from staring at it for countless times and referring to a book, I can't figure it out...I'm really stressing out

Anyways these are the instructions...So you need 1 main script and then a function script

1.You are playing a game where you roll a die 12 times. In Matlab, you simulate each result by generating a random number between [1...6] (1 point)

2.If you run a “ONE” or a “FIVE” at least six times, you win 2 dollars, or if you run “THREE” three times you win 1 dollar. (2 points)


3.Create a Matlab script that calls a function “diceGame” (1 point) that takes in a vector representing the 12 dice values and return the amount of money won.



This is what I have right now..Missing some stuff though
What I do know that I need to have a "count"
for k = 1:12
dice_result = ceil(rand * 6);
end
 
Physics news on Phys.org
You need some logic to do this. Your loop should fill an array of size 12 with the values of the 12 rolls of the die.

The main part of your m-file should cycle through the array, looking at each value. Each For each value in the array (think for loop), if the result is 1, increment a variable (one_count). If the result is 5, increment another variable (five_count). If the result is 3, increment a variable (three_count).

After your loop, inspect these three variables. If one_count >= 6 or if five_count >= 6, you win $2. If three_count == 3, you win $1. (As stated, it appears that you don't win the dollar if three_count > 3.)
 

Similar threads

Replies
4
Views
1K
Replies
2
Views
2K
Replies
53
Views
9K
Replies
41
Views
5K
Replies
6
Views
19K
Replies
2
Views
10K
Replies
5
Views
1K
Replies
4
Views
1K
Back
Top