-
Notifications
You must be signed in to change notification settings - Fork 0
/
poker.py
165 lines (148 loc) · 5.59 KB
/
poker.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import random
class Poker:
def __init__(self):
self.deck = [2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 100] * 4
self.names_cards = {1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 8: "8", 9: "9", 10: "10", 20: "Walet", 30: "Dama", 40: "King", 100: "Ace"}
def take_card(self):
user = []
bot = []
random.shuffle(self.deck)
for i in range(2):
card = self.deck.pop(random.randint(0, len(self.deck)-1))
user.append(card)
print("**"+self.names_cards[user[0]]+"--"+self.names_cards[user[1]]+"**")
for i in range(2):
card_bot = self.deck.pop(random.randint(0, len(self.deck)-1))
bot.append(card_bot)
self.table(user,bot)
def table(self,user,bot):
table_card = []
random.shuffle(self.deck)
for i in range(3):
card = self.deck.pop(random.randint(0, len(self.deck)-1))
table_card.append(card)
print("-----------------------")
print("-------"+self.names_cards[table_card[0]]+"--"+self.names_cards[table_card[1]]+"--"+self.names_cards[table_card[2]]+"-------")
print("-----------------------")
self.choise()
card = self.deck.pop(random.randint(0, len(self.deck)-1))
table_card.append(card)
print("-----------------------")
print("-----"+self.names_cards[table_card[0]]+"--"+self.names_cards[table_card[1]]+"--"+self.names_cards[table_card[2]]+"--"+self.names_cards[table_card[3]]+"-----")
print("-----------------------")
self.choise()
card = self.deck.pop(random.randint(0, len(self.deck)-1))
table_card.append(card)
print("-----------------------")
print("----"+self.names_cards[table_card[0]]+"--"+self.names_cards[table_card[1]]+"--"+self.names_cards[table_card[2]]+"--"+self.names_cards[table_card[3]]+"--"+self.names_cards[table_card[4]]+"----")
print("-----------------------")
self.win_lose(table_card,user,bot)
def choise(self):
print("What will u do?\ncheck(c)/fold(f)")
choise = input()
if choise == "c":
return
else:
self.game()
def win_lose(self, card_table, user, bot):
win_comb = []
win_comb_bot = []
score = 0
bot_score = 0
for i in user:
for j in card_table:
if i==j:
win_comb.append(j)
#print(win_comb)
if len(win_comb)==0:
for i in user:
us = max (i, i+1)
for j in bot:
bs = max(j, j+1)
if us>bs:
print("You have a best card, then bot")
score = 1
bot_score = 0
else:
score = 0
bot_score = 1
print("Bot has a best card, then u")
elif len(win_comb)==1:
print("You have a pair")
score = 1
elif len(win_comb)==2:
if win_comb[0] == win_comb[1]:
print("You have a set!")
score = 3
else:
print("Ypu have 2 pairs")
score = 2
elif len(win_comb)==3:
if win_comb[0] == win_comb[1]== win_comb[2]:
print("You have a kare!!!")
score = 6
else:
print("You have a set and a pair")
score = 4
elif len(win_comb)==4:
if win_comb[1] == win_comb[2]:
print("You have a kare!!!")
score = 6
else:
print("You have 2 sets")
score = 5
for i in bot:
for j in card_table:
if i==j:
win_comb_bot.append(j)
#print(win_comb_bot)
if len(win_comb_bot)==0:
for i in user:
us = max (i, i+1)
for j in bot:
bs = max(j, j+1)
if us>bs:
score = 1
bot_score = 0
else:
score = 0
bot_score = 1
elif len(win_comb_bot)==1:
bot_score = 1
print("Bot have a pair")
elif len(win_comb_bot)==2:
if win_comb_bot[0] == win_comb_bot[1]:
print("Bot have a set!")
bot_score = 3
else:
print("Bot have 2 pairs")
bot_score = 2
elif len(win_comb_bot)==3:
if win_comb_bot[0] == win_comb_bot[1]== win_comb_bot[2]:
bot_score = 6
print("Bot have a kare!!!")
else:
bot_score = 4
print("Bot have a set and a pair")
elif len(win_comb_bot)==4:
if win_comb_bot[1] == win_comb_bot[2]:
bot_score = 6
print("Bot have a kare!!!")
else:
bot_score = 5
print("Bot have 2 sets")
print("You: **"+self.names_cards[user[0]]+"--"+self.names_cards[user[1]]+"**")
print("Bot: **"+self.names_cards[bot[0]]+"--"+self.names_cards[bot[1]]+"**")
if score>bot_score:
print("U win bot")
else:
print("U lose bot")
def game(self):
print("U can play poker with bot, are u ready???\ny/n")
a = input()
if a == "y":
self.take_card()
else:
print("Okey, bye!")
game = Poker()
game.game()