More challenge levels

This commit is contained in:
2024-12-07 19:17:50 -08:00
parent 05161a3c42
commit 6012831267
6 changed files with 231 additions and 9 deletions

View File

@@ -139,13 +139,13 @@ moveBlock' world locMap visited loc loc' dir name box enters offset =
do (n,b) <- Map.lookup loc' locMap
(locI, offset') <- enterLoc world n b dir offset
if Set.member locI enters then
moveEpsilon
do epsilon <- findEpsilon world (locName locI)
moveEpsilon epsilon
else
moveBlock' world locMap visited loc locI dir name box (Set.insert locI enters) offset'
moveEpsilon =
do epsilon <- findEpsilon world (locName loc')
let eBox = boxIx world epsilon
moveEpsilon epsilon =
do let eBox = boxIx world epsilon
(locI, offset') <- enterLoc world epsilon eBox dir offset
moveBlock' world locMap visited loc locI dir name box (Set.insert locI enters) offset'

View File

@@ -62,6 +62,12 @@ parseBoring =
"interesting" -> pure False
_ -> empty
parseHeight :: ReadP (Maybe Int)
parseHeight = option Nothing $
do "height" <- token
Just <$> integer
parseBlock :: ReadP (Char, Box, [(Char, Location)])
parseBlock =
do cmd <- token
@@ -70,9 +76,10 @@ parseBlock =
do [name] <- token
color <- parseColor
boring <- parseBoring
height <- parseHeight
skipMany (satisfy (' '==))
_ <- char '\n'
xs1 <- parseWalls
xs1 <- parseWalls height
let locs = findLocs name xs1
let b = Box Nothing (Original (walls xs1)) color boring
pure (name, b, locs)
@@ -92,18 +99,20 @@ parseBlock =
do [name] <- token
[target] <- token
color <- parseColor
height <- parseHeight
skipMany (satisfy (' '==))
_ <- char '\n'
xs1 <- parseWalls
xs1 <- parseWalls height
let locs = findLocs name xs1
let b = Box Nothing (Epsilon target (walls xs1)) color False
pure (name, b, locs)
_ -> empty
parseWalls :: ReadP [String]
parseWalls =
parseWalls :: Maybe Int -> ReadP [String]
parseWalls height =
do row0 <- munch1 ('\n' /=) <* char '\n'
rows <- replicateM (length row0 - 1) (munch1 ('\n' /=) <* char '\n')
let h = maybe (length row0 - 1) (subtract 1) height
rows <- replicateM h (munch1 ('\n' /=) <* char '\n')
pure (row0:rows)
token :: ReadP String