Skip to content

Commit

Permalink
Fix out of range exception
Browse files Browse the repository at this point in the history
  • Loading branch information
WorkingRobot committed Jul 4, 2024
1 parent 65d01ae commit 7363b81
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions Craftimizer/Windows/SynthHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ private void DrawMacroInfo()
if (!effect.IsIndefinite())
{
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - durationShift);
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + 1);
ImGuiUtils.TextCentered($"{effects.GetDuration(effect)}", size.X);
}
}
Expand Down
25 changes: 14 additions & 11 deletions Solver/MCTS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,21 @@ private Node Select()
var currentCompletionState = expandedNode.State.SimulationCompletionState;
var currentActions = expandedNode.State.AvailableActions;

byte actionCount = 0;
var actions = actionBuffer[..Math.Min(config.MaxStepCount - currentState.ActionCount, config.MaxRolloutStepCount)];
while (SimulationNode.GetCompletionState(currentCompletionState, currentActions) == CompletionState.Incomplete &&
actionCount < actions.Length)
if (currentState.ActionCount < config.MaxStepCount)
{
var nextAction = currentActions.SelectRandom(random);
actions[actionCount++] = nextAction;
currentState = simulator.ExecuteUnchecked(currentState, nextAction);
currentCompletionState = simulator.CompletionState;
if (currentCompletionState != CompletionState.Incomplete)
break;
currentActions = simulator.AvailableActionsHeuristic(true);
var actions = actionBuffer[..Math.Min(config.MaxStepCount - currentState.ActionCount, config.MaxRolloutStepCount)];
byte actionCount = 0;
while (SimulationNode.GetCompletionState(currentCompletionState, currentActions) == CompletionState.Incomplete &&
actionCount < actions.Length)
{
var nextAction = currentActions.SelectRandom(random);
actions[actionCount++] = nextAction;
currentState = simulator.ExecuteUnchecked(currentState, nextAction);
currentCompletionState = simulator.CompletionState;
if (currentCompletionState != CompletionState.Incomplete)
break;
currentActions = simulator.AvailableActionsHeuristic(true);
}
}

var score = SimulationNode.CalculateScoreForState(currentState, currentCompletionState, config) ?? 0;
Expand Down

1 comment on commit 7363b81

@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: 7363b81 Previous: 7ad073a Ratio
Craftimizer.Benchmark.Bench.Solve(State: 4D905E7E, Config: A52FEBEA) 106662693.84615384 ns (± 536866.3052309278)
Craftimizer.Benchmark.Bench.Solve(State: C62039FC, Config: A52FEBEA) 98629663.33333333 ns (± 399177.7539070585)

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

Please sign in to comment.