From 163812980907f8918603e0bdb961d49cf271e357 Mon Sep 17 00:00:00 2001 From: Mikael de Verdier Date: Sun, 23 Aug 2026 12:40:09 +0000 Subject: [PATCH] added check to make sure there is only one moose on each level --- services/enclose_moose_service.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/services/enclose_moose_service.py b/services/enclose_moose_service.py index 3b91d618..d946f41a 100644 --- a/services/enclose_moose_service.py +++ b/services/enclose_moose_service.py @@ -21,11 +21,18 @@ def __init__(self, encoded_grid: str, wall_budget: int): if self.N <= 1: raise HTTPException(400, detail="Level must be bigger than one square") + seen_moose = False for tile in encoded_grid: + if tile == "H": + if not seen_moose: + seen_moose = True + else: + raise HTTPException(400, detail='There can only be one moose ("H")') + if tile not in ("\n", ".", "~", "H", "C", "G", "S") and not tile.isnumeric(): raise HTTPException(400, detail=f'Level contained unknown encoding: "{tile}"') - if "H" not in encoded_grid: + if not seen_moose: raise HTTPException(400, detail='Level must contain a moose ("H")') if "\n" not in encoded_grid: