Skip to content

Commit

Permalink
Enforce palette usage
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Jun 15, 2024
1 parent 85d5d9b commit ce3b1eb
Show file tree
Hide file tree
Showing 41 changed files with 108 additions and 129 deletions.
1 change: 0 additions & 1 deletion data/scenarios/Challenges/Ranching/powerset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ world:
upperleft: [-1, -1]
offset: false
palette:
'.': [grass]
'B': [grass, null, base]
'S': [grass, null, setup]
map: |
Expand Down
1 change: 0 additions & 1 deletion data/scenarios/Challenges/Sokoban/foresight.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ world:
'@': [grass, monolith]
'c': [grass, crate]
'A': [grass, wall]
'w': [dirt, water]
'x': [stone, erase]
'z': [dirt, erase]
map: |
Expand Down
1 change: 0 additions & 1 deletion data/scenarios/Challenges/ice-cream.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ world:
upperleft: [0, 0]
offset: false
palette:
'@': [stone, boulder]
'.': [grass]
':': [stone]
'B': [stone, briefcase]
Expand Down
1 change: 0 additions & 1 deletion data/scenarios/Challenges/lights-out.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ world:
z: [blank, null, judge]
'.': [blank]
'x': [blank, "off"]
'o': [blank, "on"]
map: |
B......
.xxxxx.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ world:
palette:
'.': [grass]
'*': [stone, flower]
'P': [grass, telepad entrance]
'p': [grass, telepad exit]
'': [stone, upper left corner]
'': [stone, upper right corner]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ subworlds:
palette:
'.': [dirt]
'b': [dirt, boulder]
't': [grass, null, judge]
'p':
cell: [dirt, telepad exit]
waypoint:
Expand All @@ -94,8 +93,6 @@ world:
palette:
'.': [grass]
'f': [grass, flower]
'B': [grass, null, base]
't': [grass, null, judge]
'p':
cell: [grass, telepad exit]
waypoint:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ structures:
palette:
'.': [stone]
'd': [dirt]
'f': [stone, flower]
'p':
cell: [grass, telepad exit]
waypoint:
Expand Down Expand Up @@ -99,15 +98,6 @@ subworlds:
default: [blank]
palette:
'.': [dirt]
'f': [dirt, flower]
'p':
cell: [dirt, telepad exit]
waypoint:
name: portal_out
'P':
cell: [dirt, telepad entrance]
waypoint:
name: portal_in
placements:
- src: minibox
offset: [0, 0]
Expand All @@ -132,15 +122,6 @@ subworlds:
default: [blank]
palette:
'.': [dirt]
'f': [dirt, flower]
'p':
cell: [dirt, telepad exit]
waypoint:
name: portal_out
'P':
cell: [dirt, telepad entrance]
waypoint:
name: portal_in
placements:
- src: minibox
offset: [0, 0]
Expand All @@ -165,15 +146,6 @@ subworlds:
default: [blank]
palette:
'.': [dirt]
'f': [dirt, flower]
'p':
cell: [dirt, telepad exit]
waypoint:
name: portal_out
'P':
cell: [dirt, telepad entrance]
waypoint:
name: portal_in
placements:
- src: minibox
offset: [0, 0]
Expand All @@ -198,7 +170,6 @@ world:
name: root
palette:
'.': [grass]
'B': [grass, null, base]
upperleft: [0, 0]
placements:
- src: minibox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ known: [tree, flower, bitcoin]
world:
palette:
'B': [grass, null, base]
'.': [grass]
'T': [grass, tree]
'b': [grass, bitcoin]
'f': [grass, flower]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ world:
'B': [grass, erase, base]
'.': [grass]
'f': [grass, flower]
'@': [grass, monolith]
upperleft: [0, 0]
map: |
....
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ world:
'q': [grass, quartz]
'g': [grass, gold]
's': [grass, silver]
'm': [grass, mithril]
'c': [grass, cotton]
'B': [grass, null, base]
upperleft: [0, 0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ world:
'q': [grass, quartz]
'g': [grass, gold]
's': [grass, silver]
'm': [grass, mithril]
'c': [grass, cotton]
'B': [grass, null, base]
upperleft: [0, 0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ world:
{blank}
palette:
'.': [grass]
'g': [grass, gold]
's': [grass, silver]
'B': [grass, null, base]
upperleft: [0, 0]
placements:
Expand Down
1 change: 0 additions & 1 deletion data/scenarios/Testing/1681-pushable-entity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ world:
palette:
'Ω': [grass, erase, base]
'j': [stone, erase, judge]
'.': [grass, erase]
'x': [grass, crate]
upperleft: [0, 0]
map: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ world:
'.': [grass]
'i': [ice]
'j': [dirt]
'k': [stone]
'l': [stone, sand]
'm': [stone, water]
upperleft: [3, 3]
structures:
- name: single tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ world:
- src: horizontal rectangle
- name: combined rectangles empty base
structure:
palette:
'x': [blank]
map: ""
placements:
- src: vertical rectangle
Expand Down
1 change: 0 additions & 1 deletion data/scenarios/Testing/687-watch-command.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ world:
p: [grass, null, planter]
b: [grass, null, competitor]
'.': [grass]
'T': [grass, tree]
upperleft: [0, 0]
map: |
......b...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ world:
'.': [grass]
'x': [stone, mountain]
'f': [grass, flower]
'T': [grass, tree]
upperleft: [0, 0]
map: |
xxxxx......
Expand Down
13 changes: 13 additions & 0 deletions data/scenarios/Testing/_Validation/1938-palette-usage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 1
name: Enforce palette usage
description: |
Every entry in the palette must be used by the world map.
robots: []
world:
palette:
'.': [grass]
'd': [dirt]
upperleft: [0, 0]
map: |
..
..
5 changes: 0 additions & 5 deletions data/scenarios/Vignettes/roadway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ world:
palette:
'S':
- stone
'w':
- ice
'':
- stone
- sand
map: |
SSSSSS
SSSSSS
Expand Down
6 changes: 0 additions & 6 deletions data/test/standalone-topography/checkerboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ structures:
ttttffff
- name: checker quad
structure:
palette:
't': true
'f': false
map: ""
placements:
- src: checker pair
Expand All @@ -26,9 +23,6 @@ structures:
up: south
- name: checker octo
structure:
palette:
't': true
'f': false
map: ""
placements:
- src: checker quad
Expand Down
9 changes: 5 additions & 4 deletions src/swarm-engine/Swarm/Game/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ import Swarm.Game.Terrain
import Swarm.Game.Tick (addTicks)
import Swarm.Game.Universe as U
import Swarm.Game.World qualified as W
import Swarm.Game.World.Coords
import Swarm.Game.World.Gen (Seed)
import Swarm.Language.Capability (constCaps)
import Swarm.Language.Context qualified as Ctx
Expand Down Expand Up @@ -339,9 +340,9 @@ recalcViewCenterAndRedraw g =

-- | Given a width and height, compute the region, centered on the
-- 'viewCenter', that should currently be in view.
viewingRegion :: Cosmic Location -> (Int32, Int32) -> Cosmic W.BoundsRectangle
viewingRegion :: Cosmic Location -> (Int32, Int32) -> Cosmic BoundsRectangle
viewingRegion (Cosmic sw (Location cx cy)) (w, h) =
Cosmic sw (W.Coords (rmin, cmin), W.Coords (rmax, cmax))
Cosmic sw (Coords (rmin, cmin), Coords (rmax, cmax))
where
(rmin, rmax) = over both (+ (-cy - h `div` 2)) (0, h - 1)
(cmin, cmax) = over both (+ (cx - w `div` 2)) (0, w - 1)
Expand Down Expand Up @@ -479,7 +480,7 @@ initGameState gsc =
-- | Get the entity (if any) at a given location.
entityAt :: (Has (State GameState) sig m) => Cosmic Location -> m (Maybe Entity)
entityAt (Cosmic subworldName loc) =
join <$> zoomWorld subworldName (W.lookupEntityM @Int (W.locToCoords loc))
join <$> zoomWorld subworldName (W.lookupEntityM @Int (locToCoords loc))

contentAt ::
(Has (State GameState) sig m) =>
Expand All @@ -488,7 +489,7 @@ contentAt ::
contentAt (Cosmic subworldName loc) = do
tm <- use $ landscape . terrainAndEntities . terrainMap
val <- zoomWorld subworldName $ do
(terrIdx, maybeEnt) <- W.lookupContentM (W.locToCoords loc)
(terrIdx, maybeEnt) <- W.lookupContentM (locToCoords loc)
let terrObj = terrIdx `IM.lookup` terrainByIndex tm
return (maybe BlankT terrainName terrObj, maybeEnt)
return $ fromMaybe (BlankT, Nothing) val
Expand Down
3 changes: 2 additions & 1 deletion src/swarm-engine/Swarm/Game/Step/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Swarm.Game.Step.Path.Walkability
import Swarm.Game.Step.RobotStepState
import Swarm.Game.Universe
import Swarm.Game.World qualified as W
import Swarm.Game.World.Coords
import Swarm.Game.World.Modify qualified as WM
import Swarm.Language.Capability
import Swarm.Language.Requirement qualified as R
Expand Down Expand Up @@ -69,7 +70,7 @@ updateEntityAt ::
updateEntityAt cLoc@(Cosmic subworldName loc) upd = do
someChange <-
zoomWorld subworldName $
W.updateM @Int (W.locToCoords loc) upd
W.updateM @Int (locToCoords loc) upd

forM_ (WM.getModification =<< someChange) $ \modType -> do
currentTick <- use $ temporal . ticks
Expand Down
3 changes: 2 additions & 1 deletion src/swarm-engine/Swarm/Game/Step/Util/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import Swarm.Game.Step.RobotStepState
import Swarm.Game.Step.Util
import Swarm.Game.Universe
import Swarm.Game.World qualified as W
import Swarm.Game.World.Coords
import Swarm.Language.Capability
import Swarm.Language.Context hiding (delete)
import Swarm.Language.Pipeline
Expand Down Expand Up @@ -446,7 +447,7 @@ updateWorld ::
m ()
updateWorld c (ReplaceEntity loc eThen down) = do
w <- use $ landscape . multiWorld
let eNow = W.lookupCosmicEntity (fmap W.locToCoords loc) w
let eNow = W.lookupCosmicEntity (fmap locToCoords loc) w
-- Can fail if a robot started a multi-tick "drill" operation on some entity
-- and meanwhile another entity swaps it out from under them.
if Just eThen /= eNow
Expand Down
2 changes: 1 addition & 1 deletion src/swarm-scenario/Swarm/Game/State/Landscape.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import Swarm.Game.State.Config
import Swarm.Game.Terrain (TerrainType (..), terrainIndexByName)
import Swarm.Game.Universe as U
import Swarm.Game.World
import Swarm.Game.World.Coords (addTuple)
import Swarm.Game.World.Coords
import Swarm.Game.World.Eval (runWorld)
import Swarm.Game.World.Gen (Seed, findGoodOrigin)
import Swarm.Util (applyWhen)
Expand Down
6 changes: 0 additions & 6 deletions src/swarm-scenario/Swarm/Game/World.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
-- indexed by 32-bit signed integers, so they correspond to a
-- \( 2^{32} \times 2^{32} \) torus).
module Swarm.Game.World (
-- * World coordinates
Coords (..),
locToCoords,
coordsToLoc,
BoundsRectangle,

-- * Worlds
WorldFun (..),
runWF,
Expand Down
1 change: 1 addition & 0 deletions src/swarm-scenario/Swarm/Game/World/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Data.Set qualified as S
import Data.Text (Text)
import Swarm.Game.Entity
import Swarm.Game.World
import Swarm.Game.World.Coords
import Swarm.Game.World.Syntax (CellVal (..))
import Swarm.Game.World.Typecheck (Const (CCell), TTerm (..))
import Swarm.Util.Erasable
Expand Down
6 changes: 3 additions & 3 deletions src/swarm-scenario/Swarm/Game/World/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Swarm.Game.Scenario.Topography.Rasterize
import Swarm.Game.Scenario.Topography.Structure.Overlay
import Swarm.Game.State.Landscape
import Swarm.Game.Universe
import Swarm.Game.World qualified as W
import Swarm.Game.World.Coords
import Swarm.Game.World.Gen (Seed)
import Swarm.Language.Pretty (prettyString)
import Swarm.Util (surfaceEmpty)
Expand Down Expand Up @@ -99,7 +99,7 @@ getBoundingBox ::
Location ->
PWorldDescription e ->
Maybe AreaDimensions ->
W.BoundsRectangle
BoundsRectangle
getBoundingBox vc scenarioWorld maybeSize =
mkBoundingBox areaDims upperLeftLocation
where
Expand All @@ -109,7 +109,7 @@ getBoundingBox vc scenarioWorld maybeSize =
else vc .+^ ((`div` 2) <$> V2 (negate w) h)

mkBoundingBox areaDimens upperLeftLoc =
both W.locToCoords locationBounds
both locToCoords locationBounds
where
lowerRightLocation = computeBottomRightFromUpperLeft areaDimens upperLeftLoc
locationBounds = (upperLeftLoc, lowerRightLocation)
Expand Down
1 change: 1 addition & 0 deletions src/swarm-scenario/Swarm/Util/Content.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Swarm.Game.Scenario.Topography.EntityFacade
import Swarm.Game.Terrain (TerrainMap, TerrainType, getTerrainWord)
import Swarm.Game.Universe
import Swarm.Game.World
import Swarm.Game.World.Coords
import Swarm.Util.Erasable (erasableToMaybe, maybeToErasable)

-- | Get the terrain and entity at a single cell
Expand Down
Loading

0 comments on commit ce3b1eb

Please sign in to comment.