RIB2JXPMZHC5XCLGB7Q425PVNJPHMWPJSLMR2GTFLD474WB72ZHAC 6TR3H656MQ3WM3RFWZRHWATU4G5MPRR2CEVM3BAVONWMRMVNVQ4QC K7KUOYE2VONTDGZ6BIAGA3F7RYQEBNTY3LQOYQM4FH3MOUTLBL6AC Y2N6GDITBJID3Q4Z2Y7KEDY46F7R3SU4DRK3ST6ZMA4CNLXWSFDAC ANAAF3LVFG2YCTAWUZKMT75XQN6YNS4CLLZIXSVGKJQRWJVNBMEAC RCDJ2AGX5X4FJ7B7XFLWFVMM6LTVZKTXONYQOYT4JQB7WX5TQPMQC 7QP2V7ZBVZ7SKQ3SYV6NYA7V77G3Y7GF5V6EPIXLIYFSMFRWR4VAC JDI62ZLKN7J4572C7E2WL2HPGAMFU5YEIDOERVGIOBPOOV3DRF5AC $ set Robot { name = "@" , go = mempty } 0: set Robot { name = "t0" , go = Move <$> cycle [U,N,L] } (shift v 1 U 0): set Robot { name = "t1" , go = Move <$> cycle [N,L,U] } (shift v 2 U 0): set Robot { name = "t2" , go = Move <$> cycle [L,U,N] } (shift v 1 U $ shift v 1 H 0): set Robot { name = "i" , go = Move <$> repeat N } (shift v 8 I 0): set Robot { name = "n" , go = Move <$> repeat I } (shift v 2 I 0): set Robot { name = "x" , go = mempty } (shift v 7 M 0): set Robot { name = "L0" , go = Move <$> repeat L } (shift v 17 H 0): set Robot { name = "L1" , go = Move <$> repeat L } (shift v 18 H 0): set Robot { name = "L2" , go = Move <$> repeat L } (shift v 19 H 0)
$ set Robot { name = "@" , ops = mempty } 0: set Robot { name = "t0" , ops = Move <$> cycle [U,N,L] } (shift v 1 U 0): set Robot { name = "t1" , ops = Move <$> cycle [N,L,U] } (shift v 2 U 0): set Robot { name = "t2" , ops = Move <$> cycle [L,U,N] } (shift v 1 U $ shift v 1 H 0): set Robot { name = "d0" , ops = Move <$> repeat N } (shift v 8 I 0): set Robot { name = "d1" , ops = Move <$> repeat I } (shift v 2 I 0): set Robot { name = "L0" , ops = Move <$> repeat L } (shift v 17 H 0): set Robot { name = "L1" , ops = Move <$> repeat L } (shift v 18 H 0): set Robot { name = "L2" , ops = Move <$> repeat L } (shift v 19 H 0): set Robot { name = "r0" , ops = Move <$> cycle [L,H] } (shift v 2 M 0): set Robot { name = "r1" , ops = Move <$> cycle [H,L] } (shift v 2 M $ shift v 1 L 0): set Robot { name = "m0" , ops = Move <$> repeat L } (shift v 5 N $ shift v 1 H 0): set Robot { name = "m2" , ops = Move <$> repeat H } (shift v 5 N $ shift v 1 L 0): set Robot { name = "m1" , ops = Move <$> cycle [I,N] } (shift v 5 N 0)
logic _ _ (KeyPress 'q') = Left ()logic _ (s,v) (KeyPress k) = Right (s { input = input' } , v)
logic g (s,v) e| KeyPress 'q' <- e = Left ()| KeyPress 'p' <- e = Right (s { play = True } , v)| KeyPress 'P' <- e = Right (s { play = False } , v)| KeyPress '.' <- e = Right (s' { play = False } , sim demo s' v)| KeyPress k <- e = Right (s { input = input' k } , v)| play s , Tick <- e = Right (s' , sim demo s' v)| otherwise = Right (s , v)
| Dumb <- mode s , Robot {} <- a , "n" <- name a = color Yellow Dull| Dumb <- mode s , Robot {} <- a , "i" <- name a = color Green Dull| Dumb <- mode s , Robot {} <- a , 'L':_ <- name a = color Cyan Dull
| Dumb <- mode s , Robot {} <- a , "d0" <- name a = color Yellow Dull| Dumb <- mode s , Robot {} <- a , "d1" <- name a = color Green Dull| Dumb <- mode s , Robot {} <- a , 'L':_<- name a = color Cyan Dull| Dumb <- mode s , Robot {} <- a , "r0" <- name a = color White Vivid| Dumb <- mode s , Robot {} <- a , "r1" <- name a = color Black Vivid
| Full <- mode s , Robot {} <- a , "n" <- name a = rgbColor $ sRGB24 0x99 0x99 0x66 -- #999966| Full <- mode s , Robot {} <- a , "i" <- name a = rgbColor $ sRGB24 0x66 0x99 0x66 -- #669966
| Full <- mode s , Robot {} <- a , "d0" <- name a = rgbColor $ sRGB24 0x99 0x99 0x66 -- #999966| Full <- mode s , Robot {} <- a , "d1" <- name a = rgbColor $ sRGB24 0x66 0x99 0x66 -- #669966
import Zero ( (#) )import Zero ( total, floyd )import Data.IntMap as IntMap ( IntMap, (!), mapWithKey, foldrWithKey, mapWithKey, fromDistinctAscList )
import Zero ( total )import Data.IntMap as IntMap ( IntMap, (!), mapWithKey, foldrWithKey, fromDistinctAscList )
ms :: IntMap (Maybe Dir)nodes' :: IntMap a-- fold go with future memo(ms,nodes') = bimap intmap intmap $ foldrWithKey go mempty $ nodes v-- ms: future memory of movement intent
-- fold with future(,) memo nodes' = bimap intmap intmap $ foldrWithKey φ mempty $ nodes v
go :: Int -> a -> ([Maybe Dir], [a]) -> ([Maybe Dir], [a])go i a = bimap id (f (adjacents v i) a :)
φ :: Int -> a -> ([Memo], [a]) -> ([Memo], [a])φ i a = bimap (Memo dest lock free :) (a' :)where-- chain of destinations (memory shared)dest :: [Int]| Just dir <- move a , n <- shift v 1 dir i = n : dest' (memo ! n)| otherwise = []-- want to move herepush :: [Dir]push = filter π totalwhereπ dir| d : _ <- dest' $ memo ! shift v 1 dir i = d == i| otherwise = False-- stops movementlock :: Bool| mass a , null dest = True -- block| not . null $ drop 1 push = True -- stall on dispute| otherwise = False-- find loop at element xloop :: Maybe Intloop = λ mempty (i : dest)whereλ _ [] = Nothingλ s (x:xs)| member x s = Just x| otherwise = λ (insert x s) xs
-- neighbours are free to move infree :: Bool| lock = False -- block| Just n <- loop , i /= n = False -- ρ tail || reciprocal| Just n <- loop , i == n = dest !! 1 /= i && not (any (lock' . (memo !)) $ takeWhile (/= i) dest) -- closed loop| n : _ <- dest = free' $ memo ! n -- linear (loops ruled out, recurse freely)| otherwise = True-- update atoma' :: a| free , [dir] <- push = node v $ shift v 1 dir i| free , null push = void| not free , d : _ <- dest , free' (memo ! d) = void| otherwise = a