Compare commits

...

2 Commits

Author SHA1 Message Date
e28a3f5b07 more levels 2024-12-08 16:36:16 -08:00
6012831267 More challenge levels 2024-12-07 19:17:50 -08:00
28 changed files with 1029 additions and 31 deletions

View File

@ -85,20 +85,21 @@ isWall world (Location n y x) =
type Movement = (Int, Int)
moveBlock ::
World ->
Map Location (Char, Box) ->
Map Location (Int, Char, Maybe Location) ->
Location ->
Movement ->
World {- ^ world -} ->
Map Location (Char, Box) {- ^ location cache -} ->
Map Location (Int, Char, Maybe Location) {- ^ accumulated changes -} ->
Location {- ^ source location -} ->
Movement {- ^ movement direction -} ->
Rational {- ^ offset -} ->
Maybe (Map Char (Maybe Location))
-- moving into a wall, not possible
-- moving a wall, not possible
moveBlock world _ _ loc _ _
| isWall world loc = Nothing
-- move introduced a loop, trim off the tail and report success
moveBlock _ _ visited loc _ _
-- XXX: ensure update is consistent to support flipped levels
| Just (n,_,_) <- Map.lookup loc visited
= Just (Map.fromList [(c,l) | (a,c,l) <- Map.elems visited, a >= n])
@ -126,7 +127,7 @@ moveBlock' ::
Movement ->
Char ->
Box ->
Set Location ->
Set Char ->
Rational {- ^ offset -} ->
Maybe (Map Char (Maybe Location))
moveBlock' world locMap visited loc loc' dir name box enters offset =
@ -138,16 +139,16 @@ moveBlock' world locMap visited loc loc' dir name box enters offset =
moveInto =
do (n,b) <- Map.lookup loc' locMap
(locI, offset') <- enterLoc world n b dir offset
if Set.member locI enters then
moveEpsilon
if Set.member (locName loc') enters then
do epsilon <- findEpsilon world (locName loc')
moveEpsilon epsilon
else
moveBlock' world locMap visited loc locI dir name box (Set.insert locI enters) offset'
moveBlock' world locMap visited loc locI dir name box (Set.insert (locName loc') 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'
moveBlock' world locMap visited loc locI dir name box enters offset'
moveToEat =
do let dir' = invert dir

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

65
levels/challenge04.txt Normal file
View File

@ -0,0 +1,65 @@
player p height 98
block W white boring
▓▓▓
▓w▓
▓▓▓
block w white interesting
▓U▓
7▓
p 1 ▓▓
▓▓
2 3 ▓▓
L▓
▓=▓
block U green interesting
▓▓▓
▓-▓
▓y▓
block y yellow boring
block 7 blue interesting
▓▓▓▓▓▓▓
block L blue interesting
▓▓▓▓▓▓▓
block 1 green interesting
▓▓
▓▓
▓▓
▓▓
block 2 green interesting
▓▓
▓▓
▓▓
▓▓
block 3 green interesting
▓▓
▓▓
▓▓
▓▓
▓▓
▓▓
block p red interesting
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓

57
levels/challenge05.txt Normal file
View File

@ -0,0 +1,57 @@
player p height 90
block W white boring
▓▓▓
▓w▓
▓▓▓
block w white interesting
p
g b
G B
▓▓▓
block g green interesting
▓▓▓▓▓▓▓▓▓
▓▓
▓▓
▓▓
▓▓
▓▓ ▓
▓▓
▓▓▓▓▓▓▓▓▓
block G green interesting
▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓=
▓▓▓▓▓▓▓▓▓
▓▓
▓ ▓
▓▓
▓▓
▓▓
▓▓▓▓▓▓▓▓▓
block b blue interesting
▓▓▓▓▓▓▓▓▓
▓▓
▓▓
▓▓
▓ ▓
▓▓
▓ ▓▓
▓ ▓▓
▓▓▓▓▓▓▓▓▓
block B blue interesting
▓▓▓▓▓▓▓▓▓
▓ ▓▓
▓▓
▓▓
▓ ▓
▓▓
▓▓
▓ ▓▓
▓▓▓▓▓▓▓▓▓
block p red interesting
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓

39
levels/challenge06.txt Normal file
View File

@ -0,0 +1,39 @@
player p height 105
block W white boring
▓▓▓
▓w▓
▓▓▓
block w white interesting
p 1
=
2 3
block 1 blue interesting
block 2 green interesting
block 3 yellow interesting
block p red interesting
-

27
levels/challenge08.txt Normal file
View File

@ -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
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓

89
levels/challenge11.txt Normal file
View File

@ -0,0 +1,89 @@
player p height 98
block w white boring
▓▓▓▓▓▓▓
▓▓▓ab▓▓
▓▓▓gc▓▓
▓▓▓▓▓▓▓
▓▓▓▓▓▓▓
▓p d▓
▓▓▓▓▓▓▓
link a g green
link b g green
link c g green
link d g green
block g green interesting
1ABCD
EFGHI
KLM2
OP3QR
STUVW
block 1 yellow interesting
▓▓ ▓▓
▓▓
▓▓▓▓▓
▓▓▓=
▓▓▓▓▓
block 2 yellow interesting
▓ ▓ ▓
▓ ▓
▓ ▓ ▓
▓ ▓
▓▓▓ ▓
block 3 yellow interesting
▓▓▓ ▓
▓▓▓ ▓
▓▓▓ ▓
▓ ▓▓▓
block A blue boring
block B blue boring
block C blue boring
block D blue boring
block E blue boring
block F blue boring
block G blue boring
block H blue boring
block I blue boring
block J blue boring
block K blue boring
block L blue boring
block M blue boring
block N blue boring
block O blue boring
block P blue boring
block Q blue boring
block R blue boring
block S blue boring
block T blue boring
block U blue boring
block V blue boring
block W blue boring
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓

46
levels/challenge16.txt Normal file
View File

@ -0,0 +1,46 @@
player p height 98
block g green interesting
▓▓▓▓▓▓▓▓▓
▓▓g123456
▓▓▓▓ ▓▓▓▓
▓ ▓
▓ 7 8 9 ▓
▓ ▓
▓ p y ▓
▓ Y▓
▓▓▓▓▓▓▓▓▓
block y yellow interesting
link Y y yellow
block 1 red boring
block 2 red boring
block 3 red boring
block 4 red boring
▓▓▓
▓=▓
▓ ▓
block 5 red boring
block 6 red boring
block 7 red boring
block 8 red boring
block 9 red boring
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓

View File

@ -45,10 +45,12 @@ block y blue boring
block z blue boring
block p magenta boring
block p magenta boring height 7
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓
block 1 green interesting

87
levels/challenge18.txt Normal file
View File

@ -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
▓▓ ▓▓
▓▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓

43
levels/challenge30.txt Normal file
View File

@ -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

56
levels/challenge31.txt Normal file
View File

@ -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

70
levels/challenge32.txt Normal file
View File

@ -0,0 +1,70 @@
player p
block W white boring
▓▓▓
▓w▓
▓▓▓
block w white interesting
▓▓Y▓
1 ▓ y
2
3 p
ABC
▓ 4567
block Y yellow interesting
▓▓▓▓▓
▓▓▓▓▓
▓ =▓▓
▓ ▓▓▓
▓ ▓▓▓
block g green interesting
▓D▓
E▓F
▓G▓
link A g green
link B g green
link C g green
link D g green
link E g green
link F g green
link G g green
epsilon ε g green
block Q red interesting
▓▓▓▓▓▓▓▓▓
▓ ▓
▓ ▓
▓ ▓
▓ ε ▓
▓ ▓
▓ ▓
▓ ▓
▓▓▓▓▓▓▓▓▓
block 1 blue boring
block 2 blue boring
block 3 blue boring
block 4 blue boring
block 5 blue boring
block 6 blue boring
block 7 blue boring
block y yellow boring
▓ ▓▓▓
▓ ▓▓▓
▓▓▓
▓▓▓▓▓
▓▓▓▓▓
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓

68
levels/challenge33.txt Normal file
View File

@ -0,0 +1,68 @@
player p height 121
block b blue interesting
▓▓
▓ ▓▓
▓A
▓▓
p ▓B
▓ ▓▓
f b▓▓▓C
▓▓▓▓▓
▓▓▓▓D
▓▓▓▓y▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓
block y yellow interesting
link f b blue
epsilon A b blue
X
▓ c
link c b blue
link X y yellow
epsilon B A blue
Y
d
▓ ▓
2
link d b blue
link Y y yellow
epsilon C B blue
Z
e 3
link e b blue
link Z y yellow
epsilon D C blue
=
block 1 yellow boring
block 2 yellow boring
block 3 yellow boring
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓

36
levels/challenge34.txt Normal file
View File

@ -0,0 +1,36 @@
player p height 98
block w white interesting
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓ ▓▓▓ ▓
▓ ▓ ▓
▓ 1 ▓ E ▓
▓ ▓▓ ▓
▓ 2 3 ▓ ▓
▓ ▓▓▓▓▓▓▓
▓ ▓ p ▓▓-▓▓
▓ ▓- F ▓
▓ A b ▓▓▓▓-▓▓
▓ ▓▓▓▓▓▓▓
▓ B ▓▓= ▓▓▓
▓ ▓▓ I ▓▓
▓ ▓▓▓ ▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
block b blue interesting
epsilon E b blue
epsilon F E blue
link A b blue
link B b blue
infinity I b blue
block 1 yellow boring
block 2 yellow boring
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓

33
levels/gallery01.txt Normal file
View File

@ -0,0 +1,33 @@
player p height 98
block w white interesting
▓▓▓▓▓▓▓
▓ ▓
▓ b ▓
▓ p ▓
▓ g ▓
▓ ▓
▓▓▓▓▓▓▓
block b blue interesting
block g green interesting
▓▓▓ ▓▓▓
▓▓ ▓▓▓
▓▓ ▓▓▓▓
=▓ ▓▓
▓▓-12 ▓
▓▓-▓▓▓▓
▓▓▓▓▓▓▓
block 1 yellow boring
block 2 yellow boring
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓

23
levels/gallery02.txt Normal file
View File

@ -0,0 +1,23 @@
player p height 98
block b blue interesting
▓▓▓▓▓▓▓
▓ ▓
▓ g ▓
▓p -
▓ b ▓
▓ ▓
▓▓▓▓▓▓▓
block g green interesting
▓▓▓▓▓▓▓
▓ ▓
▓ ▓
- = ▓
▓ ▓
▓ ▓
▓▓▓▓▓▓▓
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓

23
levels/gallery03.txt Normal file
View File

@ -0,0 +1,23 @@
player p height 98
block b blue interesting
▓▓▓▓▓▓▓
=▓
- -p ▓
g ▓
▓ b▓▓
▓▓▓▓ ▓▓
▓▓▓▓▓▓
block g green interesting
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓

View File

@ -0,0 +1,26 @@
player p
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓
block w white interesting
▓▓▓▓▓▓▓
▓▓▓▓ ▓▓
▓ g ▓
▓ ▓
▓ p ▓
▓ G ▓
▓▓▓▓▓▓▓
block g green interesting
▓ ▓
▓▓▓
▓▓▓
link G g green
epsilon ε g green
=

View File

@ -0,0 +1,28 @@
player p height 98
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓
block w white interesting
▓▓▓▓▓▓▓
▓ ▓
▓ p ▓
▓G ▓
▓ ▓
▓g 1 ▓
▓▓▓▓▓▓▓
block g green interesting
▓ ▓
▓▓▓
link G g green
block 1 blue boring
epsilon ε g green
=

View File

@ -0,0 +1,31 @@
player p height 98
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓
block w white interesting
▓▓▓▓▓▓▓
▓▓▓ Gg▓
▓ F▓
▓ 1 ▓
▓ ▓▓
▓p ▓▓
▓▓▓▓▓▓▓
block g green interesting
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓
▓▓▓▓▓
▓▓ ▓▓
link G g green
link F g green
block 1 blue boring
epsilon ε g green
=
▓▓
▓ ▓▓
-▓

View File

@ -0,0 +1,32 @@
player p
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓
block w white interesting
▓▓▓▓▓▓▓
▓ ▓
▓ 1 2 ▓
▓ p ▓
▓ G ▓
▓ g ▓
▓▓▓▓▓▓▓
block g green interesting
▓▓ ▓▓
▓▓ ▓▓
▓▓ ▓▓
▓▓▓▓▓
▓▓▓▓▓
link G g green
block 1 blue boring
block 2 blue boring
epsilon ε g green
=

View File

@ -0,0 +1,32 @@
player p height 98
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓
block w white interesting
▓▓▓▓▓▓▓
▓ ▓
▓ 1 2 ▓
▓ p ▓
▓ g ▓
▓ G ▓
▓▓▓▓▓▓▓
block g green interesting
▓▓ ▓▓
▓▓ ▓▓
▓▓ ▓▓
▓▓▓▓▓
▓▓▓▓▓
link G g green
block 1 blue boring
block 2 blue boring
epsilon ε g green
=

View File

@ -1,4 +1,4 @@
player p
player p height 98
block w white interesting
▓▓▓▓▓▓▓
▓ p ▓

View File

@ -0,0 +1,26 @@
player p height 98
block w white interesting
▓▓▓▓▓▓▓
▓- ▓ ▓▓
▓=p ▓▓
▓ ▓
▓ ▓ε▓▓
▓g ▓ ▓▓
▓▓▓▓▓▓▓
link G g green
block g green interesting
▓▓▓
▓▓G
▓▓▓
epsilon ε g green
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓

View File

@ -0,0 +1,26 @@
player p height 81
block w white interesting
▓▓▓▓▓▓▓▓▓
▓g ▓▓▓
▓ = ▓▓
▓G p ▓▓
▓ - ▓
▓ ▓▓
▓▓ ε ▓▓
▓▓▓▓▓▓ ▓▓
▓▓▓▓▓▓▓▓▓
link G g green
block g green interesting
epsilon ε g green
▓ ▓
▓ ▓
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓

View File

@ -0,0 +1,29 @@
player p
block p magenta boring
▓▓▓▓▓
▓ ▓ ▓
▓▓▓▓▓
▓▓▓▓▓
▓▓▓▓▓
block g green interesting
▓▓▓
▓ ε▓▓
▓▓▓
p
▓ --- ▓
g=G
link G g green
link F g green
epsilon ε g green
▓ F
▓▓▓▓▓▓
▓▓

View File

@ -11,7 +11,7 @@ block t white boring
▓▓▓▓▓▓▓▓▓
block w white interesting
▓▓▓▓▓▓▓▓▓
▓1 2▓▓=▓
▓1 2 ▓▓=▓
▓ ▓▓ε▓
▓4 3▓▓▓▓
▓ ▓ ▓
@ -32,15 +32,9 @@ block r red interesting
link a r red
link b r red
epsilon ε r red
block 1 blue boring
block 2 blue boring