diff --git a/BinaryMatrixEngine/ActionSet.cs b/BinaryMatrixEngine/ActionSet.cs index 72a20ef..7e87b13 100644 --- a/BinaryMatrixEngine/ActionSet.cs +++ b/BinaryMatrixEngine/ActionSet.cs @@ -13,7 +13,7 @@ public interface CardSpecification { public int? ResolveForPlayer(Player player); } -public struct ActionSet { +public readonly struct ActionSet { public readonly ActionType type; public readonly int lane; public readonly CardSpecification? card; @@ -34,7 +34,7 @@ public ActionSet(ActionType type, int lane) { if(type != ActionType.DRAW && type != ActionType.COMBAT) throw new ArgumentException("Invalid overload called for this type.", nameof(type)); this.type = type; - this.lane = lane; + this.lane = ValidateLane(lane, allowPseudo: type == ActionType.DRAW); this.card = default; } @@ -42,7 +42,15 @@ public ActionSet(ActionType type, CardSpecification card, int lane) { if(type != ActionType.PLAY && type != ActionType.FACEUP_PLAY && type != ActionType.DISCARD) throw new ArgumentException("Invalid overload called for this type.", nameof(type)); this.type = type; - this.lane = lane; + this.lane = ValidateLane(lane, allowPseudo: type == ActionType.DISCARD); this.card = card; } + + private static int ValidateLane(int lane, bool allowPseudo = false) { + return lane switch { + < 0 or > LANE_A => throw new ArgumentOutOfRangeException(nameof(lane), lane, "Lane must be within the range [0; " + LANE_A + "]."), + LANE_A when !allowPseudo => throw new ArgumentOutOfRangeException(nameof(lane), lane, "Lane must name a real lane, not the `a` pseudolane for this action."), + _ => lane + }; + } }