randGame :: IOUArray Pos Bool -> Pos -> Int -> Player -> Player -> IO Int randGame walls width pid them us = let otherPlayer 1 = 2 otherPlayer 2 = 1 in do -- implement old move putTraceMsg "a" writeArray walls us False -- check for room, lose if not directions <- movesIO walls width us putTraceMsg "b" if (directions==[]) then return (otherPlayer pid) else do -- make random choice gen <- getStdGen putTraceMsg "c" let (choice,gen) = randomR (0, length directions - 1) gen direction = directions !! choice setStdGen gen putTraceMsg "d" -- check for loss, recurse if didn't occur if (us+direction==them) then do putTraceMsg "f" return 0 else do putTraceMsg "e" randGame walls width (otherPlayer pid) (us+direction) them