From ac109ae7119d385e1d15a43ee225d1c44fe592fd Mon Sep 17 00:00:00 2001 From: Asriel Camora Date: Thu, 2 Nov 2023 01:01:03 -0700 Subject: [PATCH] Fix ActionSet --- Craftimizer.Test/Solver/ActionSet.cs | 2 +- Solver/ActionSet.cs | 2 +- Solver/Simulator.cs | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Craftimizer.Test/Solver/ActionSet.cs b/Craftimizer.Test/Solver/ActionSet.cs index 87a00ee..e6f07d0 100644 --- a/Craftimizer.Test/Solver/ActionSet.cs +++ b/Craftimizer.Test/Solver/ActionSet.cs @@ -15,7 +15,7 @@ public class ActionSetTests foreach (var i in Enum.GetValues()) { var idx = lut[(byte)i]; - if (idx != 0) + if (idx != -1) Assert.AreEqual(i, actions[idx]); } } diff --git a/Solver/ActionSet.cs b/Solver/ActionSet.cs index c7aaf34..248ba13 100644 --- a/Solver/ActionSet.cs +++ b/Solver/ActionSet.cs @@ -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; } diff --git a/Solver/Simulator.cs b/Solver/Simulator.cs index b3f6f60..23ab77c 100644 --- a/Solver/Simulator.cs +++ b/Solver/Simulator.cs @@ -63,6 +63,8 @@ public sealed class Simulator : SimulatorNoRandom static Simulator() { AcceptedActionsLUT = new int[Enum.GetValues().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; }