Yahtzee in Matlab?

2 Ansichten (letzte 30 Tage)
Brian Tiffman
Brian Tiffman am 21 Jan. 2016
Bearbeitet: John D'Errico am 21 Jan. 2016
Im trying to make the game yahtzee in matlab. Im setting up an array with 0's and 1's in it, and the 1's will be the dice that I want to reroll. I havent had to much trouble, but I cant figure out how to incorporate the reroll aspect into it. Im using an if statement to generate new random numbers if theres a 1 in the array. If theres a zero then there will be no need to reroll those dice in that position. Could anyone offer some help for the reroll process. Much appreciated.

Akzeptierte Antwort

John D'Errico
John D'Errico am 21 Jan. 2016
Bearbeitet: John D'Errico am 21 Jan. 2016
Why do it in a complicated way, using loops and if statements?
d = randi(6,[1 5])
d =
4 1 6 6 5
rerolls = [1 2 5];
d(rerolls) = randi(6,[1 numel(rerolls)])
d =
5 5 6 6 3
Note that IF rerolls is an empty vector, then nothing should change. Does that work here?
rerolls = [];
d(rerolls) = randi(6,[1 numel(rerolls)])
d =
5 5 6 6 3
Yep.
You still need to decide which dice to re-roll, but that is your problem.

Weitere Antworten (0)

Kategorien

Mehr zu Word games finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by