-
Notifications
You must be signed in to change notification settings - Fork 1
/
testGUIEnv.hs
64 lines (56 loc) · 1.71 KB
/
testGUIEnv.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import Graphics.UI.WX
import ChessBoard
import System.IO as S
import Data.ByteString as B
import Data.Matrix
import CXM
import Status
import Utils
main = do
varC <- varCreate initChessBoard
cmxObj <- testOfLoad
case cmxObj of
Nothing -> varUpdate varC (id)
Just c -> do
--varC <- varCreate initChessBoard
varUpdate varC (\old -> loadChessBoard c)
varUpdate varC (switchLocation 1 1)
newC <- varGet varC
--isRight <- fmap checkMosaic (varGet varC)
case checkMosaic newC of
True -> return (True)
False -> return (False)
--------------Test of hint----------
testOfHint = do
varC <- varCreate initChessBoard
let ioVar = initProgress varC
hint ioVar
initProgress varVar = do
cmxObj <- loadFromFile "u.cxm"
case cmxObj of
Nothing -> varUpdate varVar (id)
Just c-> do
varUpdate varVar (\_ -> loadChessBoard c)
---------------Test of load-----------------
testOfLoad = do
inh <- S.openBinaryFile "u.cxm" ReadMode
instr <- B.hGetContents inh
hClose inh
case parse parseCMX instr of
Right c -> return (Just c)
Left err -> do
S.putStrLn err
return (Nothing)
--------------Test of export-----------------
testOfExport :: IO ()
testOfExport = do
varC <- varCreate initChessBoard
initProgress varC
cb <- varGet varC
--Here cb is a pure complete ChessBoard
--if cb came from user data you can:
--use varGet to convert Var ChessBoard to IO ChessBoard
--use <- to take out ChessVBoard from IO
--use expandChessBoard to rebuild the header
--Then you can write it to file like following:
((exportToFile "new.cxm") . saveChessBoard) cb