Skip to content

Commit 7d74243

Browse files
committed
Turn Card into a sum type
The company stages didn't work well with the Card type, as much information was useless.
1 parent f384891 commit 7d74243

3 files changed

Lines changed: 35 additions & 41 deletions

File tree

Startups/Base.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ data CompanyStage = Project
1515
| Stage2
1616
| Stage3
1717
| Stage4
18-
deriving (Ord,Eq,Enum)
18+
deriving (Ord,Eq,Enum,Show)
1919

2020
data Company = Facebook -- ^ Rhodes
2121
| Twitter -- ^ Alexandria
@@ -27,10 +27,10 @@ data Company = Facebook -- ^ Rhodes
2727
deriving (Eq, Ord, Enum, Show)
2828

2929
data CompanySide = A | B
30-
deriving (Eq, Ord, Enum)
30+
deriving (Eq, Ord, Enum, Show)
3131

3232
data CompanyProfile = CompanyProfile Company CompanySide
33-
deriving (Eq, Ord)
33+
deriving (Eq, Ord, Show)
3434

3535
data Resource = Youthfulness -- ^ Glass
3636
| Vision -- ^ Papyrus

Startups/CardList.hs

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,14 @@ import Startups.Cards
66

77
import qualified Data.Set as S
88
import qualified Data.Text as T
9-
import Data.Monoid
109

1110
getMaxStage :: CompanyProfile -> CompanyStage
1211
getMaxStage (CompanyProfile Facebook B) = Stage2
1312
getMaxStage (CompanyProfile Microsoft B) = Stage4
1413
getMaxStage _ = Stage3
1514

16-
wondercard :: Company -> CompanyStage -> Cost -> [Effect] -> Card
17-
wondercard c s cost eff = Card ("[" <> T.pack (show c) <> "] " <> phase) 0 Age1 CompanyStage cost [] eff
18-
where
19-
phase = case s of
20-
Project -> "project phase"
21-
Stage1 -> "initial funding"
22-
Stage2 -> "grow"
23-
Stage3 -> "world takeover"
24-
Stage4 -> "And with strange aeons even death may die."
25-
2615
getResourceCard :: CompanyProfile -> CompanyStage -> Card
27-
getResourceCard (CompanyProfile c _) Project = wondercard c Project "" [ProvideResource r 1 Shared]
16+
getResourceCard p@(CompanyProfile c _) Project = CompanyCard p Project "" [ProvideResource r 1 Shared]
2817
where r = case c of
2918
Facebook -> Finance
3019
Twitter -> Youthfulness
@@ -33,7 +22,7 @@ getResourceCard (CompanyProfile c _) Project = wondercard c Project "" [ProvideR
3322
Instagram -> Marketing
3423
Amazon -> Adoption
3524
Microsoft -> Operations
36-
getResourceCard (CompanyProfile c A) Stage1 = wondercard c Stage1 cost [AddVictory CompanyVictory 3 HappensOnce]
25+
getResourceCard p@(CompanyProfile c A) Stage1 = CompanyCard p Stage1 cost [AddVictory CompanyVictory 3 HappensOnce]
3726
where
3827
cost = case c of
3928
Facebook -> "MM"
@@ -43,7 +32,7 @@ getResourceCard (CompanyProfile c A) Stage1 = wondercard c Stage1 cost [AddVicto
4332
Instagram -> "MM"
4433
Amazon -> "DD"
4534
Microsoft -> "OO"
46-
getResourceCard (CompanyProfile c A) Stage2 = wondercard c Stage2 cost eff
35+
getResourceCard p@(CompanyProfile c A) Stage2 = CompanyCard p Stage2 cost eff
4736
where
4837
(cost, eff) = case c of
4938
Facebook -> ("DDD" , [Poaching 2])
@@ -53,7 +42,7 @@ getResourceCard (CompanyProfile c A) Stage2 = wondercard c Stage2 cost eff
5342
Instagram -> ("OO" , [Opportunity (S.fromList [Age1 .. Age3])])
5443
Amazon -> ("FFF" , [Recycling])
5544
Microsoft -> ("MMM" , [AddVictory CompanyVictory 5 HappensOnce])
56-
getResourceCard (CompanyProfile c A) Stage3 = wondercard c Stage3 cost [AddVictory CompanyVictory 7 HappensOnce]
45+
getResourceCard p@(CompanyProfile c A) Stage3 = CompanyCard p Stage3 cost [AddVictory CompanyVictory 7 HappensOnce]
5746
where
5847
cost = case c of
5948
Facebook -> "FFFF"
@@ -63,27 +52,27 @@ getResourceCard (CompanyProfile c A) Stage3 = wondercard c Stage3 cost [AddVicto
6352
Instagram -> "FF"
6453
Amazon -> "AA"
6554
Microsoft -> "OOOO"
66-
getResourceCard (CompanyProfile c@Facebook B) s@Stage1 = wondercard c s "OOO" [Poaching 1, AddVictory CompanyVictory 3 HappensOnce, GainFunding 3 HappensOnce]
67-
getResourceCard (CompanyProfile c@Facebook B) s@Stage2 = wondercard c s "FFFF" [Poaching 1, AddVictory CompanyVictory 4 HappensOnce, GainFunding 4 HappensOnce]
68-
getResourceCard (CompanyProfile c@Twitter B) s@Stage1 = wondercard c s "DD" [ResourceChoice baseResources Kept]
69-
getResourceCard (CompanyProfile c@Twitter B) s@Stage2 = wondercard c s "MM" [ResourceChoice advancedResources Kept]
70-
getResourceCard (CompanyProfile c@Twitter B) s@Stage3 = wondercard c s "OOO" [AddVictory CompanyVictory 7 HappensOnce]
71-
getResourceCard (CompanyProfile c@Apple B) s@Stage1 = wondercard c s "OO" [AddVictory CompanyVictory 2 HappensOnce, GainFunding 4 HappensOnce]
72-
getResourceCard (CompanyProfile c@Apple B) s@Stage2 = wondercard c s "MM" [AddVictory CompanyVictory 3 HappensOnce, GainFunding 4 HappensOnce]
73-
getResourceCard (CompanyProfile c@Apple B) s@Stage3 = wondercard c s "YVA" [AddVictory CompanyVictory 5 HappensOnce, GainFunding 4 HappensOnce]
74-
getResourceCard (CompanyProfile c@Google B) s@Stage1 = wondercard c s "DA" [AddVictory CompanyVictory 3 HappensOnce]
75-
getResourceCard (CompanyProfile c@Google B) s@Stage2 = wondercard c s "MMY" [Efficiency]
76-
getResourceCard (CompanyProfile c@Google B) s@Stage3 = wondercard c s "DDDV" [ScientificBreakthrough]
77-
getResourceCard (CompanyProfile c@Instagram B) s@Stage1 = wondercard c s "MM" [CheapExchange baseResources (S.fromList [NLeft, NRight])]
78-
getResourceCard (CompanyProfile c@Instagram B) s@Stage2 = wondercard c s "OO" [AddVictory CompanyVictory 5 HappensOnce]
79-
getResourceCard (CompanyProfile c@Instagram B) s@Stage3 = wondercard c s "FFA" [CopyCommunity]
80-
getResourceCard (CompanyProfile c@Amazon B) s@Stage1 = wondercard c s "FF" [AddVictory CompanyVictory 2 HappensOnce, Recycling]
81-
getResourceCard (CompanyProfile c@Amazon B) s@Stage2 = wondercard c s "DDD" [AddVictory CompanyVictory 1 HappensOnce, Recycling]
82-
getResourceCard (CompanyProfile c@Amazon B) s@Stage3 = wondercard c s "YVA" [Recycling]
83-
getResourceCard (CompanyProfile c@Microsoft B) s@Stage1 = wondercard c s "MM" [AddVictory CompanyVictory 3 HappensOnce]
84-
getResourceCard (CompanyProfile c@Microsoft B) s@Stage2 = wondercard c s "OOO" [AddVictory CompanyVictory 5 HappensOnce]
85-
getResourceCard (CompanyProfile c@Microsoft B) s@Stage3 = wondercard c s "DDD" [AddVictory CompanyVictory 5 HappensOnce]
86-
getResourceCard (CompanyProfile c@Microsoft B) s@Stage4 = wondercard c s "OOOOA"[AddVictory CompanyVictory 7 HappensOnce]
55+
getResourceCard c@(CompanyProfile Facebook B) s@Stage1 = CompanyCard c s "OOO" [Poaching 1, AddVictory CompanyVictory 3 HappensOnce, GainFunding 3 HappensOnce]
56+
getResourceCard c@(CompanyProfile Facebook B) s@Stage2 = CompanyCard c s "FFFF" [Poaching 1, AddVictory CompanyVictory 4 HappensOnce, GainFunding 4 HappensOnce]
57+
getResourceCard c@(CompanyProfile Twitter B) s@Stage1 = CompanyCard c s "DD" [ResourceChoice baseResources Kept]
58+
getResourceCard c@(CompanyProfile Twitter B) s@Stage2 = CompanyCard c s "MM" [ResourceChoice advancedResources Kept]
59+
getResourceCard c@(CompanyProfile Twitter B) s@Stage3 = CompanyCard c s "OOO" [AddVictory CompanyVictory 7 HappensOnce]
60+
getResourceCard c@(CompanyProfile Apple B) s@Stage1 = CompanyCard c s "OO" [AddVictory CompanyVictory 2 HappensOnce, GainFunding 4 HappensOnce]
61+
getResourceCard c@(CompanyProfile Apple B) s@Stage2 = CompanyCard c s "MM" [AddVictory CompanyVictory 3 HappensOnce, GainFunding 4 HappensOnce]
62+
getResourceCard c@(CompanyProfile Apple B) s@Stage3 = CompanyCard c s "YVA" [AddVictory CompanyVictory 5 HappensOnce, GainFunding 4 HappensOnce]
63+
getResourceCard c@(CompanyProfile Google B) s@Stage1 = CompanyCard c s "DA" [AddVictory CompanyVictory 3 HappensOnce]
64+
getResourceCard c@(CompanyProfile Google B) s@Stage2 = CompanyCard c s "MMY" [Efficiency]
65+
getResourceCard c@(CompanyProfile Google B) s@Stage3 = CompanyCard c s "DDDV" [ScientificBreakthrough]
66+
getResourceCard c@(CompanyProfile Instagram B) s@Stage1 = CompanyCard c s "MM" [CheapExchange baseResources (S.fromList [NLeft, NRight])]
67+
getResourceCard c@(CompanyProfile Instagram B) s@Stage2 = CompanyCard c s "OO" [AddVictory CompanyVictory 5 HappensOnce]
68+
getResourceCard c@(CompanyProfile Instagram B) s@Stage3 = CompanyCard c s "FFA" [CopyCommunity]
69+
getResourceCard c@(CompanyProfile Amazon B) s@Stage1 = CompanyCard c s "FF" [AddVictory CompanyVictory 2 HappensOnce, Recycling]
70+
getResourceCard c@(CompanyProfile Amazon B) s@Stage2 = CompanyCard c s "DDD" [AddVictory CompanyVictory 1 HappensOnce, Recycling]
71+
getResourceCard c@(CompanyProfile Amazon B) s@Stage3 = CompanyCard c s "YVA" [Recycling]
72+
getResourceCard c@(CompanyProfile Microsoft B) s@Stage1 = CompanyCard c s "MM" [AddVictory CompanyVictory 3 HappensOnce]
73+
getResourceCard c@(CompanyProfile Microsoft B) s@Stage2 = CompanyCard c s "OOO" [AddVictory CompanyVictory 5 HappensOnce]
74+
getResourceCard c@(CompanyProfile Microsoft B) s@Stage3 = CompanyCard c s "DDD" [AddVictory CompanyVictory 5 HappensOnce]
75+
getResourceCard c@(CompanyProfile Microsoft B) s@Stage4 = CompanyCard c s "OOOOA"[AddVictory CompanyVictory 7 HappensOnce]
8776
getResourceCard _ _ = error "Invalid card"
8877

8978
communities :: [Card]

Startups/Cards.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ data CardType = BaseResource -- ^ The "brown" cards, provide basic re
1919
| Commercial -- ^ The "gold" cards, mainly get you funding
2020
| HeadHunting -- ^ The "red" cards, giving poaching power
2121
| Community -- ^ The "purple" cards, giving victory points according to various conditions
22-
| CompanyStage -- ^ A fake card, representing your company
2322
deriving (Eq, Show, Ord)
2423

2524
data Neighbor = NLeft
@@ -105,7 +104,13 @@ data Card = Card { _cName :: T.Text
105104
, _cCost :: Cost
106105
, _cFree :: [T.Text]
107106
, _cEffect :: [Effect]
108-
} deriving (Ord, Eq, Show)
107+
}
108+
| CompanyCard { _cCompany :: CompanyProfile
109+
, _cStage :: CompanyStage
110+
, _cCost :: Cost
111+
, _cEffect :: [Effect]
112+
}
113+
deriving (Ord,Eq,Show)
109114

110115
type Exchange = M.Map Neighbor (MS.MultiSet Resource)
111116

0 commit comments

Comments
 (0)