Day 15: Part 2 is solvable
Only manually, but who cares, this is a fun enough game to play and doesn’t take very long
This commit is contained in:
parent
58509b8d56
commit
dedbad960e
|
@ -25,8 +25,8 @@ main = do
|
|||
program <- readIntcode <$> readFile "input"
|
||||
mode <- queryMode
|
||||
let tm = defaultTM Nothing program
|
||||
let run x = runGameloop $ pure (tm {state = AwaitInput}, M.empty, V2 0 20, mode)
|
||||
(_, buf, _, _) <- run 0
|
||||
let run x = runGameloop $ pure (tm {state = AwaitInput}, M.empty, V2 0 20, 0, mode)
|
||||
(_, buf, _, _, _) <- run 0
|
||||
putStrLn "Done."
|
||||
|
||||
queryMode :: IO Bool
|
||||
|
@ -39,10 +39,10 @@ queryMode = do
|
|||
queryMode
|
||||
|
||||
runGameloop ::
|
||||
IO (TuringMachine, ScreenBuffer, V2 Int, Bool)
|
||||
-> IO (TuringMachine, ScreenBuffer, V2 Int, Bool)
|
||||
IO (TuringMachine, ScreenBuffer, V2 Int, Integer, Bool)
|
||||
-> IO (TuringMachine, ScreenBuffer, V2 Int, Integer, Bool)
|
||||
runGameloop io = do
|
||||
(tm, buf, oldPos, mode) <- io
|
||||
(tm, buf, oldPos, maxStep, mode) <- io
|
||||
case state tm of
|
||||
AwaitInput -> do
|
||||
nextCommand <-
|
||||
|
@ -61,15 +61,19 @@ runGameloop io = do
|
|||
let newPos = case tmNewOut of
|
||||
0 -> oldPos
|
||||
_ -> newPosTry
|
||||
print tmNewOut
|
||||
let bufNew = if tmNewOut == 0 then M.insert newPosTry 0 buf else buf
|
||||
let bufNew2 = if newPos /= oldPos then updatePath bufNew oldPos newPos else bufNew
|
||||
let bufNew3 = if tmNewOut == 2 then M.insert newPos 2 bufNew2 else bufNew2
|
||||
if tmNewOut == 2 then print $ countSteps bufNew2 else return ()
|
||||
print mode
|
||||
let newMode = if tmNewOut == 2 then True else mode
|
||||
let bufNew3 = if tmNewOut == 2 then M.filter (/=1) bufNew2 else bufNew2
|
||||
let newMaxStep = max maxStep tmNewOut
|
||||
putStrLn $ drawBoard (M.insert newPos 3 bufNew3)
|
||||
print $ countSteps bufNew2
|
||||
print newMaxStep
|
||||
runGameloop $
|
||||
pure (tmNew {input = Just nextCommand, output = []}, bufNew3, newPos, mode)
|
||||
_ -> pure (tm, buf, oldPos, mode)
|
||||
pure (tmNew {input = Just nextCommand, output = []}, bufNew3, newPos, newMaxStep, newMode)
|
||||
_ -> pure (tm, buf, oldPos, maxStep, mode)
|
||||
|
||||
updatePath :: ScreenBuffer -> V2 Int -> V2 Int -> ScreenBuffer
|
||||
updatePath buf oldPos newPos = if M.member newPos buf then M.delete oldPos buf else M.insert newPos 1 buf
|
||||
|
|
Loading…
Reference in New Issue
Block a user