-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.program2
More file actions
175 lines (151 loc) · 5.66 KB
/
main.program2
File metadata and controls
175 lines (151 loc) · 5.66 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
import random
import os
cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
def sum_score(player_hand):
initial_score = 0
for card in player_hand:
initial_score += card
return initial_score
# Reveal the computer's first card to the user.
def first_computer_card(computer_input):
initial_cards = [computer_input[0], "X"]
print(f"The initial cards for computer are: {initial_cards}")
# Function that will check the initial score at the beginning of the game when the user and the computer
# have two initial cards.
def initial_check():
if sum_score(user) == 21:
if sum_score(computer) == 21:
print(f"Your hand: {user}. Computer's hand: {computer}. You lose.\n")
return False
else:
print(f"Your hand: {user}. Computer's hand: {computer}.You win.\n")
return True
elif sum_score(computer) == 21:
print(f"Your hand: {user}. Computer's hand: {computer}.You lose.\n")
return False
else:
input(f"Your score is {sum_score(user)}. Press 'd' if you want to draw a card, if you want to pass type 'p': ")
draw_card(user)
# Draw a card for the player
def draw_card(player):
draw = True
while draw:
print(draw)
check_ace(player)
if sum_score(user) > 21:
print(f"Your hand: {user}. Computer's hand: {computer}. Your final score is {sum_score(user)}, you lose.")
draw = False
# Exit game ---
elif sum_score(user) == 21:
# Now computer will draw cards.
computer_play()
# Another function will compare here if user's score is higher than computer score
checker()
draw = False
print(draw)
else:
next_draw = input(f"Your current score is {sum_score(user)}. Press 'd' to draw again, or 'p' to pass: ")
if next_draw == 'd':
draw = True
else:
print(f"Your hand: {user}. Computer's hand: {computer}. Your final score is {sum_score(user)}.")
# Now computer will draw cards.
computer_play()
# Another function will compare here if user's score is higher than computer score
checker()
draw = False
print(draw)
# Check if cards[0] is an Ace, and it counts as 1 or 11 depending on the score.
def check_ace(player):
new_card = random.choice(cards)
if player == user:
if new_card == cards[0]:
if sum_score(user) <= 10:
new_card = 11
player.append(new_card)
sum_score(player)
else:
new_card = 1
player.append(new_card)
sum_score(player)
else:
player.append(new_card)
sum_score(player)
elif player == computer:
if new_card == cards[0]:
if sum_score(computer) <= 10:
new_card = 11
player.append(new_card)
sum_score(player)
else:
new_card = 1
player.append(new_card)
sum_score(player)
else:
player.append(new_card)
sum_score(player)
# This function will check the user's score and compare it with the computer's.
def checker():
computer_score = sum_score(computer)
user_score = sum_score(user)
if user_score == 21:
if computer_score == 21:
print(f"Your hand: {user}. Computer's hand: {computer}. Computer score: {computer_score}. "
f"Your score: {user_score}. You lose.")
else:
print(f"Your hand: {user}. Computer's hand: {computer}. Computer score: {computer_score}. "
f"Your score: {user_score}. You win.")
elif computer_score == 21:
print(f"Your hand: {user}. Computer's hand: {computer}. Computer score: {computer_score}. "
f"Your score: {user_score}. You lose.")
elif computer_score > user_score:
print(f"Your hand: {user}. Computer's hand: {computer}. Computer score: {computer_score}. "
f"Your score: {user_score}. You lose.")
elif computer_score == user_score:
print(f"Your hand: {user}. Computer's hand: {computer}. Computer score: {computer_score}. "
f"Your score: {user_score}. It's a draw.")
else:
print(f"Your hand: {user}. Computer's hand: {computer}. Computer score: {computer_score}. "
f"Your score: {user_score}. You win.")
return False
# Function that will draw cards until their score goes over 16.
def computer_play():
computer_score = sum_score(computer)
while computer_score < 16:
draw_card(computer)
computer_score = sum_score(computer)
#checker
# Function that asks the user if they would like to play again.
def play_again():
if not checker():
print('Game over. Would you like to play again?')
"""
"""
def drop_card():
return cards[random.randint(0, len(cards) - 1)]
def computerPlay():
while sum_score(valor) < 16:
valor = drop_card()
def showResult():
decide el ganador segun la sircustancias de como acaba la partida
def check_program_main():
if valueU == 21:
if valueC == 21:
ganas banca
else:
ganaste
elif valueC == 21:
ganas banca
else:
while:
pedirte si quieres jugar de nuevo:
input...
if(que has dicho que si)
valueU[2,4,2] = drop_card()
else:
computerPlay()
showResult()
if __name__ == '__main__':
user = [9, 1]
computer = [1, 10, 1]
check_program_main()