Skip to content

Commit

Permalink
Fix ActionSet
Browse files Browse the repository at this point in the history
  • Loading branch information
WorkingRobot committed Nov 2, 2023
1 parent 74195b5 commit ac109ae
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Craftimizer.Test/Solver/ActionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void TestAcceptedActions()
foreach (var i in Enum.GetValues<ActionType>())
{
var idx = lut[(byte)i];
if (idx != 0)
if (idx != -1)
Assert.AreEqual(i, actions[idx]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Solver/ActionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct ActionSet
private static int FromAction(ActionType action)
{
var ret = Simulator.AcceptedActionsLUT[(byte)action];
if (ret == 0)
if (ret == -1)
throw new ArgumentOutOfRangeException(nameof(action), action, $"Action {action} is unsupported in {nameof(ActionSet)}.");
return ret;
}
Expand Down
2 changes: 2 additions & 0 deletions Solver/Simulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public Simulator(SimulationState state, int maxStepCount) : base(state)
static Simulator()
{
AcceptedActionsLUT = new int[Enum.GetValues<ActionType>().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;
}
Expand Down

0 comments on commit ac109ae

Please sign in to comment.