Add ability to set initialized sim state if needed
This commit is contained in:
@@ -1018,7 +1018,7 @@ public sealed class MacroEditor : Window, IDisposable
|
||||
|
||||
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 @@ public sealed class MacroEditor : Window, IDisposable
|
||||
}
|
||||
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 @@ public sealed class MacroEditor : Window, IDisposable
|
||||
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)
|
||||
|
||||
+19
-17
@@ -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 class Simulator
|
||||
|
||||
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 @@ public class Simulator
|
||||
|
||||
public (ActionResponse Response, SimulationState NewState, int FailedActionIdx) ExecuteMultiple(in SimulationState state, IEnumerable<ActionType> 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]
|
||||
|
||||
+1
-1
@@ -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,
|
||||
|
||||
+2
-2
@@ -240,7 +240,7 @@ public sealed class Solver : IDisposable
|
||||
{
|
||||
var actions = new List<ActionType>();
|
||||
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 @@ public sealed class Solver : IDisposable
|
||||
{
|
||||
var actions = new List<ActionType>();
|
||||
var state = State;
|
||||
var sim = new Simulator(Config.MaxStepCount);
|
||||
var sim = new Simulator(Config.MaxStepCount) { State = state };
|
||||
while (true)
|
||||
{
|
||||
Token.ThrowIfCancellationRequested();
|
||||
|
||||
@@ -170,7 +170,7 @@ public class SimulatorTests
|
||||
},
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user