Skip to content

Commit

Permalink
Change scoring to allow quality to dominate as craft finishes
Browse files Browse the repository at this point in the history
  • Loading branch information
WorkingRobot committed Jul 29, 2024
1 parent 13cd698 commit 03eb60e
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions Solver/SimulationNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,59 @@ public static CompletionState GetCompletionState(CompletionState simCompletionSt
if (completionState != CompletionState.ProgressComplete)
return null;

var stepScore = 1f - ((float)(state.ActionCount + 1) / config.MaxStepCount);

if (state.Input.Recipe.MaxQuality == 0)
return 1f - ((float)(state.ActionCount + 1) / config.MaxStepCount);
return stepScore;

[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
static float Apply(float bonus, float value, float target) =>
bonus * (target > 0 ? Math.Clamp(value / target, 0, 1) : 1);
static float Apply(float multiplier, float value, float target) =>
multiplier * (target > 0 ? Math.Clamp(value / target, 0, 1) : 1);

[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
static float ApplyNondominant(float multiplier, float dominance, float value, float target) =>
Apply(float.Lerp(multiplier, 0, dominance), value, target);

[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
static float ApplyNondominant2(float multiplier, float dominance, float score) =>
float.Lerp(multiplier, 0, dominance) * score;

[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
static float ApplyDominant(float multiplier, float dominance, float value, float target) =>
Apply(float.Lerp(multiplier, 1, dominance), value, target);

var qualityDominance = state.ActionCount / config.MaxStepCount;

var progressScore = Apply(
var progressScore = ApplyNondominant(
config.ScoreProgress,
qualityDominance,
state.Progress,
state.Input.Recipe.MaxProgress
);

var qualityScore = Apply(
var qualityScore = ApplyDominant(
config.ScoreQuality,
qualityDominance,
state.Quality,
state.Input.Recipe.MaxQuality
);

var durabilityScore = Apply(
var durabilityScore = ApplyNondominant(
config.ScoreDurability,
qualityDominance,
state.Durability,
state.Input.Recipe.MaxDurability
);

var cpScore = Apply(
var cpScore = ApplyNondominant(
config.ScoreCP,
qualityDominance,
state.CP,
state.Input.Stats.CP
);

var fewerStepsScore =
config.ScoreSteps * (1f - ((float)(state.ActionCount + 1) / config.MaxStepCount));
var fewerStepsScore = ApplyNondominant2(config.ScoreSteps, qualityDominance, stepScore);

return progressScore + qualityScore + durabilityScore + cpScore + fewerStepsScore;
}
Expand Down

1 comment on commit 03eb60e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 03eb60e Previous: 1622902 Ratio
Craftimizer.Benchmark.Bench.Solve(State: 8D1CD5BA, Config: 5FB59A7C) 75502391.42857143 ns (± 629897.6889204222)
Craftimizer.Benchmark.Bench.Solve(State: B2852181, Config: 5FB59A7C) 100124645.23809527 ns (± 1300662.273225713)

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.