From cdd4f5923e308fc6082c90e3c032e73255159be4 Mon Sep 17 00:00:00 2001 From: Asriel Camora Date: Tue, 20 Jun 2023 17:07:16 -0700 Subject: [PATCH] Precompute base progress/quality increases --- Benchmark/Program.cs | 12 ++++++------ Craftimizer/SimulatorWindow.cs | 10 +++++----- Simulator/Actions/BaseBuffAction.cs | 8 +------- Simulator/Actions/WasteNot.cs | 7 ++++++- Simulator/Actions/WasteNot2.cs | 7 ++++++- Simulator/SimulationInput.cs | 30 ++++++++++++++++++++++++++--- Simulator/Simulator.cs | 15 ++------------- Solver/Crafty/Solver.cs | 4 ++-- 8 files changed, 55 insertions(+), 38 deletions(-) diff --git a/Benchmark/Program.cs b/Benchmark/Program.cs index 688eec1..8a2fa8e 100644 --- a/Benchmark/Program.cs +++ b/Benchmark/Program.cs @@ -13,10 +13,9 @@ internal static class Program //TypeLayout.PrintLayout(true); //return; - var input = new SimulationInput() - { - Stats = new CharacterStats { Craftsmanship = 4041, Control = 3905, CP = 609, Level = 90 }, - Recipe = new RecipeInfo() + var input = new SimulationInput( + new CharacterStats { Craftsmanship = 4041, Control = 3905, CP = 609, Level = 90 }, + new RecipeInfo() { IsExpert = false, ClassJobLevel = 90, @@ -29,8 +28,9 @@ internal static class Program QualityDivider = 115, ProgressModifier = 80, ProgressDivider = 130, - } - }; + }, + 0 + ); var actions = new List(); var s = Stopwatch.StartNew(); diff --git a/Craftimizer/SimulatorWindow.cs b/Craftimizer/SimulatorWindow.cs index 753b8ed..f3e9d0a 100644 --- a/Craftimizer/SimulatorWindow.cs +++ b/Craftimizer/SimulatorWindow.cs @@ -26,11 +26,11 @@ public class SimulatorWindow : Window MaximumSize = new Vector2(float.MaxValue, float.MaxValue) }; - State = new(new() - { - Stats = new CharacterStats { Craftsmanship = 4041, Control = 3905, CP = 609, Level = 90, CLvl = CalculateCLvl(90) }, - Recipe = CreateRecipeInfo(LuminaSheets.RecipeSheet.GetRow(35499)!) - }); + State = new(new( + new CharacterStats { Craftsmanship = 4041, Control = 3905, CP = 609, Level = 90, CLvl = CalculateCLvl(90) }, + CreateRecipeInfo(LuminaSheets.RecipeSheet.GetRow(35499)!), + 0 + )); Simulation = new(State); } diff --git a/Simulator/Actions/BaseBuffAction.cs b/Simulator/Actions/BaseBuffAction.cs index 3af3414..1b13cc3 100644 --- a/Simulator/Actions/BaseBuffAction.cs +++ b/Simulator/Actions/BaseBuffAction.cs @@ -6,17 +6,11 @@ internal abstract class BaseBuffAction : BaseAction { public abstract EffectType Effect { get; } public virtual byte Duration => 1; - public virtual EffectType[] ConflictingEffects => Array.Empty(); public override int DurabilityCost => 0; - public override void UseSuccess() - { - if (ConflictingEffects.Length != 0) - foreach(var effect in ConflictingEffects) - Simulation.RemoveEffect(effect); + public override void UseSuccess() => Simulation.AddEffect(Effect, Duration); - } public override string GetTooltip(bool addUsability) { diff --git a/Simulator/Actions/WasteNot.cs b/Simulator/Actions/WasteNot.cs index f337b09..09c4bcd 100644 --- a/Simulator/Actions/WasteNot.cs +++ b/Simulator/Actions/WasteNot.cs @@ -10,5 +10,10 @@ internal sealed class WasteNot : BaseBuffAction public override EffectType Effect => EffectType.WasteNot; public override byte Duration => 4; - public override EffectType[] ConflictingEffects => new[] { EffectType.WasteNot2 }; + + public override void UseSuccess() + { + base.UseSuccess(); + Simulation.RemoveEffect(EffectType.WasteNot2); + } } diff --git a/Simulator/Actions/WasteNot2.cs b/Simulator/Actions/WasteNot2.cs index 935de53..8eb4875 100644 --- a/Simulator/Actions/WasteNot2.cs +++ b/Simulator/Actions/WasteNot2.cs @@ -10,5 +10,10 @@ internal sealed class WasteNot2 : BaseBuffAction public override EffectType Effect => EffectType.WasteNot2; public override byte Duration => 8; - public override EffectType[] ConflictingEffects => new[] { EffectType.WasteNot }; + + public override void UseSuccess() + { + base.UseSuccess(); + Simulation.RemoveEffect(EffectType.WasteNot); + } } diff --git a/Simulator/SimulationInput.cs b/Simulator/SimulationInput.cs index 824352e..75962ce 100644 --- a/Simulator/SimulationInput.cs +++ b/Simulator/SimulationInput.cs @@ -2,9 +2,33 @@ namespace Craftimizer.Simulator; public readonly record struct SimulationInput { - public CharacterStats Stats { get; init; } - public RecipeInfo Recipe { get; init; } - public Random Random { get; init; } + public CharacterStats Stats { get; } + public RecipeInfo Recipe { get; } + public Random Random { get; } + + public int BaseProgressGain { get; } + public int BaseQualityGain { get; } + + public SimulationInput(CharacterStats stats, RecipeInfo recipe, int seed) + { + Stats = stats; + Recipe = recipe; + Random = new Random(seed); + + // https://github.com/NotRanged/NotRanged.github.io/blob/0f4aee074f969fb05aad34feaba605057c08ffd1/app/js/ffxivcraftmodel.js#L88 + { + var baseIncrease = (Stats.Craftsmanship * 10f / Recipe.ProgressDivider) + 2; + if (Stats.CLvl <= Recipe.RLvl) + baseIncrease *= Recipe.ProgressModifier / 100f; + BaseProgressGain = (int)baseIncrease; + } + { + var baseIncrease = (Stats.Control * 10f / Recipe.QualityDivider) + 35; + if (Stats.CLvl <= Recipe.RLvl) + baseIncrease *= Recipe.QualityModifier / 100f; + BaseQualityGain = (int)baseIncrease; + } + } public Condition[] AvailableConditions => ConditionUtils.GetPossibleConditions(Recipe.ConditionsFlag); } diff --git a/Simulator/Simulator.cs b/Simulator/Simulator.cs index 84699ff..c2adbb8 100644 --- a/Simulator/Simulator.cs +++ b/Simulator/Simulator.cs @@ -233,13 +233,7 @@ public class Simulator _ => 1.00f }; - // https://github.com/NotRanged/NotRanged.github.io/blob/0f4aee074f969fb05aad34feaba605057c08ffd1/app/js/ffxivcraftmodel.js#L88 - var baseIncrease = (Input.Stats.Craftsmanship * 10f / Input.Recipe.ProgressDivider) + 2; - if (Input.Stats.CLvl <= Input.Recipe.RLvl) - baseIncrease *= Input.Recipe.ProgressModifier / 100f; - baseIncrease = MathF.Floor(baseIncrease); - - var progressGain = (int)(baseIncrease * efficiency * conditionModifier * buffModifier); + var progressGain = (int)(Input.BaseProgressGain * efficiency * conditionModifier * buffModifier); return progressGain; } @@ -265,12 +259,7 @@ public class Simulator _ => 1.00f, }; - var baseIncrease = (Input.Stats.Control * 10f / Input.Recipe.QualityDivider) + 35; - if (Input.Stats.CLvl <= Input.Recipe.RLvl) - baseIncrease *= Input.Recipe.QualityModifier / 100f; - baseIncrease = MathF.Floor(baseIncrease); - - var qualityGain = (int)(baseIncrease * efficiency * conditionModifier * buffModifier); + var qualityGain = (int)(Input.BaseQualityGain * efficiency * conditionModifier * buffModifier); return qualityGain; } diff --git a/Solver/Crafty/Solver.cs b/Solver/Crafty/Solver.cs index 7f23b8d..56656b7 100644 --- a/Solver/Crafty/Solver.cs +++ b/Solver/Crafty/Solver.cs @@ -324,7 +324,7 @@ public class Solver return (actions, state); } - Debugger.Break(); + //Debugger.Break(); var solver = new Solver(state, true); while (!solver.Simulator.IsComplete) { @@ -344,7 +344,7 @@ public class Solver solver = new Solver(state, true); } - Debugger.Break(); + //Debugger.Break(); return (actions, state); }