-
Notifications
You must be signed in to change notification settings - Fork 57
/
you and your computer.py
64 lines (55 loc) · 2.2 KB
/
you and your computer.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
def playGame(wordList):
"""
Allow the user to play an arbitrary number of hands.
1) Asks the user to input 'n' or 'r' or 'e'.
* If the user inputs 'e', immediately exit the game.
* If the user inputs anything that's not 'n', 'r', or 'e', keep asking them again.
2) Asks the user to input a 'u' or a 'c'.
* If the user inputs anything that's not 'c' or 'u', keep asking them again.
3) Switch functionality based on the above choices:
* If the user inputted 'n', play a new (random) hand.
* Else, if the user inputted 'r', play the last hand again.
* If the user inputted 'u', let the user play the game
with the selected hand, using playHand.
* If the user inputted 'c', let the computer play the
game with the selected hand, using compPlayHand.
4) After the computer or user has played the hand, repeat from step 1
wordList: list (string)
"""
def displayHand2(hand):
displayed = ''
for letter in hand.keys():
for j in range(hand[letter]):
displayed += letter + ' '
return displayed
hand = False
while True:
ans = raw_input("Enter n to deal a new hand, r to replay the last hand, or e to end game: ")
if ans == "n":
hand = dealHand(HAND_SIZE)
tester1 = True
while tester1:
ans2 = raw_input("Enter u to have yourself play, c to have the computer play: ")
if ans2 == "u":
playHand(hand, wordList, HAND_SIZE)
tester1 = False
elif ans2 == "c":
compPlayHand(hand, wordList, HAND_SIZE)
tester1 = False
else:
print "Invalid command."
elif ans == "r":
if hand:
ans2 = raw_input("Enter u to have yourself play, c to have the computer play: ")
if ans2 == "u":
playHand(hand, wordList, HAND_SIZE)
elif ans2 == "c":
compPlayHand(hand, wordList, HAND_SIZE)
else:
print "Invalid command."
else:
print "You have not played a hand yet. Please play a new hand first!"
elif ans == "e":
break
else:
print "Invalid command."