diff --git a/Craftimizer.Test/Solver/ActionSet.cs b/Craftimizer.Test/Solver/ActionSet.cs index e6f07d0..30e4bef 100644 --- a/Craftimizer.Test/Solver/ActionSet.cs +++ b/Craftimizer.Test/Solver/ActionSet.cs @@ -8,8 +8,8 @@ public class ActionSetTests [TestMethod] public void TestAcceptedActions() { - var actions = Craftimizer.Solver.Simulator.AcceptedActions; - var lut = Craftimizer.Solver.Simulator.AcceptedActionsLUT; + var actions = ActionSet.AcceptedActions; + var lut = ActionSet.AcceptedActionsLUT; Assert.IsTrue(actions.Length <= 32); foreach (var i in Enum.GetValues()) @@ -123,7 +123,7 @@ public class ActionSetTests { var action = set.SelectRandom(rng); - Assert.IsTrue(actions.Contains(action)); + CollectionAssert.Contains(actions, action); counts[action] = counts.GetValueOrDefault(action) + 1; } diff --git a/Craftimizer/Windows/RecipeNote.cs b/Craftimizer/Windows/RecipeNote.cs index ee3d3c9..2562e9c 100644 --- a/Craftimizer/Windows/RecipeNote.cs +++ b/Craftimizer/Windows/RecipeNote.cs @@ -839,7 +839,7 @@ public sealed unsafe class RecipeNote : Window, IDisposable var state = new SimulationState(input); var config = Service.Configuration.SimulatorSolverConfig; var mctsConfig = new MCTSConfig(config); - var simulator = new Solver.Simulator(state, mctsConfig.MaxStepCount); + var simulator = new SimulatorNoRandom(state); List macros = new(Service.Configuration.Macros); token.ThrowIfCancellationRequested(); diff --git a/Solver/ActionSet.cs b/Solver/ActionSet.cs index 248ba13..43b5874 100644 --- a/Solver/ActionSet.cs +++ b/Solver/ActionSet.cs @@ -11,6 +11,48 @@ public struct ActionSet { private uint bits; + public static readonly ActionType[] AcceptedActions = new[] + { + ActionType.StandardTouchCombo, + ActionType.AdvancedTouchCombo, + ActionType.FocusedTouchCombo, + ActionType.FocusedSynthesisCombo, + ActionType.TrainedFinesse, + ActionType.PrudentSynthesis, + ActionType.Groundwork, + ActionType.AdvancedTouch, + ActionType.CarefulSynthesis, + ActionType.TrainedEye, + ActionType.DelicateSynthesis, + ActionType.PreparatoryTouch, + ActionType.Reflect, + ActionType.FocusedTouch, + ActionType.FocusedSynthesis, + ActionType.PrudentTouch, + ActionType.Manipulation, + ActionType.MuscleMemory, + ActionType.ByregotsBlessing, + ActionType.WasteNot2, + ActionType.BasicSynthesis, + ActionType.Innovation, + ActionType.GreatStrides, + ActionType.StandardTouch, + ActionType.Veneration, + ActionType.WasteNot, + ActionType.Observe, + ActionType.MastersMend, + ActionType.BasicTouch, + }; + + public static readonly int[] AcceptedActionsLUT; + + static ActionSet() + { + AcceptedActionsLUT = new int[Enum.GetValues().Length]; + for (var i = 0; i < AcceptedActions.Length; i++) + AcceptedActionsLUT[(byte)AcceptedActions[i]] = i; + } + [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static int FromAction(ActionType action) @@ -22,7 +64,7 @@ public struct ActionSet } [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static ActionType ToAction(int index) => Simulator.AcceptedActions[index]; + private static ActionType ToAction(int index) => AcceptedActions[index]; [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint ToMask(ActionType action) => 1u << (FromAction(action) + 1); diff --git a/Solver/Simulator.cs b/Solver/Simulator.cs index 23ab77c..8edf3e4 100644 --- a/Solver/Simulator.cs +++ b/Solver/Simulator.cs @@ -5,7 +5,7 @@ using System.Runtime.CompilerServices; namespace Craftimizer.Solver; -public sealed class Simulator : SimulatorNoRandom +internal sealed class Simulator : SimulatorNoRandom { private readonly int maxStepCount; @@ -25,50 +25,6 @@ public sealed class Simulator : SimulatorNoRandom this.maxStepCount = maxStepCount; } - public static readonly ActionType[] AcceptedActions = new[] - { - ActionType.StandardTouchCombo, - ActionType.AdvancedTouchCombo, - ActionType.FocusedTouchCombo, - ActionType.FocusedSynthesisCombo, - ActionType.TrainedFinesse, - ActionType.PrudentSynthesis, - ActionType.Groundwork, - ActionType.AdvancedTouch, - ActionType.CarefulSynthesis, - ActionType.TrainedEye, - ActionType.DelicateSynthesis, - ActionType.PreparatoryTouch, - ActionType.Reflect, - ActionType.FocusedTouch, - ActionType.FocusedSynthesis, - ActionType.PrudentTouch, - ActionType.Manipulation, - ActionType.MuscleMemory, - ActionType.ByregotsBlessing, - ActionType.WasteNot2, - ActionType.BasicSynthesis, - ActionType.Innovation, - ActionType.GreatStrides, - ActionType.StandardTouch, - ActionType.Veneration, - ActionType.WasteNot, - ActionType.Observe, - ActionType.MastersMend, - ActionType.BasicTouch, - }; - - public static readonly int[] AcceptedActionsLUT; - - static Simulator() - { - AcceptedActionsLUT = new int[Enum.GetValues().Length]; - for (var i = 0; i < AcceptedActionsLUT.Length; i++) - AcceptedActionsLUT[i] = -1; - for (var i = 0; i < AcceptedActions.Length; i++) - AcceptedActionsLUT[(byte)AcceptedActions[i]] = i; - } - // https://github.com/alostsock/crafty/blob/cffbd0cad8bab3cef9f52a3e3d5da4f5e3781842/crafty/src/craft_state.rs#L146 [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -191,7 +147,7 @@ public sealed class Simulator : SimulatorNoRandom return new(); var ret = new ActionSet(); - foreach (var action in AcceptedActions) + foreach (var action in ActionSet.AcceptedActions) if (CanUseAction(action, strict)) ret.AddAction(action); return ret;