-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/scenario-loading
- Loading branch information
Showing
9 changed files
with
245 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,4 @@ | |
1138-structures | ||
1356-portals | ||
144-subworlds | ||
1379-single-world-portal-reorientation.yaml |
101 changes: 101 additions & 0 deletions
101
data/scenarios/Testing/1379-single-world-portal-reorientation.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
version: 1 | ||
name: Portal reorientation within a single subworld | ||
description: | | ||
Turning without turning | ||
attrs: | ||
- name: portal_in | ||
fg: "#ff9a00" | ||
bg: "#ff5d00" | ||
objectives: | ||
- goal: | ||
- | | ||
`place` the "flower" on the white cell. | ||
condition: | | ||
j <- robotnamed "judge"; | ||
as j {ishere "flower"} | ||
solution: | | ||
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end; | ||
doN 23 move; | ||
f <- grab; | ||
doN 23 move; | ||
place f; | ||
entities: | ||
- name: telepad entrance | ||
display: | ||
attr: portal_in | ||
char: "o" | ||
description: | ||
- Portal entrance | ||
properties: [known] | ||
robots: | ||
- name: base | ||
dir: [0, 1] | ||
devices: | ||
- branch predictor | ||
- calculator | ||
- comparator | ||
- dictionary | ||
- grabber | ||
- lambda | ||
- logger | ||
- strange loop | ||
- treads | ||
- name: judge | ||
dir: [1, 0] | ||
system: true | ||
display: | ||
char: 'J' | ||
invisible: true | ||
known: [flower] | ||
world: | ||
name: root | ||
default: [blank] | ||
palette: | ||
'.': [grass] | ||
'f': [grass, flower] | ||
'g': [ice, null, judge] | ||
'B': [grass, null, base] | ||
'0': | ||
cell: [grass, telepad entrance] | ||
waypoint: | ||
name: wp0 | ||
'1': | ||
cell: [grass, telepad entrance] | ||
waypoint: | ||
name: wp1 | ||
'2': | ||
cell: [grass, telepad entrance] | ||
waypoint: | ||
name: wp2 | ||
'3': | ||
cell: [grass, telepad entrance] | ||
waypoint: | ||
name: wp3 | ||
upperleft: [-1, 1] | ||
portals: | ||
- entrance: wp0 | ||
exitInfo: | ||
exit: wp0 | ||
reorient: right | ||
- entrance: wp1 | ||
exitInfo: | ||
exit: wp1 | ||
reorient: right | ||
- entrance: wp2 | ||
exitInfo: | ||
exit: wp2 | ||
reorient: right | ||
- entrance: wp3 | ||
exitInfo: | ||
exit: wp3 | ||
reorient: right | ||
map: | | ||
......... | ||
.1.....2. | ||
......... | ||
.B....... | ||
.f....... | ||
.g....... | ||
......... | ||
.0.....3. | ||
......... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
{-# LANGUAGE DerivingStrategies #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE UndecidableInstances #-} | ||
|
||
-- | | ||
-- SPDX-License-Identifier: BSD-3-Clause | ||
-- | ||
-- Types and helper functions for working with directions | ||
module Swarm.Language.Direction ( | ||
-- * Directions | ||
Direction (..), | ||
AbsoluteDir (..), | ||
RelativeDir (..), | ||
PlanarRelativeDir (..), | ||
directionSyntax, | ||
isCardinal, | ||
allDirs, | ||
) where | ||
|
||
import Data.Aeson.Types hiding (Key) | ||
import Data.Char qualified as C (toLower) | ||
import Data.Data (Data) | ||
import Data.Hashable (Hashable) | ||
import Data.List qualified as L (tail) | ||
import Data.Text hiding (filter, length, map) | ||
import Data.Text qualified as T | ||
import GHC.Generics (Generic) | ||
import Swarm.Util qualified as Util | ||
import Witch.From (from) | ||
|
||
------------------------------------------------------------ | ||
-- Directions | ||
------------------------------------------------------------ | ||
|
||
-- | An absolute direction is one which is defined with respect to an | ||
-- external frame of reference; robots need a compass in order to | ||
-- use them. | ||
-- | ||
-- NOTE: These values are ordered by increasing angle according to | ||
-- the standard mathematical convention. | ||
-- That is, the right-pointing direction, East, is considered | ||
-- the "reference angle" and the order proceeds counter-clockwise. | ||
-- See https://en.wikipedia.org/wiki/Polar_coordinate_system#Conventions | ||
-- | ||
-- Do not alter this ordering, as there exist functions that depend on it | ||
-- (e.g. "nearestDirection" and "relativeTo"). | ||
data AbsoluteDir = DEast | DNorth | DWest | DSouth | ||
deriving (Eq, Ord, Show, Read, Generic, Data, Hashable, Enum, Bounded) | ||
|
||
directionJsonModifier :: String -> String | ||
directionJsonModifier = map C.toLower . L.tail | ||
|
||
directionJsonOptions :: Options | ||
directionJsonOptions = | ||
defaultOptions | ||
{ constructorTagModifier = directionJsonModifier | ||
} | ||
|
||
instance FromJSON AbsoluteDir where | ||
parseJSON = genericParseJSON directionJsonOptions | ||
|
||
instance ToJSON AbsoluteDir where | ||
toJSON = genericToJSON directionJsonOptions | ||
|
||
cardinalDirectionKeyOptions :: JSONKeyOptions | ||
cardinalDirectionKeyOptions = | ||
defaultJSONKeyOptions | ||
{ keyModifier = directionJsonModifier | ||
} | ||
|
||
instance ToJSONKey AbsoluteDir where | ||
toJSONKey = genericToJSONKey cardinalDirectionKeyOptions | ||
|
||
instance FromJSONKey AbsoluteDir where | ||
fromJSONKey = genericFromJSONKey cardinalDirectionKeyOptions | ||
|
||
-- | A relative direction is one which is defined with respect to the | ||
-- robot's frame of reference; no special capability is needed to | ||
-- use them. | ||
data RelativeDir = DPlanar PlanarRelativeDir | DDown | ||
deriving (Eq, Ord, Show, Read, Generic, Data, Hashable, ToJSON, FromJSON) | ||
|
||
-- | Caution: Do not alter this ordering, as there exist functions that depend on it | ||
-- (e.g. "nearestDirection" and "relativeTo"). | ||
data PlanarRelativeDir = DForward | DLeft | DBack | DRight | ||
deriving (Eq, Ord, Show, Read, Generic, Data, Hashable, Enum, Bounded) | ||
|
||
instance FromJSON PlanarRelativeDir where | ||
parseJSON = genericParseJSON directionJsonOptions | ||
|
||
instance ToJSON PlanarRelativeDir where | ||
toJSON = genericToJSON directionJsonOptions | ||
|
||
-- | The type of directions. Used /e.g./ to indicate which way a robot | ||
-- will turn. | ||
data Direction = DAbsolute AbsoluteDir | DRelative RelativeDir | ||
deriving (Eq, Ord, Show, Read, Generic, Data, Hashable, ToJSON, FromJSON) | ||
|
||
-- | Direction name is generated from the deepest nested data constructor | ||
-- e.g. DLeft becomes "left" | ||
directionSyntax :: Direction -> Text | ||
directionSyntax d = toLower . T.tail . from $ case d of | ||
DAbsolute x -> show x | ||
DRelative x -> case x of | ||
DPlanar y -> show y | ||
_ -> show x | ||
|
||
-- | Check if the direction is absolute (e.g. 'north' or 'south'). | ||
isCardinal :: Direction -> Bool | ||
isCardinal = \case | ||
DAbsolute _ -> True | ||
_ -> False | ||
|
||
allDirs :: [Direction] | ||
allDirs = map DAbsolute Util.listEnums <> map DRelative (DDown : map DPlanar Util.listEnums) |
Oops, something went wrong.