bigmike2238
Member
- Joined
- Dec 24, 2013
- Messages
- 7
- Programming Experience
- Beginner
Hello,
I have taken on a challenge set forth by a popular .Net training site. I think my math is right but the problem is player 2 is disproportionally winning in the simulated darts game. Here is the class where the calculations are being performed:
...And the method that tallys up the score:
I would appreciate any assistance with this issue. Thank you to all that reply.
Mike :witless:
I have taken on a challenge set forth by a popular .Net training site. I think my math is right but the problem is player 2 is disproportionally winning in the simulated darts game. Here is the class where the calculations are being performed:
C#:
public class Dart
{
Random random = new Random();
public int Score { get; set; }
private int bonusValue { get; set; }
public int throwMethod()
{
int _throwResult = random.Next(0, 20);
if (_throwResult == 0)
{
checkForBullsEye();
return this.Score;
}
else
{
calcBonus();
this.Score += _throwResult * (this.bonusValue);
return this.Score;
}
}
void checkForBullsEye()
{
double _bullCheck = random.NextDouble();
if (_bullCheck <= 0.5)
this.Score = 25;
else
this.Score = 50;
}
void calcBonus()
{
double _check = random.NextDouble();
if (_check < (1 / 3))
this.bonusValue = 2;
else if (_check >= (1 / 3) && _check < (2 / 3))
this.bonusValue = 3;
else
this.bonusValue = 1;
}
}
...And the method that tallys up the score:
C#:
static public void OneRun()
{
Dart dart = new Dart();
Player1Score += dart.throwMethod();
Player2Score += dart.throwMethod();
}
I would appreciate any assistance with this issue. Thank you to all that reply.
Mike :witless: