-
Notifications
You must be signed in to change notification settings - Fork 0
/
manual.hs
44 lines (37 loc) · 1 KB
/
manual.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Main where
import Control.Applicative ((<$>))
import System.IO (hGetLine, stdin)
import System.Environment
import GameState
fullGameLoop :: Board -> IO ()
fullGameLoop board = do
mMove <- getMoveFromStdin
case mMove of
Just move ->
let newBoard = gameLoop move board in
do
putStrLn $ [ moveToChar move ]
putStrLn $ prettyBoard newBoard
fullGameLoop newBoard
Nothing ->
fullGameLoop board
main :: IO ()
main = do
args <- getArgs
b <- readBoard (head args)
putStrLn $ prettyBoard b
fullGameLoop b
getMoveFromStdin :: IO (Maybe Move)
getMoveFromStdin = do
l <- hGetLine stdin
return (case l of
[] -> Nothing
x:_ -> charToMove x)
readBoard :: String -> IO Board
readBoard file = board <$> readCellLists
where readCellLists = do
fileStr <- readFile file
return (map stringToCells (lines fileStr))
gameLoop :: Move -> Board -> Board
gameLoop ourMove board =
move board ourMove