From 04e5bd8c50a6a23fa161ec658e2ae70676a6839b Mon Sep 17 00:00:00 2001 From: Brent Yorgey Date: Mon, 24 Jun 2024 15:19:24 -0500 Subject: [PATCH] fix world DSL coordinate bug --- .../Testing/1320-world-DSL/00-ORDER.txt | 1 + .../Testing/1320-world-DSL/coords.yaml | 22 +++++++++++++++++++ .../Swarm/Game/World/Interpret.hs | 7 ++++-- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 data/scenarios/Testing/1320-world-DSL/coords.yaml diff --git a/data/scenarios/Testing/1320-world-DSL/00-ORDER.txt b/data/scenarios/Testing/1320-world-DSL/00-ORDER.txt index 8a46bc0af..b8b093e30 100644 --- a/data/scenarios/Testing/1320-world-DSL/00-ORDER.txt +++ b/data/scenarios/Testing/1320-world-DSL/00-ORDER.txt @@ -1,3 +1,4 @@ constant.yaml erase.yaml override.yaml +coords.yaml diff --git a/data/scenarios/Testing/1320-world-DSL/coords.yaml b/data/scenarios/Testing/1320-world-DSL/coords.yaml new file mode 100644 index 000000000..d1bc97a51 --- /dev/null +++ b/data/scenarios/Testing/1320-world-DSL/coords.yaml @@ -0,0 +1,22 @@ +version: 1 +name: Coordinate test +description: | + Ensure x and y are handled correctly in the world DSL +creative: false +objectives: + - goal: + - Must pick up a rock + condition: | + as base {has "rock"} +solution: | + grab +robots: + - name: base + loc: [1, 2] + dir: east + devices: + - logger + - grabber +world: + dsl: | + mask (x == 1) (mask (y == 2) {rock,dirt}) diff --git a/src/swarm-scenario/Swarm/Game/World/Interpret.hs b/src/swarm-scenario/Swarm/Game/World/Interpret.hs index 3437af9c8..552455bf2 100644 --- a/src/swarm-scenario/Swarm/Game/World/Interpret.hs +++ b/src/swarm-scenario/Swarm/Game/World/Interpret.hs @@ -1,4 +1,6 @@ {-# LANGUAGE GADTs #-} +{-# LANGUAGE PatternSynonyms #-} +{-# LANGUAGE ViewPatterns #-} -- | -- SPDX-License-Identifier: BSD-3-Clause @@ -16,8 +18,9 @@ import Data.ByteString (ByteString) import Data.Hash.Murmur (murmur3) import Data.Tagged (unTagged) import Numeric.Noise.Perlin (noiseValue, perlin) +import Swarm.Game.Location (pattern Location) import Swarm.Game.World.Abstract (BTerm (..)) -import Swarm.Game.World.Coords (Coords (..)) +import Swarm.Game.World.Coords (Coords (..), coordsToLoc) import Swarm.Game.World.Gen (Seed) import Swarm.Game.World.Syntax (Axis (..), Rot (..)) import Swarm.Game.World.Typecheck (Const (..), Empty (..), Over (..)) @@ -55,7 +58,7 @@ interpConst seed = \case CGeq -> (>=) CMask -> \b x c -> if b c then x c else empty CSeed -> fromIntegral seed - CCoord ax -> \(Coords (x, y)) -> fromIntegral (case ax of X -> x; Y -> y) + CCoord ax -> \(coordsToLoc -> Location x y) -> fromIntegral (case ax of X -> x; Y -> y) CHash -> \(Coords ix) -> fromIntegral . murmur3 0 . unTagged . from @String @(Encoding.UTF_8 ByteString) . show $ ix CPerlin -> \s o k p -> let noise = perlin (fromIntegral s) (fromIntegral o) k p