a classic game implemented using Happstack+Fay+Acid-State

root / MasterMind / Shared / Core.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
{-# LANGUAGE DeriveDataTypeable, NoImplicitPrelude #-}
module MasterMind.Shared.Core where

-- import AJAX
-- import FFI
import Data.Data
import ResponseType
import Prelude (Maybe, Eq, Read, Show, Int)

data Color
    = Red
    | Orange
    | Yellow
    | Green
    | Blue
    | Purple
      deriving (Eq, Read, Show, Data, Typeable)
-- instance Foreign Color

data Guess = Guess Color Color Color Color
{-
    { peg1 :: Color
    , peg2 :: Color
    , peg3 :: Color
    , peg4 :: Color
    }
-}
    deriving (Read, Show, Data, Typeable)
-- instance Foreign Guess

data ScorePeg
    = Black
    | White
    | None
      deriving (Read, Show, Data, Typeable)
-- instance Foreign ScorePeg

data Score = Score
    { score1 :: ScorePeg
    , score2 :: ScorePeg
    , score3 :: ScorePeg
    , score4 :: ScorePeg
    }
    deriving (Read, Show, Data, Typeable)
-- instance Foreign Score

data Row = Row
    { guess :: Guess
    , score :: Score
    }
    deriving (Read, Show, Data, Typeable)
-- instance Foreign Row

data Board = Board { rows ::  [Row] }
    deriving (Read, Show, Data, Typeable)
-- instance Foreign Board

data GameId = GameId { unGameId :: Int }
    deriving (Eq, Read, Show, Data, Typeable)
-- instance Foreign GameId

data Status
    = Win
    | Lose
    | Undecided
    deriving (Eq, Read, Show, Data, Typeable)
-- instance Foreign Status

data Game = Game
    { correctGuess :: Guess
    , status       :: Status
    , board        :: Board
    }
    deriving (Read, Show, Data, Typeable)
-- instance Foreign Game

data Command
    = SendGuess Guess (ResponseType (Maybe Row))
    | FetchBoard (ResponseType (Maybe Board))
    deriving (Read, Show, Data, Typeable)
-- instance Foreign Command