-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDia.hs
71 lines (56 loc) · 1.77 KB
/
Dia.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
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
module Dia where
import Data.Array
import Data.Char
import Data.Maybe
import Diagrams.Prelude
import Diagrams.Backend.Cairo.CmdLine
import Game
import Types
import Utils
data FieldD a = FieldD
(Colour a) -- field color
(Maybe (PieceD a)) -- piece description (if any)
Bool -- is from field?
Bool -- is to field?
data PieceD a = PieceD
(Colour a) -- piece color
(Colour a) -- player color
SumoD -- sumo description
data SumoD = SumoD -- TBD
f2f :: (Ord a, Floating a) => [Move] -> (Coord, Field) -> FieldD a
f2f lastMoves (fieldCoord, Field {..}) =
let (isFrom, isTo) =
case lastMoves of
[] -> (False, False)
Move from to : _ -> (from == fieldCoord, to == fieldCoord)
in FieldD (c2c fColor) (fmap p2p fPiece) isFrom isTo
p2p :: (Ord a, Floating a) => Piece -> PieceD a
p2p Piece {..} = PieceD (c2c pColor) (c2c pPlayer) SumoD
roundDefs :: (Floating a, Ord a) => Round -> [[FieldD a]]
roundDefs Round{..}
= map (reverse . map (f2f rMoves))
. groupIn 8
. assocs
$ rBoard
roundDiag = hcat . map (vcat . map fieldDiag) . roundDefs
fieldDiag (FieldD color piece isFrom isTo) =
maybe mempty pieceDiag piece
<>
roundedRect 1 1 0.1 # lw (if isSpecial then 0.06 else 0.02)
# fc color
# if isSpecial then lc red else id
where isSpecial = isFrom || isTo
pieceDiag (PieceD piece player _) =
circle 0.35 # lw 0.1
# fc piece
# lc player
c2c c
= fromMaybe (error $ "Unrecognized color: " ++ show c)
. readColourName
. map toLower
. show
$ c