I am working on an assignment where I need to create a fully functioning Yahtzee program. I am now done with the initial task, and have a fully functioning Yahtzee application, so I can roll the dice and I can hold values etc. But the problem I am facing right now is that I need to add 2 special dies to the mix, one of the dies need to have a higher probability of outputting low numbers while the other die need to have a higher probability of outputting higher numbers, also I need to provide a way for the user to adjust the probability on these dies within the console window.
So basically I was looking around on the internet and it seemed like, if I hardcoded it with an array, where I basically put more low numbers than high numbers, it does work, but that is very messy, and also doesn't fix the issue and also makes the task of allowing the user to adjust the probability very silly.
Long time since I've used the site, apologize if this is a bit sloppy.
class Dice
{
public static readonly Random rng = new Random();
public int NumberOfDice { get; private set; }
public Dice()
{
NumberOfDice = rng.Next(1, 7);
}
public void Reroll()
{
NumberOfDice = rng.Next(1, 7);
}
}
public bool FirstRound { get; private set; } = true;
public readonly Dice[] Dices =
{
new Dice(),
new Dice(),
new Dice(),
new Dice(),
new Dice(),
public void KeepDices(int[] toReroll)
{
for (int i = 0; i < Dices.Length; i++)
{
bool numFound = false;
foreach (int roll in toReroll)
{
if (Dices[i].NumberOfDice == roll)
{
numFound = true;
}
}
if (numFound)
{
continue;
}
else
{
Dices[i].Reroll();
}
}
ShowDices();
}
public void ShowDices()
{
Console.WriteLine();
foreach (Dice dice in Dices)
{
Console.Write("[{0}] ", dice.NumberOfDice);
FirstRound = false;
}
Console.WriteLine();
Console.WriteLine();
}
public void RerollAll()
{
foreach (Dice dice in Dices)
{
dice.Reroll();
}
ShowDices();
}
}
As I said the program runs fine, it works, but just need to somehow add a way to tie two of the dices to probability.
