summaryrefslogtreecommitdiff
path: root/2019
diff options
context:
space:
mode:
Diffstat (limited to '2019')
-rw-r--r--2019/13.hs28
1 files changed, 18 insertions, 10 deletions
diff --git a/2019/13.hs b/2019/13.hs
index ca4444b..1f16a2c 100644
--- a/2019/13.hs
+++ b/2019/13.hs
@@ -2,6 +2,7 @@
module Main where
import Control.Concurrent
+import Control.Monad
import Data.List
import qualified Data.Map.Strict as Map
import Data.Maybe
@@ -11,6 +12,10 @@ import Input
import IntCode
+showGame :: Bool
+showGame = False
+
+
blockBy :: Show a => Int -> [a] -> [[a]]
blockBy _ [] = []
blockBy n l = case splitAt n l of
@@ -68,20 +73,23 @@ main = do
Map.empty (blockBy 3 output)
in length (filter (== 2) (Map.elems bd))
- putStr "\x1B[H\x1B[2J"
+ when showGame $ putStr "\x1B[H\x1B[2J"
let program' = 2 : tail program
loop ai mcont output = do
let ai1 = foldl' (\ai' [a,b,c] -> processOutput (a, b, c) ai') ai (blockBy 3 output)
- -- putStr "\x1B[1;1H\x1B[2J"
- -- putStr (unlines (printMap (aiScreen ai1)))
- flip mapM_ (blockBy 3 output) $ \[x,y,v] ->
- if x /= -1
- then putStr ("\x1B[" ++ show (y + 1) ++ ";" ++ show (x + 1) ++ "H" ++ [".#+=O" !! fromIntegral v])
- else return ()
- putStrLn ("\x1B[24;1H" ++ show (aiScore ai1))
- hFlush stdout
- threadDelay 2000
+
+ when showGame $ do
+ -- putStr "\x1B[1;1H\x1B[2J"
+ -- putStr (unlines (printMap (aiScreen ai1)))
+ flip mapM_ (blockBy 3 output) $ \[x,y,v] ->
+ if x /= -1
+ then putStr ("\x1B[" ++ show (y + 1) ++ ";" ++ show (x + 1) ++ "H" ++ [".#+=O" !! fromIntegral v])
+ else return ()
+ putStrLn ("\x1B[24;1H" ++ show (aiScore ai1))
+ hFlush stdout
+ threadDelay 2000
+
case mcont of
Just cont -> case runContinue cont [provideInput ai1] of
Left (cont', out) -> loop ai1 (Just cont') out