mainLoop :: IO (IORef GState) -> IO ()
mainLoop dp = do
  res <- dp
  gstate <- readIORef res
  if isGameOver (getPlayer 1 (gamecard gstate)) (getPlayer 2 (gamecard gstate))
   then do 
     print (gamecard gstate)
     ref <- readIORef res
     let p1 = getScore (card (getPlayer (cplayer ref) (gamecard ref)))
         p2 = getScore (card (getPlayer (increment (cplayer ref)) (gamecard ref)))
         winner = if p1 > p2 then cplayer ref else increment (cplayer ref)
     putStrLn $ (++ " wins!") $ show $ name (getPlayer winner (gamecard ref))
    else mainLoop $ dartPrompt res
mainLoop :: IO (IORef GState) -> IO ()
mainLoop dp = do
  res <- dp
  gstate <- readIORef res
  if isGameOver (getPlayer 1 (gamecard gstate)) (getPlayer 2 (gamecard gstate))
   then do 
     print (gamecard gstate)
     ref <- readIORef res
     let p1 = getScore (card (getPlayer (cplayer ref) (gamecard ref)))
         p2 = getScore (card (getPlayer (increment (cplayer ref)) (gamecard ref)))
         winner = if p1 > p2 then cplayer ref else increment (cplayer ref)
     putStrLn $ (++ " wins!") $ show $ name (getPlayer winner (gamecard ref))
    else mainLoop $ dartPrompt res
mainLoop dp = do
  res <- dp
  gstate <- readIORef res
  if isGameOver (getPlayer 1 (gamecard gstate)) (getPlayer 2 (gamecard gstate))
   then do 
     print (gamecard gstate)
     ref <- readIORef res
     let p1 = getScore (card (getPlayer (cplayer ref) (gamecard ref)))
         p2 = getScore (card (getPlayer (increment (cplayer ref)) (gamecard ref)))
         winner = if p1 > p2 then cplayer ref else increment (cplayer ref)
     putStrLn $ (++ " wins!") $ show $ name (getPlayer winner (gamecard ref))
    else mainLoop $ dartPrompt res