-
Notifications
You must be signed in to change notification settings - Fork 0
/
Defs.hs
82 lines (62 loc) · 2.89 KB
/
Defs.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
module Defs where
import Control.Monad.Reader
import Control.Monad.Writer
import Control.Lens hiding (Fold, folded)
data PlayAction = Fold | Call | Raise Money deriving (Eq, Show, Ord)
data RoundStartAction = Check | Bet Money | Fold_ deriving (Eq, Show, Ord)
data BotStatus = Playing | Folded | AllIn deriving (Eq, Show, Ord)
data Suit = Club | Diamond | Heart | Spade deriving (Eq, Show, Enum, Ord)
data Value = Two | Three | Four | Five | Six | Seven | Eight | Nine | Ten | Jack | Queen | King | Ace deriving (Eq, Show, Enum, Ord)
type Card = (Suit, Value)
data HandEvaluation = HighCard [Value]
| OnePair [Value]
| TwoPair [Value]
| ThreeOfAKind [Value]
| Straight [Value]
| Flush [Value]
| FullHouse [Value]
| FourOfAKind [Value]
| StraightFlush [Value] deriving (Eq, Show, Ord)
data BotSimple = BotSimple {_money :: Int, _botName :: String, _status :: BotStatus} deriving (Eq, Show, Ord)
data PotSimple = PotSimple { _bet :: Int, _botss :: [BotSimple]} deriving (Eq, Show, Ord)
type Deck = [Card]
type Hand = [Card]
type CommunityCards = [Card]
type Money = Int
type PokerAction a = ReaderT BotState IO a
type GamePlay a = WriterT String IO a
data PokerBot = PokerBot { _name :: String, _startAction :: PokerAction RoundStartAction, _playAction :: PokerAction PlayAction, _botStatus :: BotStatus, _currentCall :: Money}
data BotState = BotState {_hole :: Hand, _moneyLeft :: Int, _investedInPot :: Int, _callNeeded :: Int, _potTotal :: [PotSimple], _communityCards :: CommunityCards} -- deriving (Show)
data TexasHoldemPoker = TexasHoldemPoker { _bots :: [(PokerBot, BotState)], _deck :: Deck} deriving (Show)
instance Show PokerBot where
show b = "POKERBOT (status: " ++ (show $ _botStatus b) ++ ", call: " ++ (show $ _currentCall b) ++ ") " ++ _name b
instance Show BotState where
show b = "BOTSTATE investedInPot: " ++ (show $ _investedInPot b) ++ " _moneyLeft: " ++ (show $ _moneyLeft b) ++ " _callNeeded: " ++ (show $ _callNeeded b) ++ " _communityCards: " ++ (show $ _communityCards b)
type CompleteBot = (PokerBot, BotState)
type Pot = (Money, [CompleteBot])
type Pot2 = [(Money, CompleteBot)]
--instance Show Pot where
-- show p = "Pot money: " ++ fst p ++ " bots: " ++ show $ snd p
makeLenses ''PokerBot
makeLenses ''BotState
makeLenses ''TexasHoldemPoker
makeLenses ''PotSimple
makeLenses ''BotSimple
instance Ord PokerBot where
compare x y
| x^.name == y^.name = EQ
| x^.name <= y^.name = LT
| otherwise = GT
instance Ord BotState where
compare x y
| x^.moneyLeft == y^.moneyLeft = EQ
| x^.moneyLeft <= y^.moneyLeft = LT
| otherwise = GT
instance Eq BotState where
(==) x y = x^.moneyLeft == y^.moneyLeft
instance Eq PokerBot where
(==) x y = x^.name == y^.name
class PokerGame a where
initGame :: [PokerBot] -> GamePlay a
round :: a -> GamePlay a
playGame :: a -> GamePlay a