-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManipulate.py
209 lines (151 loc) · 5.91 KB
/
Manipulate.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
from Game import *
from Util import *
import itertools
import json
totalPlayers = int(input("Players: "))
game = PokerGame(totalPlayers)
game.getDeck().createDeck(False)
def inputCard():
while True:
x = input("Card (Ex - 10S [10 of Spade]): ").upper()
if len(x) == 0 or x in ["NONE", "NULL"]:
return None
shape = Shape.getShapeFromValue(x[-1])
if shape is None or x[:-1] not in POSSIBLE_NUMBERS:
print("Invalid Card!")
continue
card = game.getDeck().getCard(shape, x[0:-1])
if card is None:
print("This card is already being used!")
continue
game.getDeck().DECK.remove(card)
return card
def modifyHand(player):
playerHand = game.getHands().get(player, [])
game.getDeck().DECK.extend(playerHand)
card1 = inputCard()
card2 = inputCard()
game.getHands()[player] = [card1, card2]
def modifyTable():
pr, npr = "", ""
for i in range(5):
pr += ("None" if len(game.TABLE) <= i else str(game.TABLE[i])) + "\t"
npr += str(i + 1) + "\t"
print(f'{pr}\n{npr}')
card = int(input("Card: ")) - 1
if card > len(game.TABLE):
cls()
print("You cannot edit this card!")
modifyTable()
return
for i in range(card):
if game.TABLE[i] == None:
cls()
print("You cannot edit this card!")
modifyTable()
return
if len(game.TABLE) > card:
game.getDeck().DECK.append(game.TABLE[card])
modified = inputCard()
if len(game.TABLE) > card:
game.TABLE[card] = modified
else:
game.TABLE.append(modified)
while True:
cls()
print(f"Total Players: {totalPlayers}\n")
option = int(input("Options:\n1. Player\n2. Table\n3. Calculate\n4. Exit\n5. Experimental\n"))
if option == 5:
TABLE_COMBINATIONS = itertools.combinations(game.deck.DECK, 5)
for comb in TABLE_COMBINATIONS:
game.TABLE.extend(comb[0:-2])
for card in game.TABLE:
game.deck.DECK.remove(card)
WINDICT = {
3: {},
4: {},
5: {}
} # TABLE_CARD: { [HAND]: (win, draw, loose) }
for refer in range(3):
PLAYER_COMBINATION = itertools.combinations(itertools.combinations(game.deck.DECK, 2), totalPlayers)
key = refer + 3
for pcomb in PLAYER_COMBINATION:
for player in range(totalPlayers):
game.HANDS[player] = list(pcomb[player])
game.winner()
for player in range(totalPlayers):
hand = game.HANDS[player]
wins = WINDICT.get(key, {}).get(" ".join(map(str, hand)), {"wins": 0, "draws": 0, "loss": 0})
if player in game.WINNERS:
if len(game.WINNERS) > 1:
wins["draws"] += 1 # Draw
else:
wins["wins"] += 1 # Win
else:
wins["loss"] += 1 # Loose
WINDICT[key][" ".join(map(str, hand))] = wins
if refer == 2: # No need to pop and add for 6th table card
break
game.TABLE.append(comb[key])
game.deck.DECK.remove(comb[key])
with open("data/" + " ".join(map(str, comb[0:-2])), "w") as file:
json.dump(dict, file)
game.deck.createDeck(False)
game.TABLE.clear()
if option == 4:
cls()
print("Exited!")
exit()
elif option == 3:
cls()
print("Calculating all possible wins: ")
print()
COMBINATION = itertools.combinations(itertools.combinations(game.deck.DECK, 2), totalPlayers - 1)
won = 0
draw = 0
totalGames = 0
for comb in COMBINATION:
# distribute the card
for i in range(totalPlayers - 1):
cards = list(comb[i])
game.HANDS[i + 1] = cards
game.winner()
if 0 in game.WINNERS:
if len(game.WINNERS) > 1:
draw += 1
else:
won += 1
totalGames += 1
print(f"Total Games: {totalGames}")
print(f"Total Won: {won}")
print(f"Total Draw: {draw}")
elif option == 2:
while True:
cls()
print("TABLE:", "None, None, None, None, None" if len(game.TABLE) == 0 else ', '.join(map(str, game.TABLE)), sep="\n")
print()
if input("Do you want to modify the table (Y/N)? ").upper() == "Y":
cls()
modifyTable()
else:
break
elif option == 1:
while True:
cls()
game.printAllHands()
player = int(input("\nSelect Player (-1 to Exit): "))
if player >= totalPlayers or player < 0:
if player == -1:
break
print("Invalid Player!")
continue
cls()
HAND = game.getHands()
if player in HAND:
game.printHand(player)
while True:
if input("Do you want to modify this hand (Y/N)? ").upper() == "Y":
modifyHand(player)
break
else:
modifyHand(player)