-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInteractive.hs
102 lines (72 loc) · 2.02 KB
/
Interactive.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import System.IO
import Control.Monad.State
import Bloxorz
import Levels
import Search
import Control.Concurrent
import qualified System.Process as SP
{-
Setați workingOs la una dintre valorile
Windows, Linux, în funcție de sistemul
de operare pe care lucrați.
-}
workingOs :: Os
workingOs = Windows
data Os = Windows | Linux
deriving (Show, Eq)
{-
Primește ca parametru nivelul pe care să-l joace.
În timpul execuției, introduceți direcția urmată
de enter.
-}
play :: Level -> IO Level
play = execStateT init_cli
init_cli = do
lift cls
lift $ hSetEcho stdin False
x <- get
lift $ putStr (show x)
lift printInstructions
loop_play
lift $ hSetEcho stdin True
lift cls
loop_play = do
x <- get
lift $ hSetEcho stdin False
ch <- lift $ getLine
lift cls
case ch of
"w" -> put (move North x)
"s" -> put (move South x)
"a" -> put (move West x)
"d" -> put (move East x)
"q" -> return()
_ -> put x
newX <- get
lift $ putStr (show newX)
lift printInstructions
if ch /= "q" && (continueGame newX) then loop_play else return()
{-
Primește ca parametru nivelul pe care să-l rezolve
și un Bool care va desemna dacă folosește sau nu euristica .
-}
visualize :: Level -> Bool -> IO [Level]
visualize level useHeuristic = execStateT loop_visualize
$ level :(map snd (solve level useHeuristic))
loop_visualize = do
x <- get
put (tail x)
lift cls
lift $ putStr (show (head x))
lift $ threadDelay 500000
if length x == 1 then return () else loop_visualize
cls = do
case workingOs of
Linux -> SP.system "clear"
Windows -> SP.system "cls"
printInstructions = do
putStr "Use w to move North\n\
\Use s to move South\n\
\Use a to move West\n\
\Use d to move East\n\
\Use q to exit...\n"