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

In summary, the conversation is about creating a Matlab script that simulates a game where you roll a die 12 times and win money based on certain outcomes. The script should call a function called "diceGame" which takes in a vector representing the 12 dice values and returns the amount of money won. The main script should use logic to determine the number of times a certain value appears in the vector and compare it to the winning criteria to determine the amount of money won. There should also be a loop to fill an array with the values of the 12 rolls.
  • #1
Judas543
6
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
  • #2
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.)
 

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

1. What is the purpose of the MATLAB Annoying Dice Game?

The purpose of the MATLAB Annoying Dice Game is to simulate a game of rolling two dice and recording the results. It can be used for entertainment or educational purposes.

2. How do I play the MATLAB Annoying Dice Game?

To play the MATLAB Annoying Dice Game, simply run the program and follow the prompts. You will be asked to input the number of rounds you want to play, and then the game will begin. Each round, two dice will be rolled and the results will be recorded. The game will continue for the specified number of rounds.

3. Can I customize the rules of the game?

Yes, you can customize the rules of the game by changing the values in the program. For example, you can change the number of dice being rolled or the winning conditions. However, this would require knowledge of MATLAB programming.

4. How accurate is the MATLAB Annoying Dice Game?

The MATLAB Annoying Dice Game is as accurate as the random number generator used in the program. It uses the built-in randi() function, which generates uniformly distributed random integers, so the results should be fairly accurate.

5. Can I use the MATLAB Annoying Dice Game for research purposes?

Yes, the MATLAB Annoying Dice Game can be used for research purposes, but it is not meant to be a professional-grade simulation tool. It is a simple program that can be used for basic simulations, but for more complex research, it would be best to use more specialized software.

Similar threads

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