Optimize heuristic code slightly
This commit is contained in:
+36
-5
@@ -33,12 +33,27 @@ internal sealed class Simulator : SimulatorNoRandom
|
|||||||
this.maxStepCount = maxStepCount;
|
this.maxStepCount = maxStepCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/alostsock/crafty/blob/cffbd0cad8bab3cef9f52a3e3d5da4f5e3781842/crafty/src/craft_state.rs#L146
|
||||||
|
[Pure]
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
private bool CouldUseAction(BaseAction baseAction)
|
||||||
|
{
|
||||||
|
if (CalculateSuccessRate(baseAction.SuccessRate(this)) != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// don't allow quality moves at max quality
|
||||||
|
if (Quality >= Input.Recipe.MaxQuality && baseAction.IncreasesQuality)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return baseAction.CouldUse(this);
|
||||||
|
}
|
||||||
|
|
||||||
// https://github.com/alostsock/crafty/blob/cffbd0cad8bab3cef9f52a3e3d5da4f5e3781842/crafty/src/craft_state.rs#L146
|
// https://github.com/alostsock/crafty/blob/cffbd0cad8bab3cef9f52a3e3d5da4f5e3781842/crafty/src/craft_state.rs#L146
|
||||||
[Pure]
|
[Pure]
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// It's just a bunch of if statements, I would assume this is actually quite simple to follow
|
// It's just a bunch of if statements, I would assume this is actually quite simple to follow
|
||||||
#pragma warning disable MA0051 // Method is too long
|
#pragma warning disable MA0051 // Method is too long
|
||||||
private bool CouldUseAction(ActionType action, BaseAction baseAction, bool strict)
|
private bool ShouldUseAction(ActionType action, BaseAction baseAction)
|
||||||
#pragma warning restore MA0051 // Method is too long
|
#pragma warning restore MA0051 // Method is too long
|
||||||
{
|
{
|
||||||
if (CalculateSuccessRate(baseAction.SuccessRate(this)) != 1)
|
if (CalculateSuccessRate(baseAction.SuccessRate(this)) != 1)
|
||||||
@@ -48,8 +63,6 @@ internal sealed class Simulator : SimulatorNoRandom
|
|||||||
if (Quality >= Input.Recipe.MaxQuality && baseAction.IncreasesQuality)
|
if (Quality >= Input.Recipe.MaxQuality && baseAction.IncreasesQuality)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (strict)
|
|
||||||
{
|
|
||||||
// always use Trained Eye if it's available
|
// always use Trained Eye if it's available
|
||||||
if (action == ActionType.TrainedEye)
|
if (action == ActionType.TrainedEye)
|
||||||
return baseAction.CouldUse(this);
|
return baseAction.CouldUse(this);
|
||||||
@@ -127,7 +140,6 @@ internal sealed class Simulator : SimulatorNoRandom
|
|||||||
if ((action == ActionType.Veneration || action == ActionType.Innovation) &&
|
if ((action == ActionType.Veneration || action == ActionType.Innovation) &&
|
||||||
(GetEffectDuration(EffectType.Veneration) > 1 || GetEffectDuration(EffectType.Innovation) > 1))
|
(GetEffectDuration(EffectType.Veneration) > 1 || GetEffectDuration(EffectType.Innovation) > 1))
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return baseAction.CouldUse(this);
|
return baseAction.CouldUse(this);
|
||||||
}
|
}
|
||||||
@@ -139,9 +151,28 @@ internal sealed class Simulator : SimulatorNoRandom
|
|||||||
return new();
|
return new();
|
||||||
|
|
||||||
var ret = new ActionSet();
|
var ret = new ActionSet();
|
||||||
|
if (strict)
|
||||||
|
{
|
||||||
foreach (var (data, action) in actionPoolObjects)
|
foreach (var (data, action) in actionPoolObjects)
|
||||||
if (CouldUseAction(action, data, strict))
|
{
|
||||||
|
if (ShouldUseAction(action, data))
|
||||||
ret.AddAction(action);
|
ret.AddAction(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If Trained Eye is possible, *always* use Trained Eye
|
||||||
|
if (ret.HasAction(ActionType.TrainedEye))
|
||||||
|
{
|
||||||
|
ret = new();
|
||||||
|
ret.AddAction(ActionType.TrainedEye);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var (data, action) in actionPoolObjects)
|
||||||
|
if (CouldUseAction(data))
|
||||||
|
ret.AddAction(action);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user