From a3256d3ffbd05ca56a87b36402827144d1ce4906 Mon Sep 17 00:00:00 2001
From: Neil Smith <neil.git@njae.me.uk>
Date: Thu, 24 Dec 2020 11:54:14 +0000
Subject: [PATCH] Cleaning up the loops

---
 advent15/src/advent15loop.hs | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/advent15/src/advent15loop.hs b/advent15/src/advent15loop.hs
index 7d2d258..f023cf9 100644
--- a/advent15/src/advent15loop.hs
+++ b/advent15/src/advent15loop.hs
@@ -25,6 +25,11 @@ runGame seed roundsNeeded =
        gameLoop roundsNeeded round word history
        readSTRef word
 
+gameLoop targetRound round word history =
+    do gameStep round word history 
+         `untilM_` ((== targetRound) <$> readSTRef round)
+       return ()
+
 -- gameLoop targetRound round word history =
 --     do ( gameStep round word history 
 --          `untilM_` (do r <- readSTRef round
@@ -44,11 +49,16 @@ runGame seed roundsNeeded =
 --                (gameStep round word history ) 
 --        return ()
 
-gameLoop targetRound round word history =
-    do whileM_ (do r <- readSTRef round
-                   return $ r /= targetRound )
-               $ gameStep round word history
-       return ()
+-- gameLoop targetRound round word history =
+--     do whileM_ (do r <- readSTRef round
+--                    return $ r /= targetRound )
+--                $ gameStep round word history
+--        return ()
+
+-- gameLoop targetRound round word history =
+--     do whileM_ ((/= targetRound) <$> readSTRef round)
+--                $ gameStep round word history
+--        return ()
 
 seedGame seed historySize = 
   do round <- newSTRef $ length seed
-- 
2.43.0