public const long MINIMUM_DIE_VALUE = 1;
public const long MAXIMUM_DIE_VALUE = 20;
public static void RunExample()
public static void Report(
+ bonus_normal.ToString()
+ "\tBonus (advantage) = "
+ bonus_advantage.ToString()
+ System.Environment.NewLine
if (ShouldRollWithAdvantage(
stringMessage += "Your odds are better with the power of ADVANTAGE!";
stringMessage += "Advantage is for losers; roll normally!";
Console.WriteLine(stringMessage);
public static bool ShouldRollWithAdvantage(
if (dc - bonus_advantage > MAXIMUM_DIE_VALUE)
if (dc - bonus_normal > MAXIMUM_DIE_VALUE)
if (dc - bonus_normal <= MINIMUM_DIE_VALUE)
if (dc - bonus_advantage <= MINIMUM_DIE_VALUE)
var leftHandSide = (dc - bonus_advantage - MINIMUM_DIE_VALUE);
leftHandSide *= leftHandSide;
var rightHandSide = (MAXIMUM_DIE_VALUE - MINIMUM_DIE_VALUE + 1) * (dc - bonus_normal - MINIMUM_DIE_VALUE);
var shouldRollWithAdvantage = leftHandSide < rightHandSide;
return shouldRollWithAdvantage;
private static bool TryValidateProgramConstants(
if (!(MINIMUM_DIE_VALUE < MAXIMUM_DIE_VALUE))
errorMessage = "Maximum die value must be greater than minimum die value.";
if (MINIMUM_DIE_VALUE < -1000)
errorMessage = "Unreasonably low minimum die value.";
if (MAXIMUM_DIE_VALUE > 1000)
errorMessage = "Unreasonably high maximum die value.";
errorMessage = default(string);
public static void Main()
if (TryValidateProgramConstants(out errorMessage))
Console.WriteLine("Error in program validation; aborting run.");
if (!string.IsNullOrWhiteSpace(errorMessage))
Console.WriteLine(errorMessage);