From 61dc8155c81f0344865e936d11073c4086fd9ecf Mon Sep 17 00:00:00 2001 From: Brent Yorgey Date: Sun, 5 Jan 2025 14:17:20 -0600 Subject: [PATCH] fix gallery --- data/scenarios/Challenges/_gallery/setup.sw | 30 +++++++++++---------- data/scenarios/Challenges/gallery.yaml | 10 ++++--- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/data/scenarios/Challenges/_gallery/setup.sw b/data/scenarios/Challenges/_gallery/setup.sw index 474b097aa..72ccc5a87 100644 --- a/data/scenarios/Challenges/_gallery/setup.sw +++ b/data/scenarios/Challenges/_gallery/setup.sw @@ -88,13 +88,21 @@ def naiveRandomStack = \valueFunc. \maxval. \bitmask. \n. valueFunc val; end; -def getEntName = \idx. - result <- tagmembers "bust" idx; - return $ snd result; - end; +def index : Int -> (rec l. Unit + a * l) -> a = \i. \l. + case l + (\_. fail "bad index") + (\cons. if (i == 0) {fst cons} {index (i-1) (snd cons)}) +end + +def length : (rec l. Unit + a * l) -> Int = \l. + case l (\_. 0) (\cons. 1 + length (snd cons)) +end + +def busts : (rec l. Unit + Text * l) = tagmembers "bust" end +def bustCount : {Int} = {length busts} end def placeThing = \entIdx. - entName <- getEntName entIdx; + let entName = index entIdx busts in create entName; place entName; end; @@ -116,13 +124,10 @@ bust in the base's inventory increases monotonically. "idx" counts upwards. */ def populateInventory = \baseCount. \idx. - - result <- tagmembers "bust" idx; - let total = fst result in - if (idx < total) { + if (idx < force bustCount) { - let item = snd result in + let item = index idx busts in // Give copies to the base baseExtras <- random 5; @@ -143,12 +148,9 @@ def populateInventory = \baseCount. \idx. end; def setup = - result <- tagmembers "bust" 0; - let totalCount = fst result in - populateInventory 0 0; - naiveRandomStack placeEntByIndex totalCount 0 totalCount; + naiveRandomStack placeEntByIndex (force bustCount) 0 (force bustCount); turn back; move; create "bitcoin"; diff --git a/data/scenarios/Challenges/gallery.yaml b/data/scenarios/Challenges/gallery.yaml index 69d8cf7c9..bba64700c 100644 --- a/data/scenarios/Challenges/gallery.yaml +++ b/data/scenarios/Challenges/gallery.yaml @@ -62,14 +62,18 @@ objectives: ); end; + def length : (rec l. Unit + a * l) -> Int = \l. + case l (\_. 0) (\cons. 1 + length (snd cons)) + end + j <- robotnamed "judge"; as j { // Flag that setup is done hasBitcoin <- has "bitcoin"; if hasBitcoin { - result <- tagmembers "bust" 0; - let itemCount = fst result in - ensureMonotonicDecreasing itemCount $ itemCount + 1; + let busts = tagmembers "bust" in + let bustCount = length busts in + ensureMonotonicDecreasing bustCount $ bustCount + 1; } { return false; }