\r
lexicon_file = "lexicon.txt"\r
\r
+// Is a Char a member of a String\r
+isMemberString :: String Char -> Bool\r
+isMemberString "" c = False\r
+isMemberString s c = s.[0] == c || isMemberString (s % (1,size s - 1)) c\r
+\r
// From the slides\r
skip_nl :: String -> String\r
skip_nl str = if (size str > 0 && str.[size str-1] == '\n') (str%(0,size str-2)) str\r
# (seed,env) = getNewRandomSeed env\r
| otherwise = (Just (skip_nl ((shuffle (fromJust ss) seed)!!0)), env)\r
\r
-// word, guesses, stdio -> (win, new guesses, stdio)\r
-round :: String [Char] *File -> (Bool, [Char], *File)\r
-round w g io\r
+// word, guesses, mistakes left, stdio -> (win, new guesses, stdio)\r
+play :: String [Char] Int *File -> (Bool, [Char], *File)\r
+play w g n io\r
# io = io <<< stripUnknown w g <<< '\n'\r
| stripUnknown w g == w = (True, g, io)\r
-# io = io <<< "Guess: "\r
+# io = io <<< "Guess (" <<< toString n <<< "): "\r
# (ok,g`,io) = freadc io\r
# (_,io) = freadline io // to read until the next \n\r
| not ok = abort "Couldn't get guessed letter"\r
-| otherwise = round w [g`:g] io\r
+| isMemberString w g` = play w [g`:g] n io\r
+| n == 0 = (False, [g`:g], io)\r
+| otherwise = play w [g`:g] (n-1) io\r
\r
Start :: *World -> *World\r
Start world\r
| word == Nothing = abort "Couldn't get random word"\r
# word = fromJust word\r
# (io,world) = stdio world\r
-# (win,g,io) = round word [] io\r
-# io = if win (io <<< "You win!\n") io\r
+# (win,g,io) = play word [] 5 io\r
+# io = if win (io <<< "You win!\n") (io <<< "You lose!\n")\r
# (ok,world) = fclose io world\r
| not ok = abort "Couldn't close stdio"\r
| otherwise = world\r