[Haskell-beginners] nim
John Moore
john.moore54 at gmail.com
Tue Oct 27 08:39:55 EDT 2009
Hi getting there with nimprogram well have it working in different areas.
The last part is where the most trouble is
import Control.Monad
import System.Random
initNim :: IO [Int]
initNim = replicateM 3 $ randomRIO (1,10)--- This get the random numbers
data PileName = A | B | C deriving (Show, Eq, Read)
typeOfMove :: (PileName, Int) -> [Int] -> [Int]
typeOfMove (A, x) xs = zipWith (-) xs [x,0,0]
typeOfMove (B, x) xs = zipWith (-) xs [0,x,0]
typeOfMove (C, x) xs = zipWith (-) xs [0,0,x]
main :: IO ()
main = do
putStrLn "Which pile A, B, or C ?"
x <- readLn
putStrLn "How many stones?"
y <- readLn
let z = typeOfMove (x,y) [9,9,9]-- cannot get the random numbers here
putStrLn . show $ z
*This is where the main problem is I 'm trying to run the game?*
play nim = do
z <- getLine
newAnswer <- return (diff z)
if newAnswer == [0,0,1]||[0,1,0]||[1,0,0]
then putStrn "You win"
else play nim newAnswer
diff z ws hs =[ if z==w then w else h]-- trying to return different list
here
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20091027/7aca1600/attachment.html
More information about the Beginners
mailing list