-
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.
- Loading branch information
Showing
12 changed files
with
179 additions
and
3 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
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,56 @@ | ||
version: 1 | ||
name: Demo volume command | ||
description: | | ||
Measure volume of enclosed space | ||
creative: true | ||
objectives: | ||
- goal: | ||
- | | ||
Make an enclosed volume of 14 cells | ||
condition: | | ||
as base { | ||
let targetVolume = 14 in | ||
vol <- volume targetVolume; | ||
return $case vol (\_. false) (\x. x == targetVolume); | ||
} | ||
solution: | | ||
move; | ||
push; | ||
turn left; | ||
move; | ||
turn right; | ||
move; | ||
turn right; | ||
push; | ||
robots: | ||
- name: base | ||
dir: east | ||
devices: | ||
- ADT calculator | ||
- treads | ||
- dozer blade | ||
- logger | ||
- branch predictor | ||
- comparator | ||
entities: | ||
- name: monolith | ||
display: | ||
char: '@' | ||
description: | ||
- Pushable rock | ||
properties: [known, unwalkable, pickable] | ||
known: [mountain] | ||
world: | ||
dsl: | | ||
{grass} | ||
palette: | ||
'B': [grass, null, base] | ||
'.': [grass] | ||
'A': [stone, mountain] | ||
'@': [grass, monolith] | ||
upperleft: [-1, 1] | ||
map: | | ||
AAAAAAAAA | ||
A.......A | ||
AB.@....A | ||
AAAA.AAAA |
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 |
---|---|---|
|
@@ -55,6 +55,7 @@ | |
"selfdestruct" | ||
"move" | ||
"backup" | ||
"volume" | ||
"path" | ||
"push" | ||
"stride" | ||
|
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,65 @@ | ||
-- | | ||
-- SPDX-License-Identifier: BSD-3-Clause | ||
-- | ||
-- Implementation of the 'Swarm.Language.Syntax.Volume' command for robots. | ||
module Swarm.Game.Step.Flood ( | ||
floodFill, | ||
) where | ||
|
||
import Control.Effect.Lens | ||
import Control.Monad (filterM) | ||
import Data.HashSet (HashSet) | ||
import Data.HashSet qualified as HashSet | ||
import Swarm.Game.Location | ||
import Swarm.Game.Step.RobotStepState | ||
import Swarm.Game.Step.Util (checkMoveFailureUnprivileged) | ||
import Swarm.Game.Step.Util.Inspect (getNeighborLocs) | ||
import Swarm.Game.Universe | ||
|
||
data FloodParms = FloodParms | ||
{ theSubworld :: SubworldName | ||
, maxVisits :: Int | ||
} | ||
|
||
floodRecursive :: | ||
HasRobotStepState sig m => | ||
HashSet Location -> | ||
[Location] -> | ||
FloodParms -> | ||
m (Maybe Int) | ||
floodRecursive visited pending st = | ||
case pending of | ||
nextLoc : otherLocs -> | ||
if visitedCount > maxVisits st | ||
then return Nothing | ||
else checkNeighbors nextLoc otherLocs | ||
[] -> return $ Just visitedCount | ||
where | ||
visitedCount = HashSet.size visited | ||
checkNeighbors nextLoc otherLocs = do | ||
candidateNeighbors <- listNeighbors $ Cosmic (theSubworld st) nextLoc | ||
let visitableNeighbors = filter (not . (`HashSet.member` visited)) candidateNeighbors | ||
-- It's cheaper to prepend the "visitableNeighbors" list because | ||
-- it should in general be a shorter list than the pending queue. | ||
newPending = visitableNeighbors <> otherLocs | ||
floodRecursive newVisited newPending st | ||
where | ||
newVisited = HashSet.insert nextLoc visited | ||
|
||
listNeighbors :: | ||
HasRobotStepState sig m => | ||
Cosmic Location -> | ||
m [Location] | ||
listNeighbors loc = do | ||
locs <- filterM isWalkableLoc $ getNeighborLocs loc | ||
return $ map (view planar) locs | ||
where | ||
isWalkableLoc = fmap null . checkMoveFailureUnprivileged | ||
|
||
floodFill :: | ||
HasRobotStepState sig m => | ||
Cosmic Location -> | ||
Int -> | ||
m (Maybe Int) | ||
floodFill (Cosmic swn curLoc) = | ||
floodRecursive mempty [curLoc] . FloodParms swn |
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
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