diff --git a/Craftimizer/Windows/MacroEditor.cs b/Craftimizer/Windows/MacroEditor.cs index 0685427..b5fb4f4 100644 --- a/Craftimizer/Windows/MacroEditor.cs +++ b/Craftimizer/Windows/MacroEditor.cs @@ -1018,7 +1018,7 @@ private void DrawIngredientHQEntry(int idx) private void DrawActionHotbars() { - var sim = CreateSim(); + var sim = CreateSim(State); var imageSize = ImGui.GetFrameHeight() * 2; var spacing = ImGui.GetStyle().ItemSpacing.Y; @@ -1283,8 +1283,7 @@ private void DrawMacro() } if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) { - var sim = CreateSim(); - ImGui.SetTooltip($"{action.GetName(RecipeData!.ClassJob)}\n{actionBase.GetTooltip(sim, true)}"); + ImGui.SetTooltip($"{action.GetName(RecipeData!.ClassJob)}\n{actionBase.GetTooltip(CreateSim(lastState), true)}"); } lastState = state; } @@ -1653,6 +1652,9 @@ private void RecalculateState() private static Sim CreateSim() => Service.Configuration.ConditionRandomness ? new Sim() : new SimNoRandom(); + private static Sim CreateSim(in SimulationState state) => + Service.Configuration.ConditionRandomness ? new Sim() { State = state } : new SimNoRandom() { State = state }; + private void AddStep(ActionType action, int index = -1, bool isSolver = false) { if (index < -1 || index >= Macro.Count) diff --git a/Simulator/Simulator.cs b/Simulator/Simulator.cs index 4ac07a2..75364f5 100644 --- a/Simulator/Simulator.cs +++ b/Simulator/Simulator.cs @@ -6,20 +6,22 @@ namespace Craftimizer.Simulator; public class Simulator { - protected SimulationState State; + public SimulationState State { init => state = value; } - public SimulationInput Input => State.Input; - public ref int ActionCount => ref State.ActionCount; - public ref int StepCount => ref State.StepCount; - public ref int Progress => ref State.Progress; - public ref int Quality => ref State.Quality; - public ref int Durability => ref State.Durability; - public ref int CP => ref State.CP; - public ref Condition Condition => ref State.Condition; - public ref Effects ActiveEffects => ref State.ActiveEffects; - public ref ActionStates ActionStates => ref State.ActionStates; + private SimulationState state; - public bool IsFirstStep => State.StepCount == 0; + public SimulationInput Input => state.Input; + public ref int ActionCount => ref state.ActionCount; + public ref int StepCount => ref state.StepCount; + public ref int Progress => ref state.Progress; + public ref int Quality => ref state.Quality; + public ref int Durability => ref state.Durability; + public ref int CP => ref state.CP; + public ref Condition Condition => ref state.Condition; + public ref Effects ActiveEffects => ref state.ActiveEffects; + public ref ActionStates ActionStates => ref state.ActionStates; + + public bool IsFirstStep => state.StepCount == 0; public virtual CompletionState CompletionState { get @@ -37,8 +39,8 @@ public virtual CompletionState CompletionState { public (ActionResponse Response, SimulationState NewState) Execute(in SimulationState state, ActionType action) { - State = state; - return (Execute(action), State); + this.state = state; + return (Execute(action), this.state); } private ActionResponse Execute(ActionType action) @@ -67,16 +69,16 @@ private ActionResponse Execute(ActionType action) public (ActionResponse Response, SimulationState NewState, int FailedActionIdx) ExecuteMultiple(in SimulationState state, IEnumerable actions) { - State = state; + this.state = state; var i = 0; foreach(var action in actions) { var resp = Execute(action); if (resp != ActionResponse.UsedAction) - return (resp, State, i); + return (resp, this.state, i); i++; } - return (ActionResponse.UsedAction, State, -1); + return (ActionResponse.UsedAction, this.state, -1); } [Pure] diff --git a/Solver/MCTS.cs b/Solver/MCTS.cs index 25c0ea6..99e6147 100644 --- a/Solver/MCTS.cs +++ b/Solver/MCTS.cs @@ -20,7 +20,7 @@ public sealed class MCTS public MCTS(in MCTSConfig config, in SimulationState state) { this.config = config; - var sim = new Simulator(config.MaxStepCount); + var sim = new Simulator(config.MaxStepCount) { State = state }; rootNode = new(new( state, null, diff --git a/Solver/Solver.cs b/Solver/Solver.cs index f0b17d0..add8bd1 100644 --- a/Solver/Solver.cs +++ b/Solver/Solver.cs @@ -240,7 +240,7 @@ private async Task SearchStepwiseForked() { var actions = new List(); var state = State; - var sim = new Simulator(Config.MaxStepCount); + var sim = new Simulator(Config.MaxStepCount) { State = state }; while (true) { Token.ThrowIfCancellationRequested(); @@ -303,7 +303,7 @@ private Task SearchStepwise() { var actions = new List(); var state = State; - var sim = new Simulator(Config.MaxStepCount); + var sim = new Simulator(Config.MaxStepCount) { State = state }; while (true) { Token.ThrowIfCancellationRequested(); diff --git a/Test/Simulator/Simulator.cs b/Test/Simulator/Simulator.cs index dbf0be7..886f056 100644 --- a/Test/Simulator/Simulator.cs +++ b/Test/Simulator/Simulator.cs @@ -170,7 +170,7 @@ public void TrainedFinesseProcs() }, 0, 4064, 15, 332); Assert.AreEqual(10, state.ActiveEffects.InnerQuiet); - Assert.IsTrue(ActionType.TrainedFinesse.Base().CanUse(new SimulatorNoRandom())); + Assert.IsTrue(ActionType.TrainedFinesse.Base().CanUse(new SimulatorNoRandom() { State = state })); } [TestMethod]