From 601283126790bd79afd9a9b97700e6550e04cb66 Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Sat, 7 Dec 2024 19:17:50 -0800 Subject: [PATCH] More challenge levels --- app/Model.hs | 8 ++-- app/Parser.hs | 19 ++++++--- levels/challenge08.txt | 27 +++++++++++++ levels/challenge18.txt | 87 ++++++++++++++++++++++++++++++++++++++++++ levels/challenge30.txt | 43 +++++++++++++++++++++ levels/challenge31.txt | 56 +++++++++++++++++++++++++++ 6 files changed, 231 insertions(+), 9 deletions(-) create mode 100644 levels/challenge08.txt create mode 100644 levels/challenge18.txt create mode 100644 levels/challenge30.txt create mode 100644 levels/challenge31.txt diff --git a/app/Model.hs b/app/Model.hs index 32d3b9f..8d7a922 100644 --- a/app/Model.hs +++ b/app/Model.hs @@ -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' diff --git a/app/Parser.hs b/app/Parser.hs index 483ecff..49cf386 100644 --- a/app/Parser.hs +++ b/app/Parser.hs @@ -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 diff --git a/levels/challenge08.txt b/levels/challenge08.txt new file mode 100644 index 0000000..4586126 --- /dev/null +++ b/levels/challenge08.txt @@ -0,0 +1,27 @@ +player p height 81 +block b blue interesting +▓▓▓▓▓▓▓▓▓ +▓ ▓ +▓ - - ▓ +▓ y g ▓ + ▓ ▓ +▓ p b ▓ +▓ ▓ +▓ ▓ +▓▓▓▓▓▓▓▓▓ +block y yellow boring +▓ +block g green interesting +▓▓▓▓▓▓▓ +▓ ▓ +▓ ▓ + ▓ +▓▓▓ ▓ +▓= - ▓ +▓▓▓▓▓▓▓ +block p red boring +▓▓▓▓▓ +▓ ▓ ▓ +▓▓▓▓▓ +▓▓▓▓▓ +▓▓▓▓▓ diff --git a/levels/challenge18.txt b/levels/challenge18.txt new file mode 100644 index 0000000..c5262a6 --- /dev/null +++ b/levels/challenge18.txt @@ -0,0 +1,87 @@ +player p height 154 +block w white boring +▓▓▓▓▓▓▓▓▓▓▓ +▓abc▓ q▓▓▓▓ +▓ p ▓▓ +▓123▓▓▓▓y ▓ +▓▓▓▓▓▓▓▓▓ ▓ +▓▓▓▓▓▓▓I H▓ +▓▓▓4▓▓▓ ▓▓▓ +▓ ▓K J▓▓▓ +▓ ▓▓▓▓▓ +▓LMN▓ r▓▓▓▓ +▓▓▓▓▓▓▓▓▓▓▓ +block 1 green boring +▓▓▓▓▓ +▓▓▓▓▓ +▓▓▓▓▓ +▓▓ +▓▓ ▓▓ +block 2 green boring +▓▓▓▓▓ +▓▓ +▓▓ ▓▓ + ▓▓ +▓▓▓▓▓ +block 3 green boring +▓ ▓▓▓ + ▓▓▓ +▓▓▓▓▓ +▓▓▓▓▓ +▓▓▓▓▓ +block 4 green boring +▓▓▓▓▓ +▓▓▓▓▓ +▓▓▓▓▓ +▓=▓▓▓ +▓ ▓▓▓ +block A cyan boring +▓ +block B cyan boring +▓ +block C cyan boring +▓ +block D cyan boring +▓ +block E cyan boring +▓ +block F cyan boring +▓ +block G cyan boring +▓ +block H cyan boring +▓ +block I cyan boring +▓ +block J cyan boring +▓ +block K cyan boring +▓ +block L cyan boring +▓ +block M cyan boring +▓ +block N cyan boring +▓ +block p red boring height 1 +ABCDEFG +link q p red +link r p red +block a blue boring +▓▓▓ +▓▓▓ +▓ ▓ +block b blue boring +▓▓▓ +▓▓▓ +▓ ▓ +block c blue boring +▓▓▓ +▓▓▓ +▓ ▓ +block y yellow boring +▓▓ ▓▓ +▓▓ +▓▓▓▓▓ +▓▓▓▓▓ +▓▓▓▓▓ diff --git a/levels/challenge30.txt b/levels/challenge30.txt new file mode 100644 index 0000000..744cdb2 --- /dev/null +++ b/levels/challenge30.txt @@ -0,0 +1,43 @@ +player p height 81 +block w white boring +▓▓▓▓▓▓▓▓▓ +▓▓▓ y▓▓▓▓ +▓ ▓▓ +▓ G ▓▓ +▓=p g▓ +▓ Y ▓▓ +▓ ▓▓ +▓▓E▓F▓▓▓▓ +▓▓▓▓▓▓▓▓▓ +link G g green +link Y y yellow +block p red boring +▓▓▓▓▓ +▓ ▓ ▓ +▓▓▓▓▓ +▓▓▓▓▓ +▓▓▓▓▓ +block y yellow boring +▓▓▓ + ▓▓ +▓▓▓ +block g green boring +▓▓▓ + ▓▓ +▓▓▓ +epsilon E y yellow +▓▓▓ ▓ + + + + 1- +epsilon F g green +▓▓▓ ▓ + + + + 2- +block 1 cyan boring +▓ +block 2 cyan boring +▓ diff --git a/levels/challenge31.txt b/levels/challenge31.txt new file mode 100644 index 0000000..6e722bc --- /dev/null +++ b/levels/challenge31.txt @@ -0,0 +1,56 @@ +player p height 81 +block w white boring +▓▓▓▓▓▓▓▓▓ +▓ ▓ +▓ g y ▓ +▓B G Y b▓ +▓ ▓ +▓ p ▓▓▓▓ +▓= ▓ +▓▓▓▓▓QRS▓ +▓▓▓▓▓▓▓▓▓ +link G g green +link Y y yellow +link B b blue +block p red boring +▓▓▓▓▓ +▓ ▓ ▓ +▓▓▓▓▓ +▓▓▓▓▓ +▓▓▓▓▓ +block y yellow interesting +▓▓▓ +▓▓▓ +▓ ▓ +block g green interesting +▓▓▓ +▓▓▓ +▓ ▓ +block b blue interesting +▓▓▓ +▓▓▓ +▓ ▓ +epsilon Q g green +▓▓▓ ▓ +▓-▓ ▓ +▓1 ▓ +▓ ▓▓▓ +▓ ▓▓ +epsilon R y yellow +▓▓▓ ▓ +▓-▓ ▓ +▓2 ▓ +▓ ▓▓▓ +▓ ▓▓ +epsilon S b blue +▓▓▓ ▓ +▓-▓ ▓ +▓3 ▓ +▓ ▓▓▓ +▓ ▓▓ +block 1 cyan boring +▓ +block 2 cyan boring +▓ +block 3 cyan boring +▓