Skip to content

Commit

Permalink
fix world DSL coordinate bug
Browse files Browse the repository at this point in the history
  • Loading branch information
byorgey committed Jun 25, 2024
1 parent dc7ea65 commit 04e5bd8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions data/scenarios/Testing/1320-world-DSL/00-ORDER.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
constant.yaml
erase.yaml
override.yaml
coords.yaml
22 changes: 22 additions & 0 deletions data/scenarios/Testing/1320-world-DSL/coords.yaml
Original file line number Diff line number Diff line change
@@ -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})
7 changes: 5 additions & 2 deletions src/swarm-scenario/Swarm/Game/World/Interpret.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}

-- |
-- SPDX-License-Identifier: BSD-3-Clause
Expand All @@ -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 (..))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 04e5bd8

Please sign in to comment.