How do I run a random number several times

1 回表示 (過去 30 日間)
Benedict Comerford
Benedict Comerford 2020 年 8 月 31 日
回答済み: Benedict Comerford 2020 年 8 月 31 日
HI i need to basically program a monopoly game, the aim is to find out the number of moves 2 players will make after 50 turns each
I have wriiten a function that finds the number of moves for one players turn but am having trouble coming up with code to alternate between the 2 players and track the total moves each has made.
1. In the game of Monopoly, a pair of dice are rolled to move a player's piece around the board. If a double is rolled (the dice show the same number), the player receives another roll of the dice. If a double is rolled a second time, a third roll of the dice is received. If a double is rolled on the third occasion, the player forfeits their turn (and goes to Jail). Write a program which simulates two players having 50 turns each (a turn is however many dice rolls a player has in a row before it's the other player's turn) and determines:
a) the total number of spaces moved by each player; and
b) how many times a player rolls a double which results in movement of a piece.
Use the randi function.
For fun, incorporate the rule that a player cannot leave Jail (cannot move) unless they either roll a double or three turns have passed without rolling a double.

回答 (1 件)

Benedict Comerford
Benedict Comerford 2020 年 8 月 31 日
This is the function for the dice roll

カテゴリ

Help Center および File ExchangeStrategy & Logic についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by