From 5189ef5d74d9d7fdc7f44114088a6373ce5939e9 Mon Sep 17 00:00:00 2001 From: Asriel Camora Date: Wed, 21 Jun 2023 07:52:21 -0700 Subject: [PATCH] last optimization stuff i promise --- Solver/Crafty/Simulator.cs | 16 +++++----------- Solver/Crafty/Solver.cs | 5 +---- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/Solver/Crafty/Simulator.cs b/Solver/Crafty/Simulator.cs index 8afa032..7619683 100644 --- a/Solver/Crafty/Simulator.cs +++ b/Solver/Crafty/Simulator.cs @@ -54,9 +54,6 @@ public class Simulator : Sim { var baseAction = action.WithUnsafe(); - if (!baseAction.CanUse) - return false; - if (CalculateSuccessRate(baseAction.SuccessRate) != 1) return false; @@ -68,14 +65,11 @@ public class Simulator : Sim ActionStates.Observed) return false; - if (action == ActionType.FinalAppraisal) - return false; - if (strict) { // always used Trained Eye if it's available if (action == ActionType.TrainedEye) - return true; + return baseAction.CanUse; // only allow Focused moves after Observe if (ActionStates.Observed && @@ -97,10 +91,10 @@ public class Simulator : Sim if (baseAction.IncreasesProgress) { - var progress_increase = CalculateProgressGain(baseAction.Efficiency); - var would_finish = Progress + progress_increase >= Input.Recipe.MaxProgress; + var progressIncrease = CalculateProgressGain(baseAction.Efficiency); + var wouldFinish = Progress + progressIncrease >= Input.Recipe.MaxProgress; - if (would_finish) + if (wouldFinish) { // don't allow finishing the craft if there is significant quality remaining if (Quality < (Input.Recipe.MaxQuality / 5)) @@ -145,7 +139,7 @@ public class Simulator : Sim return false; } - return true; + return baseAction.CanUse; } // https://github.com/alostsock/crafty/blob/cffbd0cad8bab3cef9f52a3e3d5da4f5e3781842/crafty/src/craft_state.rs#L137 diff --git a/Solver/Crafty/Solver.cs b/Solver/Crafty/Solver.cs index 7aaec1a..8f62fad 100644 --- a/Solver/Crafty/Solver.cs +++ b/Solver/Crafty/Solver.cs @@ -1,6 +1,5 @@ using Craftimizer.Simulator; using Craftimizer.Simulator.Actions; -using System.Diagnostics; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -15,7 +14,7 @@ public class Solver public Random Random => Simulator.Input.Random; - public const int Iterations = 1000000; + public const int Iterations = 50000; public const float ScoreStorageThreshold = 1f; public const float MaxScoreWeightingConstant = 0.1f; public const float ExplorationConstant = 4f; @@ -244,7 +243,6 @@ public class Solver public static (List Actions, SimulationState State) SearchStepwise(SimulationInput input, Action? actionCallback) { var state = new SimulationState(input); - //Debugger.Break(); var actions = new List(); var solver = new Solver(state, true); while (!solver.Simulator.IsComplete) @@ -266,7 +264,6 @@ public class Solver solver = new Solver(state, true); } - //Debugger.Break(); return (actions, state); }