Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import System.IO
- import System.Random
- -- scegli una riga a caso dal file
- randomline :: StdGen -> [String] -> String
- randomline g l = l' !! i
- where
- l' = [x | x <- l, not(null(x))]
- i = fst $ randomR (0, length l' - 1) g
- -- controlla se la lettera e` stata indovinata
- ismatch :: (Char, Char) -> Char -> Bool
- ismatch x c = snd x == c && fst x == '_'
- -- calcola nuovo stato
- newstatus :: [(Char, Char)] -> Char -> [(Char, Char)]
- newstatus s c = [if ismatch x c then (snd(x),snd(x)) else x | x <- s]
- -- chiedi input e prova finche` non e` tutto indovinato
- trials :: [(Char, Char)] -> IO ()
- trials status = do
- nc <- getChar
- --let newstatus = [if ismatch c n then (snd(c),snd(c)) else c | c <- status]
- let ns = newstatus status nc
- putStrLn [fst x | x <- ns]
- if all (==True) [fst(x) == snd(x) | x <- ns] then
- return ()
- else
- trials ns
- --------------------------------------------------------
- main = do
- fc <- readFile "pallotron"
- gen <- getStdGen
- let target = randomline gen (lines fc)
- let start = take (length target) (repeat '_')
- putStrLn "Indovina, stronzo!"
- trials $ zip start target
- putStrLn ("Esatto, era proprio " ++ target)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement