-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathGame_Club.py
More file actions
285 lines (238 loc) · 10.1 KB
/
Game_Club.py
File metadata and controls
285 lines (238 loc) · 10.1 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
print("\t\t--------Menu--------")
print("1. NQueens Problem\n2. Caesar Cipher\n3. Black Jack")
a = int(input("Enter any one choise you want: "))
if a == 1:
class QueenChessBoard:
def __init__(self, size):
self.size = size
self.columns = []
def get_size(self):
return self.size
def get_queens_count(self):
return len(self.columns)
def place_in_next_row(self, column):
self.columns.append(column)
def remove_in_current_row(self):
return self.columns.pop()
def is_this_column_safe_in_next_row(self, column):
row = len(self.columns)
for queen_column in self.columns:
if column == queen_column:
return False
# check diagonal
for queen_row, queen_column in enumerate(self.columns):
if queen_column - queen_row == column - row:
return False
# check other diagonal
for queen_row, queen_column in enumerate(self.columns):
if ((self.size - queen_column) - queen_row
== (self.size - column) - row):
return False
return True
def display(self):
for row in range(self.size):
for column in range(self.size):
if column == self.columns[row]:
print('Q', end=' ')
else:
print('-', end=' ')
print()
def print_all_solutions_to_n_queen(size):
board = QueenChessBoard(size)
number_of_solutions = print_all_solutions_helper(board)
print('Number of solutions:', number_of_solutions)
def print_all_solutions_helper(board):
size = board.get_size()
# if board is full, display solution
if size == board.get_queens_count():
board.display()
print()
return 1
number_of_solutions = 0
# place queen in next row
for column in range(size):
if board.is_this_column_safe_in_next_row(column):
board.place_in_next_row(column)
number_of_solutions += print_all_solutions_helper(board)
board.remove_in_current_row()
return number_of_solutions
n = int(input('Enter n: '))
print_all_solutions_to_n_queen(n)
elif a == 2:
def getMode():
while True:
mode = input("Do you want to encrypt or decrypt or brute force a message?: ").lower()
if mode in 'encrypt e decrypt d brute b'.split():
return mode
else:
print("Enter either 'encrypt' or 'e' or 'decrypt' or 'd' or 'brute' or 'b': ")
def getMessage():
print("Enter your message: ")
return input()
def getKey():
key = 0
while True:
key = int(input("Enter the key number(1-26): "))
if key >= 1 and key <= 26:
return key
def getTranslatedMessage(mode, message, key):
if mode[0] == 'd':
key = -key
translated = ""
for symbol in message:
if symbol.isalpha():
num = ord(symbol)
num += key
if symbol.isupper():
if num > ord('Z'):
num -= 26
elif num < ord('A'):
num += 26
elif symbol.islower():
if num > ord('z'):
num -= 26
elif num < ord('a'):
num += 26
translated += chr(num)
else:
translated += symbol
return translated
mode = getMode()
message = getMessage()
if mode[0] != 'b':
key = getKey()
print("Your translated text is: ")
if mode[0] != 'b':
print(getTranslatedMessage(mode, message, key))
else:
for key in range (1, 27):
print(key, ")", getTranslatedMessage('decrypt', message, key))
elif a == 3:
import random
from supportSystem import *
# GAMEPLAY!
if __name__ == "__main__":
player_Chips = Chips()
print("Welcome to BlackJack!")
while (True):
print("How many chips would you like to bet? you have now {} ".format(
player_Chips.total))
# if y is int , and you have Enough Chips to Play
y = Error().Error_bet(player_Chips.total)
player = Hand()
dealer = Hand()
card_in_game = Deck(Card().all_card)
# 1 card to dealer
random_choice = random.choices(
card_in_game.cards) # random ...[('3', 'Hearts')]....
card_in_game.Deck_pop(card_in_game.find_idx(
random_choice[0])) # pop obj in card_in_game by idx
dealer.add_card(
random_choice,
card_in_game.cart[random_choice[0][0]]) # add card to player
# 2 card to dealer
random_choice = random.choices(
card_in_game.cards) # random ...[('3', 'Hearts')]....
card_in_game.Deck_pop(card_in_game.find_idx(
random_choice[0])) # pop obj in card_in_game by idx
dealer.add_card(
random_choice,
card_in_game.cart[random_choice[0][0]]) # add card to player
Presentation().dealer_printing(
dealer) # print 2 card in player hand
# 1 card to player
# random ...[('3', 'Hearts')]....
random_choice = random.choices(card_in_game.cards)
card_in_game.Deck_pop(card_in_game.find_idx(
random_choice[0])) # pop obj in card_in_game by idx
player.add_card(
random_choice,
card_in_game.cart[random_choice[0][0]]) # add card to player
# 2 card to player
# random ...[('3', 'Hearts')]....
random_choice = random.choices(card_in_game.cards)
# pop obj in card_in_game by idx
card_in_game.Deck_pop(card_in_game.find_idx(random_choice[0]))
# add card to player
player.add_card(random_choice, card_in_game.cart[random_choice[0][0]])
print("~ Player Hand ~")
print("~~~~~~~~~~~~~~~~")
# print 2 card in player hand
Presentation().Hand_printing(player)
# win , lose or go on
for_loop_2 = player.hand_win()
# player win or not , if not player can take another card
while (True):
if (player.hand_win() == "Win"):
print("player Win")
for_loop_2 = player.hand_win()
player_Chips.add(y)
break
elif (player.hand_win() == "Lose"):
print("player Lose")
for_loop_2 = player.hand_win()
player_Chips.remove(y)
break
else:
print("You want to take another card : yes or no ")
x = Error().is_Error() # need to be yes or no
if x == "yes" or x == 'y':
random_choice = random.choices(
card_in_game.cards) # random ...[('3', 'Hearts')]....
card_in_game.Deck_pop(
card_in_game.find_idx(random_choice[0])
) # pop obj in card_in_game by idx
player.add_card(random_choice, card_in_game.cart[
random_choice[0][0]]) # add card to player
print("~ Player Hand ~")
print("~~~~~~~~~~~~~~~~")
Presentation().Hand_printing(
player) # print 2 card in player hand
else:
print("~ Dealer Hand ~")
print("~~~~~~~~~~~~~~~~")
Presentation().Hand_printing(dealer)
for_loop_2 = player.hand_win()
break
while (for_loop_2 == "Go on"): #if player dont win or lose Dealer move
if (dealer.hand_win() == "Win"):
print("Dealer Win")
player_Chips.remove(y)
break
elif (dealer.hand_win() == "Lose"):
print("Dealer Lose")
player_Chips.add(y)
break
elif (dealer.value < 17): # 17 > dealer , dealer +1 card
random_choice = random.choices(
card_in_game.cards) # random ...[('3', 'Hearts')]....
card_in_game.Deck_pop(card_in_game.find_idx(
random_choice[0])) # pop obj in card_in_game by idx
dealer.add_card(random_choice, card_in_game.cart[
random_choice[0][0]]) # add card to player
print("~ Dealer Hand ~")
print("~~~~~~~~~~~~~~~~")
Presentation().Hand_printing(dealer)
elif (dealer.value >= 17
and dealer.value > player.value): # 17 <= dealer > player
print("Dealer Win")
player_Chips.remove(y)
break
else: # 17 < = dealer < player or dealer == player
print("Player Win")
player_Chips.add(y)
break
if (player_Chips.total == 0):
print("you have 0 Chips !! sorry Game over !! :( ")
break
print("You'll want a new game : yes / no ")
x = Error().is_Error() # need to be yes or no
if x == "no":
print("Game End")
print("you have {} Chips in the End of the Game ".format(
player_Chips.total))
break
else:
print(" ") # \n
print(" New Game ")
print(" ") # \n