-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.hs
25 lines (20 loc) · 710 Bytes
/
game.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Main where
import Control.Monad (forever)
import Data.Char (digitToInt)
import System.Environment (getArgs)
import Hells.Common
import Hells.Setter
import Hells.Guesser
import qualified Hells.Strategy.Simple as Simple
main :: IO ()
main = do
args <- getArgs
game <- set
case args of
["simple"] -> putStrLn . showResult $ play Simple.guess game 10
_ -> forever $ getLine >>= putStrLn . writeAnswer . answer game . readGuess
readGuess :: String -> Guess
readGuess = Guess . map digitToInt
writeAnswer :: Response -> String
writeAnswer (TryAgain bulls cows) = (show bulls) ++ " bulls and " ++ (show cows) ++ " cows."
writeAnswer Victory = "You win!"