summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-12-15 11:02:40 +0100
committertomsmeding <tom.smeding@gmail.com>2019-12-15 11:02:40 +0100
commit238edbb3475461e1b8e51d5819e12ab535261c17 (patch)
treead52c5a8c27ccbf7d633e79f7c47074e90fa0520
parent92ed850443d1689d3abd9920a40c16a7940a5498 (diff)
Print just the output by default in day 13
-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