-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChessPiece.hs
More file actions
37 lines (29 loc) · 940 Bytes
/
ChessPiece.hs
File metadata and controls
37 lines (29 loc) · 940 Bytes
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
----------------------------------------------------------
-- ChessPiece.hs
--
-- ChessPiece related types
--
-- Author:
-- Ramin Rakhamimov
-- http://raminrakhamimov.tk
-- ramin32@gmail.com
---------------------------------------------------------
module ChessPiece where
data PieceName = Pawn | Knight | Bishop | Rook | Queen | King deriving (Eq, Ord, Show, Enum)
data Color = White | Black deriving (Eq, Ord, Show, Enum)
data ChessPiece = ChessPiece {name :: PieceName, color :: Color} deriving (Eq, Ord)
value :: ChessPiece -> Int
value (ChessPiece name _) = case name of
Pawn -> 1
Knight -> 3
Bishop -> 3
Rook -> 5
Queen -> 9
King -> 200
toggleColor :: Color -> Color
toggleColor White = Black
toggleColor Black = White
instance Show ChessPiece where
show p = ([head $ show $ color p]) ++ initial
where
initial = [if (name p) == Knight then 'N' else (head $ show $ name p)]