Im trying to make yahtzee in matlab, and I understand how to do most of it. Im really struggling on the code for the rerolls. For instance if I roll once, and I want to keep dice 2 and 4, then how would I reroll only dice 1,3, and 5. I was thinking about using an array of 0's and 1's that would determine which dice I want to keep. True=0 and False=1. Appreciate any help, Thanks.

1 comentario

jgg
jgg el 22 de En. de 2016
I think you'll have to give us some more information. What does your code look like? Your approach seems sensible; control your re-rolls with an indicator but without more information I don't know how we can help.

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 22 de En. de 2016

1 voto

Is this a homework question? John answered this in http://www.mathworks.com/matlabcentral/answers/264706#answer_206976 and I also saw an answer from Walter here http://www.mathworks.com/matlabcentral/answers/264740#answer_207025

5 comentarios

Nick Haufler
Nick Haufler el 22 de En. de 2016
It was a homework question. I forgot to mention that, sorry.
Image Analyst
Image Analyst el 22 de En. de 2016
Was John's answer to Brian good for you too? Or do you still have a question?
Nick Haufler
Nick Haufler el 22 de En. de 2016
I still dont understand how I would reroll only certain dice. Like if I roll my first turn and get 4 4 2 5 8. I would then want to reroll the last three dice. I just dont understand how to do that.
Image Analyst
Image Analyst el 22 de En. de 2016
Perhaps if I rename some of his variables to something more descriptive:
% Get initial roll values of 5 dice.
diceValues = randi(6,[1 5])
% Define some indexes that you want to roll again.
diceIndexesToReRoll = [3,4,5];
% Assign the new values to those indexes only.
diceValues(diceIndexesToReRoll) = randi(6,[1 numel(diceIndexesToReRoll)])
Now it's up to you to figure out which dice to roll again and set the dice numbers in the variable "diceIndexesToReRoll" based on the rules of Yahtzee.
John D'Errico
John D'Errico el 22 de En. de 2016
Can't be much more clear than that.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Word games en Centro de ayuda y File Exchange.

Preguntada:

el 22 de En. de 2016

Comentada:

el 22 de En. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by