-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTypes.hs
106 lines (91 loc) · 3.02 KB
/
Types.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
103
104
105
106
{-# LANGUAGE TemplateHaskell, GADTs #-}
module Types where
import qualified Rank2
import qualified Rank2.TH
import Data.Tree(Forest)
import Reactive.Banana
import Reactive.Banana.Frameworks
import Data.Array.IArray
import Data.AppSettings
import Data.Maybe
import Text.Printf
import Base
import Node hiding (position)
-- per-game constants, as seen by the event-handling function
data GameParams = GameParams
{names :: Array Colour String
,ratings :: Array Colour (Maybe Int)
,isUser :: Array Colour Bool
,timeControl :: TimeControl
,rated :: Bool
}
emptyGameParams :: GameParams
emptyGameParams = GameParams (colourArray (repeat ""))
(colourArray (repeat Nothing))
(colourArray (repeat False))
(fromJust (parseTimeControl "1d/30d/100/0/10m/0"))
False
---------------------------------------------------------------
data Request = RequestStart | RequestMove GenMove | RequestResign Colour
data Update = UpdateStart
| UpdateMove (GenMove, Maybe Int)
| UpdateResult (Colour, Reason)
| UpdateClock (Colour, Int)
| UpdateUsed {playerUsed :: Maybe (Colour, Int), gameUsed :: Maybe Int, timeDiff :: Maybe Int}
-- | UpdateUsed (Colour, Int)
-- | UpdateGameUsed Int
deriving Show
data GameState = GameState
{started :: Bool
,position :: Position
,result :: Maybe (Colour, Reason)
} deriving Show
newGameState = GameState{started = False, position = newPosition, result = Nothing}
updateGameState gs UpdateStart = gs{started = True}
updateGameState gs (UpdateMove (m,_)) = either (error . printf "Illegal move from server (%s)")
(\p -> gs{position = p})
$ playGenMove (position gs) m
updateGameState gs (UpdateResult x) = gs{result = Just x}
updateGameState gs _ = gs
----------------------------------------------------------------
data NewGame = forall a. Eq a => NewGame
{params :: GameParams
,initialTree :: Forest SomeNode
,request :: Either (Request -> IO ()) (Request -> IO a, MomentIO (Event a))
,updates :: MomentIO (Behavior GameState, Event Update)
,cleanup :: IO ()
}
data Events f = Events
{newGameE :: f NewGame
,leftPress :: f (Square, (Double, Double))
,rightPress :: f Square
,release :: f Square
,motion :: f Square
,flipE :: f ()
,tick :: f ()
,blindMode :: f (Bool, Bool)
,setupIconsE :: [f ()]
,treePress :: f (Double, Double)
,sendE :: f ()
,resignE :: f ()
,sharpE :: f ()
,planE :: f ()
,clearE :: f ()
,prevE :: f ()
,nextE :: f ()
,startE :: f ()
,endE :: f ()
,currentE :: f ()
,deleteNodeE :: f ()
,deleteLineE :: f ()
,deleteAllE :: f ()
,prevBranchE :: f ()
,nextBranchE :: f ()
,deleteFromHereE :: f ()
,confE :: f Conf
,toggleSharpE :: f ()
,copyMovelistE :: f ()
}
Rank2.TH.deriveFunctor ''Events
Rank2.TH.deriveFoldable ''Events
Rank2.TH.deriveTraversable ''Events