-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.hs
71 lines (63 loc) · 1.96 KB
/
Player.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
module Player (
Player(..),
Color(..),
Control(..),
getColor,
getControl,
getPosition,
getCards,
move
) where
import Board
import Position
import Cards
import Tile
data Color = Yellow | Red | Blue | Green deriving (Show)
data Control = Human | AI deriving (Show)
data Player = Player Color Control Position Cards deriving (Show)
getColor :: Player -> Color
getColor (Player color _ _ _) = color
getControl :: Player -> Control
getControl (Player _ control _ _) = control
getPosition :: Player -> Position
getPosition (Player _ _ pos _) = pos
getCards :: Player -> Cards
getCards (Player _ _ _ cards) = cards
move :: [Char] -> Board -> Player -> Maybe Player
move dir (Board tiles) (Player col cont pos cards)
| dir == "left" =
let newX = (xPosition pos) - 1
in
if newX < 0
then Nothing
else
if (hasConnection dir (tiles !! (yPosition pos) !! (xPosition pos))) && (hasConnection "right" (tiles !! (yPosition pos) !! newX))
then Just $ Player col cont (Position newX $ yPosition pos) cards
else Nothing
| dir == "right" =
let newX = (xPosition (pos)) + 1
in
if newX > 6
then Nothing
else
if (hasConnection dir (tiles !! (yPosition pos) !! (xPosition pos))) && (hasConnection "left" (tiles !! (yPosition pos) !! newX))
then Just $ Player col cont (Position newX $ yPosition pos) cards
else Nothing
| dir == "up" =
let newY = (yPosition (pos)) - 1
in
if newY < 0
then Nothing
else
if (hasConnection dir (tiles !! (yPosition pos) !! (xPosition pos))) && (hasConnection "down" (tiles !! newY !! (xPosition pos)))
then Just $ Player col cont (Position (xPosition pos) newY) cards
else Nothing
| dir == "down" =
let newY = (yPosition (pos)) + 1
in
if newY > 6
then Nothing
else
if (hasConnection dir (tiles !! (yPosition pos) !! (xPosition pos))) && (hasConnection "up" (tiles !! newY !! (xPosition pos)))
then Just $ Player col cont (Position (xPosition pos) newY) cards
else Nothing