From b65af7e65e51a14b505bf3ae1b855dee1e9cd797 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 13 Dec 2019 13:23:38 +0100 Subject: See the gaaaaame --- 2019/13.hs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/2019/13.hs b/2019/13.hs index 29fb9b9..ca4444b 100644 --- a/2019/13.hs +++ b/2019/13.hs @@ -1,9 +1,11 @@ {-# LANGUAGE MultiWayIf #-} module Main where +import Control.Concurrent import Data.List import qualified Data.Map.Strict as Map import Data.Maybe +import System.IO import Input import IntCode @@ -66,11 +68,20 @@ main = do Map.empty (blockBy 3 output) in length (filter (== 2) (Map.elems bd)) + 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[H\x1B[2J" - putStr (unlines (printMap (aiScreen ai1))) + -- 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