From 238edbb3475461e1b8e51d5819e12ab535261c17 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sun, 15 Dec 2019 11:02:40 +0100 Subject: Print just the output by default in day 13 --- 2019/13.hs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to '2019/13.hs') 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 -- cgit v1.2.3-70-g09d2