-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProbabilities.hs
122 lines (89 loc) · 3.93 KB
/
Probabilities.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---- Poker Analyser Probability Related Functions
--
-- Author:
-- Dr-Lord
--
-- Version:
-- 0.2 - 30-31/03/2015
--
-- Description:
-- Poker analysing shell.
-- This package contains all the functions related to probability
-- calculations.
--
-- Sections:
-- 0 - Imports
-- 1 - Mathematical Functions
-- 2 - Probability -> Hand Functions
-- 3 - Hand Specific Probability Functions
-- 4 - Quality Related Functions
--
---- 0 - IMPORTS ---------------------------------------------------------------
module Probabilities where
import DataTypes
import HandRankings
---- 2 - PROBABILITY -> HAND FUNCTIONS -----------------------------------------
-- Return the hand the player actually has
-- bestHand :: [Card] -> Hand
-- bestHand cs = probsToHand scs . snd $ foldr addCard noProbs scs
-- where scs = sort cs
-- Assumes Probabilities are sorted by descending HandType
-- and that at least one has a 100% chance
probsToHand :: [Card] -> [Prob] -> Hand
probsToHand scs prs = Hand hT scs
where hT = pKind . head . dropWhile ((/= 1) . chance) $ prs
---- 3 - HAND SPECIFIC PROBABILITY FUNCTIONS -----------------------------------
-- Change the existing probabilities on existing list of cards by taking a
-- new card into consideration
-- addCard :: Card -> [Prob] -> [Prob]
-- addCard c (scs, [rF, sF, fK, fH, fl, st, tK, tP, oP, hC]) =
-- (c:scs, [rF', sF', fK', fH', fl', st', tK', tP', oP', hC'])
-- where (rF', sF', fl') = flushesProbs (rF, sF, fl) scs c
-- (fK', fH', tK', tP', oP') = nOfAKindProbs (fK, fH, tz, tP, oP) scs c
-- st' = straightProb st scs c
-- hC' = highCardProb hC scs c
--aimingFor :: [Prob] -> Prob
-- Perhaps this should just be bestChance
-- Returns Probabilities of RoyalFlush, StraightFlush and Flush
-- flushesProbs :: (Prob,Prob,Prob) -> [Card] -> Card -> (Prob,Prob,Prob)
-- flushesProbs (rF, sF, fl) scs c = (rF', sF', fl')
-- where rF' =
-- sF' =
-- fl' = Prob Flush flChance flNeed
--
-- flChance = sum $ map check required
-- where n = 52 - 2*(nPlayers - 1) - (length scs + 1)
-- check x
-- | x > left = 0
-- | otherwise = (1/) . choose n x
-- ---- NEED TO CARRY AROUND OR, IN GENERAL, KNOW WHAT SUIT IS BEING CONSIDERED.
-- ---- ALSO, NEED TO TAKE INTO ACCOUNT THE CONDITIONAL (A|B) PROBABILITY
-- ---- OF EXTRACTING THE NEEDED NUMBER OF CARDS OF THE SPECIFIC SUITS GIVEN
-- ---- THAT left CARDS WILL BE/HAVE BEEN EXTRACTED. (THE choose RIGHT
-- ---- BEFORE THESE COMMENTS SHOULD BE SUCH A CONDITIONAL ONE).
--
-- -- Cards left to extract in Texas Hold'em (one card is 'c')
-- left = 6 - length scs
-- ---- WRONG: NOT CONSIDERING DISCARDED CARDS, DIFFERENT AT EACH TURN.
--
-- -- Number of required cards of the same suits
-- required = map (5-) . map length $ suitDescGroups scs
-- Returns Probabilities of FourOfAKind, FullHouse, ThreeOfAKind, TwoPair and OnePair
-- nOfAKindProbs :: (Prob,Prob,Prob,Prob,Prob) -> [Card] -> Card -> (Prob,Prob,Prob,Prob,Prob)
-- nOfAKindProbs (fK, fH, tz, tP, oP) scs c = (fK', fH', tK', tP', oP')
-- where fK' =
-- fH' =
-- tK' =
-- tP' =
-- oP' =
-- Returns the Probability of a Straight
-- straightProb :: Prob -> [Card] -> Card -> Prob
-- straightProb st scs c =
-- Returns the Probability of a HighCard
-- highCardProb :: Prob -> [Card] -> Card -> Prob
-- highCardProb hC scs c = Prob HighCard 1 []
---- 4 - QUALITY RELATED FUNCTIONS ---------------------------------------------
type Qual = Int
-- Returns the Quality of a HighCard
highCardQual :: Hand -> Qual
highCardQual h = fromEnum . head . cards $ h