Skip to content

Commit

Permalink
validate subworld names of explicitly located robots
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed May 29, 2024
1 parent eb20ea9 commit 4669c03
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
version: 1
name: Subworld shared structures
description: |
Traverse floors of the tower
Traverse the floors of the tower, then grab the flower in the middle
attrs:
- name: portal_in
fg: "#ff9a00"
bg: "#ff5d00"
- name: portal_out
fg: "#00a2ff"
bg: "#0065ff"
objectives:
- goal:
- |
Visit all of the floors
condition: |
as base {has "flower"}
entities:
- name: telepad entrance
display:
Expand All @@ -27,7 +33,9 @@ entities:
robots:
- name: base
dir: east
loc: [0, 0]
loc:
subworld: root
loc: [0, 0]
devices:
- ADT calculator
- branch predictor
Expand All @@ -41,6 +49,21 @@ robots:
- logger
- strange loop
- treads
solution: |
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;
doN 4 (
doN 4 move;
turn right;
doN 4 move;
);
doN 2 move;
turn right;
doN 2 move;
grab;
known: [flower]
structures:
- name: minibox
Expand Down Expand Up @@ -87,17 +110,18 @@ subworlds:
waypoint:
name: portal_in
placements:
- src: flowers
offset: [1, 1]
- src: minibox
offset: [0, 0]
orient:
up: west
- src: flowers
offset: [1, 1]
portals:
- entrance: portal_in
exitInfo:
exit: portal_out
subworldName: floor2
reorient: back
upperleft: [0, 0]
map: |
.....
Expand All @@ -119,17 +143,18 @@ subworlds:
waypoint:
name: portal_in
placements:
- src: flowers
offset: [1, 0]
- src: minibox
offset: [0, 0]
orient:
up: south
- src: flowers
offset: [1, 0]
portals:
- entrance: portal_in
exitInfo:
exit: portal_out
subworldName: floor3
reorient: back
upperleft: [0, 0]
map: |
.....
Expand All @@ -151,17 +176,18 @@ subworlds:
waypoint:
name: portal_in
placements:
- src: flowers
offset: [1, -2]
- src: minibox
offset: [0, 0]
orient:
up: east
- src: flowers
offset: [1, -2]
portals:
- entrance: portal_in
exitInfo:
exit: portal_out
subworldName: root
reorient: back
upperleft: [0, 0]
map: |
.....
Expand All @@ -171,20 +197,21 @@ subworlds:
.....
world:
name: root
default: [blank]
palette:
'.': [grass]
'B': [grass, null, base]
upperleft: [0, 0]
placements:
- src: flowers
offset: [0, -2]
- src: minibox
offset: [0, 0]
- src: flowers
offset: [0, -2]
portals:
- entrance: portal_in
exitInfo:
exit: portal_out
subworldName: floor1
reorient: back
map: |
.....
.....
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 1
name: Robot location in nonexistent named subworld
description: |
Robot specifies an explicit "planar" location, which uses
the "default" subworld name. However, since the root subworld
has been given a name, we object that the subworld specified by
the robot doesn't exist.
robots:
- name: base
dir: east
loc: [0, 0]
world:
name: mySubworld
palette:
'.': [grass]
map: |
.....
.....
.....
.....
.....
20 changes: 17 additions & 3 deletions src/swarm-scenario/Swarm/Game/Scenario.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import Control.Carrier.Throw.Either (runThrow)
import Control.Effect.Lift (Lift, sendIO)
import Control.Effect.Throw
import Control.Lens hiding (from, (.=), (<.>))
import Control.Monad (filterM, unless, (<=<))
import Control.Monad (filterM, forM_, unless, (<=<))
import Data.Aeson
import Data.List.NonEmpty (NonEmpty ((:|)))
import Data.List.NonEmpty qualified as NE
Expand All @@ -89,7 +89,7 @@ import Swarm.Game.Land
import Swarm.Game.Location
import Swarm.Game.Recipe
import Swarm.Game.ResourceLoading (getDataFileNameSafe)
import Swarm.Game.Robot (TRobot)
import Swarm.Game.Robot (TRobot, robotEntity, trobotLocation)
import Swarm.Game.Scenario.Objective
import Swarm.Game.Scenario.Objective.Validation
import Swarm.Game.Scenario.RobotLookup
Expand All @@ -112,7 +112,7 @@ import Swarm.Language.Pipeline (ProcessedTerm)
import Swarm.Language.Pretty (prettyText)
import Swarm.Language.Syntax (Syntax)
import Swarm.Language.Text.Markdown (Document)
import Swarm.Util (binTuples, failT)
import Swarm.Util (binTuples, commaList, failT, quote)
import Swarm.Util.Effect (ignoreWarnings, throwToMaybe, withThrow)
import Swarm.Util.Lens (makeLensesNoSigs)
import Swarm.Util.Yaml
Expand Down Expand Up @@ -352,6 +352,20 @@ instance FromJSONE ScenarioInputs Scenario where
, T.intercalate ", " $ map renderWorldName dupedNames
]

-- Validate robot locations
forM_ rs $ \r -> forM_ (r ^. trobotLocation) $ \rLoc ->
unless ((rLoc ^. subworld) `M.member` worldsByName)
. fail
. T.unpack
$ T.unwords
[ "Robot"
, quote $ r ^. robotEntity . entityName
, "specifies location in nonexistent subworld"
, quote (renderWorldName (rLoc ^. subworld)) <> "."
, "Valid subworlds are:"
, commaList $ map (quote . renderWorldName) $ M.keys worldsByName
]

let mergedWaypoints =
M.fromList $
map (worldName &&& runIdentity . waypoints . navigation) $
Expand Down
1 change: 1 addition & 0 deletions test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ testScenarioSolutions rs ui =
, testSolution Default "Testing/144-subworlds/basic-subworld"
, testSolution Default "Testing/144-subworlds/subworld-mapped-robots"
, testSolution Default "Testing/144-subworlds/subworld-located-robots"
, testSolution Default "Testing/144-subworlds/subworld-shared-structures"
, testSolution Default "Testing/1355-combustion"
, testSolution Default "Testing/1379-single-world-portal-reorientation"
, testSolution Default "Testing/1322-wait-with-instant"
Expand Down

0 comments on commit 4669c03

Please sign in to comment.