-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprobability.py
127 lines (117 loc) · 5.03 KB
/
probability.py
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
121
122
123
124
125
126
127
from Setup_deal import *
import winner
import ties_wins
import winners_circle
#probability of winning with your cards without seeing other card's opponents
def probability_preflop_hidden(round1, num_player, print_txt):
#deals out the flop, turn and river
user_wins = 0
round1.deal_flop()
round1.deal_turn()
round1.deal_turn()
#see who the winner is based on first deal out
list = winners_circle.winning_players(round1.player, round1.table_cards, num_player, print_txt)
if len(list)==1 and list[0]==1:
#accumulate the wins
user_wins = user_wins+1
#proceed to play 10000 different rounds with your current card
for i in range(10000):
roundx = Poker(num_player)
roundx.randomize_others(round1.player[1])
roundx.deal_flop()
roundx.deal_turn()
roundx.deal_turn()
list = winners_circle.winning_players(roundx.player, roundx.table_cards, num_player, print_txt)
#if user is in the list and is the only one in the list, user has won this round
if len(list)==1 and list[0]==1:
user_wins = user_wins+1
#find the percentage and truncate
percentage = user_wins/10001
percentage = percentage*100
percentage = float(f'{percentage:.4f}')
return percentage
#finds probability of winning given that we are at preflop and cards are revealed
def probability_preflop_revealed(round1, num_player, print_txt):
#accumulated wins from user
user_wins = 0
#see who the winner is based on first deal out
for i in range(10000):
#randomize the board
roundx = Poker(num_player)
for i in round1.player:
roundx.add_hand(round1.player[i],i)
roundx.randomize_entire_board(5)
#check who the winner is
list = winners_circle.winning_players(roundx.player, roundx.table_cards, num_player, print_txt)
#if user is in the list and is the only one in the list, user has won this round
if len(list)==1 and list[0]==1:
user_wins = user_wins+1
#calculate the percentage
percentage = user_wins/10000
percentage = percentage*100
percentage = float(f'{percentage:.4f}')
return percentage
#finds the probability of winning given a card has been dealt and players' cards are revealed
def probability_postflop_revealed(round1, num_player, print_txt, indicator):
#accumulated wins from user
user_wins = 0
#see who the winner is based on first deal out
for i in range(10000):
#randomize the board
roundx = Poker(num_player)
for i in round1.player:
roundx.add_hand(round1.player[i],i)
for i in range(5-indicator):
roundx.add_card_board(round1.table_cards[i])
roundx.randomize_entire_board(indicator)
#check who the winner is
list = winners_circle.winning_players(roundx.player, roundx.table_cards, num_player, print_txt)
#if user is in the list and is the only one in the list, user has won this round
if len(list)==1 and list[0]==1:
user_wins = user_wins+1
#clear the last #(indicator) cards on board
#calculate the percentage
percentage = user_wins/10000
percentage = percentage*100
percentage = float(f'{percentage:.4f}')
return percentage
#finds the probability of winning if a card was dealt and cards are hidden
def probability_postflop_hidden(round1, num_player, print_txt, indicator):
randomize = 5 - indicator
#accumulated wins from user
user_wins = 0
for i in range(10000):
#create new poker object
roundx = Poker(num_player)
#append the flop into board because the flop should be the same every iteration
for i in range(indicator):
roundx.add_card_board(round1.table_cards[i])
#randomize other players' card except user's
roundx.randomize_others(round1.player[1])
#randomize the the next two cards
roundx.randomize_entire_board(randomize)
#print(roundx.player)
#find the winners
list = winners_circle.winning_players(roundx.player, roundx.table_cards, num_player, print_txt)
#if user is the only one in the list, then user wins
if len(list)==1 and list[0]==1:
user_wins = user_wins+1
percentage = user_wins/10000
percentage = percentage*100
percentage = float(f'{percentage:.4f}')
return percentage
#finds the probabiltiy given that all opponents' cards are hidden and there are 5 table cards
def proability_allcards_hidden(round1, num_player, print_txt):
user_wins = 0
for i in range(10000):
roundx = Poker(num_player)
for i in range(5):
roundx.add_card_board(round1.table_cards[i])
roundx.randomize_others(round1.player[1])
list = winners_circle.winning_players(roundx.player, roundx.table_cards, num_player, print_txt)
if len(list)==1 and list[0]==1:
user_wins = user_wins+1
percentage = user_wins/10000
percentage = percentage*100
percentage = float(f'{percentage:.4f}')
return percentage