-
Notifications
You must be signed in to change notification settings - Fork 0
/
personInputPlayer.py
124 lines (111 loc) · 4.22 KB
/
personInputPlayer.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
import math
import random
values = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
class PlayerInputPlayer(object):
# this person relies on player input so that a person can play against the bots
def __init__(self, name):
self.name = str(name)
self.startingHand = []
self.valHand = []
self.cardDict = {
2: 0,
3: 0,
4: 0,
5: 0,
6: 0,
7: 0,
8: 0,
9: 0,
10: 0,
11: 0,
12: 0,
13: 0,
14: 0
}
self.totalCards = 0
def resetPlayer(self):
self.startingHand = []
self.valHand = []
self.cardDict = {2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0, 14: 0}
self.totalCards = 0
def sortHand(self):
for card in self.startingHand:
self.valHand.append(card.value)
self.valHand.sort()
# makes dictionary for how many of each card they have
for card in self.valHand:
self.totalCards += 1
for typeOfCard in self.cardDict:
if card == typeOfCard:
self.cardDict[typeOfCard] += 1
# print(self.cardDict)
# Draw n number of cards from a given deck
def draw(self, deck, num=1):
for i in range(num):
self.startingHand.append(deck.draw())
def showValHand(self):
return self.valHand
def showHand(self):
return self.startingHand
def play(self, cardsOnTop):
print("Others hand sizes: ", cardsOnTop[2])
print("Your hand: ", self.cardDict)
card = input("What value card do you (" + self.name + ") want to play? ('pass' or 'out')")
if card == 'out' or card == 'pass':
return [card]
else:
card = int(card)
if card == 2:
self.cardDict[2] -= 1
return [2, 1]
if self.cardDict[3] > 0:
three = input("Did you use a three? (y/n)")
if three == 'y':
amountOfThree = int(input("How many threes did you use?"))
self.cardDict[3] -= amountOfThree
self.cardDict[card] -= (cardsOnTop[1] - amountOfThree)
return [card, cardsOnTop[1], "Threes played:", amountOfThree]
# if it hasn't returned by now they are just playing normally
self.cardDict[card] -= cardsOnTop[1]
return [card, cardsOnTop[1]]
def start(self):
print(self.cardDict)
card = input("You (" + self.name + ") are starting, what value card do you want to play? (or 'out')")
if card == 'out':
return [card]
else:
card = int(card)
if card == 2:
self.cardDict[2] -= 1
return [2, 1]
amount = int(input("How many of that card do you want to play? (including threes)"))
if self.cardDict[3] > 0:
three = input("Did you use a three? (y/n)")
if three == 'y':
amountOfThree = int(input("How many threes did you use?"))
self.cardDict[3] -= amountOfThree
self.cardDict[card] -= (amount - amountOfThree)
return [card, amount, "Threes played:", amountOfThree]
# if it hasn't returned by now they are just playing normally
self.cardDict[card] -= amount
return [card, amount]
def giveLowestCard(self):
print(self.cardDict)
card = int(input("You (" + self.name + ") are giving any card away. What card?"))
self.cardDict[card] -= 1
return card
def giveHighestCard(self):
if self.cardDict[2] > 0:
self.cardDict[2] -= 1
print("You (" + self.name + ") have given away a 2")
return 2
if self.cardDict[3] > 0:
self.cardDict[3] -= 1
print("You (" + self.name + ") have given away a 3")
return 3
# cant loop through dict reversed so i made a list of the cards at the top of this
for card in reversed(values):
if self.cardDict[card] > 0:
self.cardDict[card] -= 1
print("You (" + self.name + ") have given away a " + str(card))
return card