CHFKQM47XREZBR5LKV6J4G7FYXQD3SA5XGDAY7P4JF6IBCMUGG3QC F3QBAH24YMFWMCA3KJBBUWQTCVTCZW7ZWMSCNWJVQVSLK7BG7TGQC RTM5VGIPTRMJMKLJER4543HXDRMGUZ7TI5VJBOV4ZFGUCILNQ62QC 7QP2V7ZBVZ7SKQ3SYV6NYA7V77G3Y7GF5V6EPIXLIYFSMFRWR4VAC 6QAAR2VPKVD3II6SKKLQBHRYOFX4NHA6HGJMBMFRPQCVE5OLKWJQC NQEZG66FQWQQOOYXN2GK7MHIQH25QBBNKE37GGDJBCHCSKWJZABQC O7B34AE2RCSSUKPDKL6VRLOAGH3OYXD6VAI6C6KHZMA7RWUMN2MQC K7KUOYE2VONTDGZ6BIAGA3F7RYQEBNTY3LQOYQM4FH3MOUTLBL6AC newtype Team = Team { n :: Word , color :: Color }data Place = None | Some Placenewtype Dois = Dois Team Pieceinstance Atom Dois wherevoid = Nonemass a| None <- a = False| otherwise = Truemove a| Robot {} <- a , Move dir : _ <- ops a = Just dir| Box {} <- a = push a| otherwise = Nothingdata Mode = Dumb | Full
f :: Cell State Unitf s ns u| Robot { ops = [] } <- u , Just dir <- push = u { ops = [Move dir] } -- push| me u = me'| Robot {} <- u = u { ops = drop 1 $ ops u }| Box { push = Nothing } <- u , Just dir <- push = u { push = Just dir } -- push| Box {} <- u = Box { push = Nothing }| otherwise = uwhere
up :: Stack -> Maybe (Piece,Stack)up s| Just i <- V.findIndex isJust s , Just p <- showing s = Just (p , s // [(i , Nothing)])| otherwise = Nothing
me' :: Unit| Just 'h' <- fst $ input s = u { ops = [Move H] }| Just 'j' <- fst $ input s = u { ops = [Move N] }| Just 'k' <- fst $ input s = u { ops = [Move I] }| Just 'l' <- fst $ input s = u { ops = [Move L] }| otherwise = u { ops = [] }
down :: Piece -> Stack -> Maybe Stackdown p s| (n,j) <- V.break isJust s, Just p > showing j, l <- V.length n, l > 0= Just $ s // [(pred l , Just p)]| otherwise = Nothingshowing :: Stack -> Maybe Pieceshowing s| Just p <- V.find isJust s = p| otherwise = Nothinginstance Atom Stack wherevoid = V.generate 3 $ const Nothingmass = const Truemove = const Nothing
| KeyPress 'q' <- e = Left ()| KeyPress 'p' <- e = Right (s { play = True } , v)| KeyPress 'P' <- e = Right (s { play = False } , v)| KeyPress 'c' <- e = Right (s { mode = Dumb } , v)| KeyPress 'C' <- e = Right (s { mode = Full } , v)| KeyPress 'H' <- e = Right (s { center = shift v 1 H $ center s } , v)| KeyPress 'J' <- e = Right (s { center = shift v 1 N $ center s } , v)| KeyPress 'K' <- e = Right (s { center = shift v 1 I $ center s } , v)| KeyPress 'L' <- e = Right (s { center = shift v 1 L $ center s } , 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)where-- prevent repeat before tickinput' :: Char -> (Maybe Char,Queue Char)input' k-- | Just (q,_) <- dequeue $ snd $ input s , k == q = input s| otherwise = enqueue k <$> input sz :: State| Just (c,q) <- dequeue $ snd $ input s = s { input = (Just c , q) }| otherwise = s { input = (Nothing , snd $ input s) }
| Tick <- e = Right (s { frame = succ $ frame s } , v)| KeyPress 'H' <- e = Right (s { center = shift v 1 H $ center s } , v)| KeyPress 'J' <- e = Right (s { center = shift v 1 N $ center s } , v)| KeyPress 'K' <- e = Right (s { center = shift v 1 I $ center s } , v)| KeyPress 'L' <- e = Right (s { center = shift v 1 L $ center s } , v)| KeyPress 'h' <- e = Right (s { focus = shift v 1 H $ focus s } , v)| KeyPress 'j' <- e = Right (s { focus = shift v 1 N $ focus s } , v)| KeyPress 'k' <- e = Right (s { focus = shift v 1 I $ focus s } , v)| KeyPress 'l' <- e = Right (s { focus = shift v 1 L $ focus s } , v)| KeyPress '\ESC' <- e = Right (s { hand = Nothing} , v)-- up| KeyPress ' ' <- e, Nothing <- hand s -- empty hand, Just p <- showing $ get v $ focus s , team p == turn s -- top is team= Right (s { hand = Just $ focus s } , v)-- cancel| KeyPress ' ' <- e, Just pι <- hand s , focus s == pι= Right (s { hand = Nothing } , v)-- down| KeyPress ' ' <- e, Just pι <- hand s, fι <- focus s, orig <- get v pι, dest <- get v fι, Just (p,orig') <- up orig, Just dest' <- down p dest= Right (s { hand = Nothing , turn = mod (succ $ turn s) (players s) } , sets [(pι , orig') , (fι , dest')] v )
s' :: State-- | Just 'x' <- k = z { }| otherwise = zwhere
| KeyPress k <- e , elem k $ take 3 ['1','2','3'], Just stack <- down (Piece (turn s) (pred $ digitToInt k)) (get v $ focus s)= Right (s { hand = Nothing , turn = mod (succ $ turn s) (players s) } , set stack (focus s) v )
where(c,q) = input skey :: Planekey = word (maybe id (:) c $ toList q) # color Black Vividinfo :: Plane| Just n <- V.find (me . atom) $ nodes v = word $ show $ atom n| otherwise = word "no robot found!" # color Red Vividscope :: Maybe (Node Unit) -> Planescope mn| Just n <- mn , ns <- neighbour v (ix n) = foldl (&) (blankPlane 5 3)[ (1,2) % let a = get v $ ns U in cell (grapheme a) # cellDraw a, (1,4) % let a = get v $ ns I in cell (grapheme a) # cellDraw a, (2,1) % let a = get v $ ns H in cell (grapheme a) # cellDraw a, (2,3) % let a = atom n in cell (grapheme a), (2,5) % let a = get v $ ns L in cell (grapheme a) # cellDraw a, (3,2) % let a = get v $ ns N in cell (grapheme a) # cellDraw a, (3,4) % let a = get v $ ns M in cell (grapheme a) # cellDraw a]| otherwise = blankPlane 5 3where
| None <- a , Dumb <- mode s = '.'| None <- a , Full <- mode s = '∙'
colors :: [(Color, ColorIntensity)]colors =[ (Green,Dull), (Blue,Dull), (Red,Dull), (Yellow,Dull), (Cyan,Dull), (Magenta,Dull), (White,Dull), (Green,Vivid), (Blue,Vivid), (Red,Vivid), (Yellow,Vivid), (Cyan,Vivid), (Magenta,Vivid), (White,Vivid)]
| Wall <- a = '#'| Box {} <- a = 'x'| Robot {} <- a = maybe 'o' (const '@') $ move acellStyle :: Unit -> ATGP.Cell -> ATGP.CellcellStyle a| Dumb <- mode s , me a = ATGP.colorCell White Dull| Dumb <- mode s , not (mass a) = ATGP.colorCell Black Vivid| Dumb <- mode s , Robot {} <- a , "t0" <- name a = ATGP.colorCell Blue Dull| Dumb <- mode s , Robot {} <- a , "t1" <- name a = ATGP.colorCell Magenta Dull| Dumb <- mode s , Robot {} <- a , "t2" <- name a = ATGP.colorCell Red Dull| Dumb <- mode s , Robot {} <- a , "d0" <- name a = ATGP.colorCell Yellow Dull| Dumb <- mode s , Robot {} <- a , "d1" <- name a = ATGP.colorCell Green Dull| Dumb <- mode s , Robot {} <- a , 'L':_ <- name a = ATGP.colorCell Cyan Dull| Dumb <- mode s , Robot {} <- a , "r0" <- name a = ATGP.colorCell White Vivid| Dumb <- mode s , Robot {} <- a , "r1" <- name a = ATGP.colorCell Black Vivid| Dumb <- mode s , Robot {} <- a , "m0" <- name a = ATGP.colorCell Green Vivid| Dumb <- mode s , Robot {} <- a , "m1" <- name a = ATGP.colorCell Green Vivid| Dumb <- mode s , Robot {} <- a , "p0" <- name a = ATGP.colorCell White Dull| Dumb <- mode s , Robot {} <- a , "Tp" <- name a = ATGP.colorCell White Dull| Dumb <- mode s , Robot {} <- a , "T0" <- name a = ATGP.colorCell Blue Dull| Dumb <- mode s , Robot {} <- a , "T1" <- name a = ATGP.colorCell Magenta Dull| Dumb <- mode s , Robot {} <- a , "T2" <- name a = ATGP.colorCell Red Dull| Dumb <- mode s = ATGP.colorCell White Vivid| Full <- mode s , me a = ATGP.rgbColorCell $ sRGB24 0x21 0xb2 0x8e -- #21b28e| Full <- mode s , not (mass a) = ATGP.rgbColorCell $ sRGB24 0x66 0x66 0x66 -- #666666| Full <- mode s , Robot {} <- a , "t0" <- name a = ATGP.rgbColorCell $ sRGB24 0x66 0x66 0x99 -- #666699| Full <- mode s , Robot {} <- a , "t1" <- name a = ATGP.rgbColorCell $ sRGB24 0x99 0x66 0x99 -- #996699| Full <- mode s , Robot {} <- a , "t2" <- name a = ATGP.rgbColorCell $ sRGB24 0x99 0x66 0x66 -- #996666| Full <- mode s , Robot {} <- a , "d0" <- name a = ATGP.rgbColorCell $ sRGB24 0x99 0x99 0x66 -- #999966| Full <- mode s , Robot {} <- a , "d1" <- name a = ATGP.rgbColorCell $ sRGB24 0x66 0x99 0x66 -- #669966| Full <- mode s , Robot {} <- a , 'L':_ <- name a = ATGP.rgbColorCell $ sRGB24 0x66 0x99 0x99 -- #669999| Full <- mode s , Robot {} <- a , "r0" <- name a = ATGP.rgbColorCell $ sRGB24 0x99 0x99 0x99 -- #999999| Full <- mode s , Robot {} <- a , "r1" <- name a = ATGP.rgbColorCell $ sRGB24 0x66 0x66 0x66 -- #666666| Full <- mode s , Robot {} <- a , "m0" <- name a = ATGP.rgbColorCell $ sRGB24 0x93 0xe9 0xbe -- #93e9be| Full <- mode s , Robot {} <- a , "m1" <- name a = ATGP.rgbColorCell $ sRGB24 0x93 0xe9 0xbe -- #93e9be| Full <- mode s , Robot {} <- a , "p0" <- name a = ATGP.rgbColorCell $ sRGB24 0xff 0xff 0xff -- #ffffff| Full <- mode s , Robot {} <- a , "Tp" <- name a = ATGP.rgbColorCell $ sRGB24 0xff 0xff 0xff -- #ffffff| Full <- mode s , Robot {} <- a , "T0" <- name a = ATGP.rgbColorCell $ sRGB24 0x66 0x66 0x99 -- #666699| Full <- mode s , Robot {} <- a , "T1" <- name a = ATGP.rgbColorCell $ sRGB24 0x99 0x66 0x99 -- #996699| Full <- mode s , Robot {} <- a , "T2" <- name a = ATGP.rgbColorCell $ sRGB24 0x99 0x66 0x66 -- #996666| Full <- mode s = ATGP.rgbColorCell $ sRGB24 0x99 0x99 0x99 -- #999999
| KeyPress 'h' <- e = Right (s { center = shift v 1 H $ center s } , v)| KeyPress 'j' <- e = Right (s { center = shift v 1 N $ center s } , v)| KeyPress 'k' <- e = Right (s { center = shift v 1 I $ center s } , v)| KeyPress 'l' <- e = Right (s { center = shift v 1 L $ center s } , v)
| KeyPress 'H' <- e = Right (s { center = shift v 1 H $ center s } , v)| KeyPress 'J' <- e = Right (s { center = shift v 1 N $ center s } , v)| KeyPress 'K' <- e = Right (s { center = shift v 1 I $ center s } , v)| KeyPress 'L' <- e = Right (s { center = shift v 1 L $ center s } , v)| KeyPress 'h' <- e = Right (s { focus = shift v 1 H $ focus s } , v)| KeyPress 'j' <- e = Right (s { focus = shift v 1 N $ focus s } , v)| KeyPress 'k' <- e = Right (s { focus = shift v 1 I $ focus s } , v)| KeyPress 'l' <- e = Right (s { focus = shift v 1 L $ focus s } , v)
| KeyPress '-' <- e = Right (s , v { nodes = V.map (\n -> n { atom = prev $ atom n } ) $ nodes v })| KeyPress '+' <- e = Right (s , v { nodes = V.map (\n -> n { atom = next $ atom n } ) $ nodes v })| KeyPress c <- e , isDigit c , n <- digitToInt c , n <= fromEnum (maxBound :: Algo) = Right (s { algo = toEnum n } , v)
| KeyPress '_' <- e = Right (s , v { nodes = V.map (\n -> n { atom = prev $ atom n }) $ nodes v })| KeyPress '+' <- e = Right (s , v { nodes = V.map (\n -> n { atom = next $ atom n }) $ nodes v })| KeyPress '-' <- e = Right (s , upd prev (focus s) v)| KeyPress '=' <- e = Right (s , upd next (focus s) v)| KeyPress c <- e , isDigit c , n <- digitToInt c , n <= fromEnum (maxBound :: Hex) = Right (s , upd (const $ toEnum n) (focus s) v)| KeyPress c <- e , Just n <- elemIndex c ")!@#$%^&*(" , n <= fromEnum (maxBound :: Algo) = Right (s { algo = toEnum n } , v)
write (x,y) = (c , ATGP.paletteColorCell k $ ATGP.creaCell $ " ·~+=≠co" !! fromEnum h)
write (x,y)| n == focus s = (c , ATGP.paletteColorCell k $ ATGP.creaCell $ intToDigit $ fromEnum h)| otherwise = (c , ATGP.paletteColorCell k $ ATGP.creaCell $ " ·~+=≠co" !! fromEnum h)
executable doisimport: optsghc-options: -threaded -rtsoptshs-source-dirs: testmain-is: Dois.hsbuild-depends: base, zero, nove, vector, ansi-terminal-game, colour