-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDatatypes.hs
56 lines (47 loc) · 2.2 KB
/
Datatypes.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
module Datatypes where
import Data.Vector
import Data.List
import Data.Char
data Player = Human | IA deriving (Eq)
type PlayerCouple = (Player, Player)
data PieceType = Pawn | King | Queen | Rook | Bishop | Horse deriving (Show, Eq)
data Color = Black | White deriving (Eq, Show)
type PieceInfo = (PieceType, Color)
type Coords = (Int, Int)
type Move = (Coords, Coords)
data Square = Empty | Piece PieceInfo deriving (Eq)
instance Show Square where
show Empty = "."
show (Piece (pieceType, White)) = [Data.List.head (show pieceType)]
show (Piece (pieceType, Black)) = [toLower $ Data.List.head (show pieceType)]
type Board = Vector (Vector Square)
type GameState = (Board, Color)
instance Read Square where
readsPrec d ('k': therest) = [(Piece (King, Black), therest)]
readsPrec d ('q': therest) = [(Piece (Queen, Black), therest)]
readsPrec d ('r': therest) = [(Piece (Rook, Black), therest)]
readsPrec d ('b': therest) = [(Piece (Bishop, Black), therest)]
readsPrec d ('h': therest) = [(Piece (Horse, Black), therest)]
readsPrec d ('p': therest) = [(Piece (Pawn, Black), therest)]
readsPrec d ('K': therest) = [(Piece (King, White), therest)]
readsPrec d ('Q': therest) = [(Piece (Queen, White), therest)]
readsPrec d ('R': therest) = [(Piece (Rook, White), therest)]
readsPrec d ('B': therest) = [(Piece (Bishop, White), therest)]
readsPrec d ('H': therest) = [(Piece (Horse, White), therest)]
readsPrec d ('P': therest) = [(Piece (Pawn, White), therest)]
readsPrec d ('.': therest) = [(Empty, therest)]
readsPrec d _ = []
squareToAscii :: Square -> String
squareToAscii Empty = "."
squareToAscii (Piece (King, Black)) = "♚"
squareToAscii (Piece (Queen, Black)) = "♛"
squareToAscii (Piece (Rook, Black)) = "♜"
squareToAscii (Piece (Bishop, Black)) = "♝"
squareToAscii (Piece (Horse, Black)) = "♞"
squareToAscii (Piece (Pawn, Black)) = "♟"
squareToAscii (Piece (King, White)) = "♔"
squareToAscii (Piece (Queen, White)) = "♕"
squareToAscii (Piece (Rook, White)) = "♖"
squareToAscii (Piece (Bishop, White)) = "♗"
squareToAscii (Piece (Horse, White)) = "♘"
squareToAscii (Piece (Pawn, White)) = "♙"