Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix world DSL coordinate bug #1988

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/scenarios/Challenges/Ranching/beekeeping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ world:
in
overlay
[ {grass}
, mask (flowers && (x + y) % 3 == 0) {wildflower}
, mask (flowers && (x - y) % 3 == 0) {wildflower}
, mask (rubble && (x + y) % 2 == 0) {rock}
, mask rock {rock}
, mask trees {tree}
Expand Down
4 changes: 2 additions & 2 deletions data/scenarios/Challenges/gallery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ world:
dsl: |
overlay
[ {terrain: stone}
, if (x/5 + y/5) % 2 == 0 then {terrain: dirt} else {blank}
, if (((x + 3) % 20)/11 + ((y + 3) % 20)/11) == 0 then {terrain: grass} else {blank}
, if (x/5 + (-y)/5) % 2 == 0 then {terrain: dirt} else {blank}
, if (((3 - y) % 20)/11 + ((x + 3) % 20)/11) == 0 then {terrain: grass} else {blank}
]
upperleft: [0, 11]
offset: false
Expand Down
2 changes: 1 addition & 1 deletion data/scenarios/Challenges/wave.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ world:
dsl: |
overlay
[ {dirt, water}
, if (x + y / 2) % 5 == 0 then {dirt, wavy water} else {blank}
, if (x / 2 - y) % 5 == 0 then {dirt, wavy water} else {blank}
]
upperleft: [-3, 6]
offset: false
Expand Down
2 changes: 1 addition & 1 deletion data/scenarios/Fun/horton.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ world:
[ {dirt}
, mask (patch) {boulder}
, mask (prize) {flower}
, mask (y < -80 || y > 80 || x < -60 || x > 60) (overlay [{water}])
, mask (x < -80 || x > 80 || y < -60 || y > 60) (overlay [{water}])
]
upperleft: [-4, 4]
offset: false
Expand Down
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})
4 changes: 2 additions & 2 deletions data/scenarios/Testing/1535-ping/1535-in-range.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ world:
dsl: |
overlay
[ {terrain: stone}
, if (x/5 + y/5) % 2 == 0 then {terrain: dirt} else {blank}
, if ((x + 3) % 19)/12 + (y % 19)/12 == 0 then {terrain: grass} else {blank}
, if (x/5 + (-y)/5) % 2 == 0 then {terrain: dirt} else {blank}
, if ((3 - y) % 19)/12 + (x % 19)/12 == 0 then {terrain: grass} else {blank}
]
palette:
'B': [blank, null, base]
Expand Down
4 changes: 2 additions & 2 deletions data/scenarios/Testing/1535-ping/1535-out-of-range.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ world:
dsl: |
overlay
[ {terrain: blank}
, if (x/4 + y/4) % 2 == 0 then {terrain: dirt} else {blank}
, if ((x + 3) % 19)/12 + (y % 19)/12 == 0 then {terrain: grass} else {blank}
, if (x/4 + (-y)/4) % 2 == 0 then {terrain: dirt} else {blank}
, if ((3 - y) % 19)/12 + (x % 19)/12 == 0 then {terrain: grass} else {blank}
]
palette:
'B': [stone, null, base]
Expand Down
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
Loading