Skip to content

Commit

Permalink
add RandomGen.RollVariation
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad Jamrozik committed Jun 22, 2024
1 parent 94bd3f8 commit 68a7ab1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/game-lib/Lib/IRandomGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ public interface IRandomGen
TValue Pick<TKey, TValue>(IDictionary<TKey, TValue> dict);
int RandomizeMissionSiteCountdown();
bool FlipCoin();


(int result, float variationRoll) RollVariation(int baseValue, (int min, int max) range, int precision);

(int result, float variationRoll) RollVariation(int baseValue, int min, int max, int precision);

}
14 changes: 14 additions & 0 deletions src/game-lib/Lib/RandomGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,18 @@ public virtual int RandomizeMissionSiteCountdown()
=> Roll(Ruleset.FactionMissionSiteCountdownRange);

public bool FlipCoin() => _random.Next(2) == 1;

public (int result, float variationRoll) RollVariation(int baseValue, (int min, int max) range, int precision)
=> RollVariation(baseValue, range.min, range.max, precision);

public (int result, float variationRoll) RollVariation(int baseValue, int min, int max, int precision)
{
// e.g. -15 = Roll(-30, 30)
int variationRoll = Roll(min, max);
// e.g. 85 = 100 + (-15)
int modifier = precision + variationRoll;
// e.g. 42 = 50 * 85 / 100
int result = baseValue * modifier / precision;
return (result, variationRoll: variationRoll / (float)precision);
}
}
12 changes: 6 additions & 6 deletions src/game-lib/Model/Ruleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ public static (int difficulty, int baseDifficulty, float variationRoll) RollMiss
// Note that currently the only ways of increasing agents survivability of difficulty is:
// - by surviving missions
// - via training
// As such, if difficulty due to turn would grow at least as fast as Ruleset.AgentTrainingCoefficient,
// As such, if difficulty per turn would grow at least as fast as Ruleset.AgentTrainingCoefficient,
// then at some point missions would become impossible, as eventually even the most experienced
// agents would die, and any new agents would never be able to catch up with mission difficulty.
int precision = MissionSiteDifficultyRollPrecision;
int baseDifficulty = factionPower / MissionSiteDifficultyFactionPowerDivisor;
int variationRoll = randomGen.Roll(MissionSiteDifficultyVariationRange);
int difficultyModifier = precision + variationRoll;
int difficulty = (baseDifficulty * difficultyModifier) / precision;
return (difficulty, baseDifficulty, variationRoll: variationRoll/(float)precision);
(int difficulty, float variationRoll) = randomGen.RollVariation(
baseValue: baseDifficulty,
range: MissionSiteDifficultyVariationRange,
precision: MissionSiteDifficultyRollPrecision);
return (difficulty, baseDifficulty, variationRoll);
}

public static int RequiredSurvivingAgentsForSuccess(MissionSite site)
Expand Down

0 comments on commit 68a7ab1

Please sign in to comment.