-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelperIO.hs
More file actions
50 lines (45 loc) · 1.64 KB
/
HelperIO.hs
File metadata and controls
50 lines (45 loc) · 1.64 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module HelperIO where
import qualified System.Console.ANSI as Con
-- Game Rules
printRules :: IO ()
printRules = do
putStrLn "--- MASTERMIND ---"
putStrLn ""
putStrLn "Command Line Arguments:"
putStrLn " -h --help : Prints this Help"
putStrLn " -n N : Sets the code-length to N"
putStrLn " -a {CODE|N} : Starts the AI to solve the Code"
putStrLn ""
putStrLn "RULES: Try guessing the code with as little tries as possible"
putStrLn " The code consists of 4 pegs with one of 6 colors"
putStrLn " Possible colors are: Red, Green, Blue, Yellow, Purple, Orange"
putStrLn " Use their first letter to build your guess"
putStrLn ""
putStrLn " On each try the computer will respond with a pattern to show"
putStrLn " you how many blocks are in the right position, or of the right"
putStrLn " color but at the wrong position"
putStrLn " '+' represents the first, 'o' the latter case"
putStrLn ""
putStrLn "Type 'quit' to give up"
putStrLn ""
putStrLn "GOOD LUCK!"
putStrLn ""
data StartOpts = StartOpts {
showHelp :: Bool,
codeLen :: Int,
aiMode :: Maybe String
}
parseArgs :: [String] -> StartOpts
parseArgs (s:ss)
| s == "-h" = cont {showHelp = True}
| s == "--help" = cont {showHelp = True}
| s == "-n" = cont {codeLen = (read h)}
| s == "--ai" = cont {aiMode = Just h}
| s == "-a" = cont {aiMode = Just h}
| otherwise = cont
where
cont = parseArgs ss
h = case length ss of
0 -> ""
_ -> head ss
parseArgs _ = StartOpts {showHelp = False, codeLen = 4, aiMode = Nothing}