Paste: halting problem

Author: sucks
Mode: haskell
Date: Sat, 20 Feb 2010 03:50:04
Plain Text |
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 return 0
            else do
                putTraceMsg "e"
                randGame walls width (otherPlayer pid) (us+direction) them

New Annotation

Summary:
Author:
Mode:
Body: