-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.py
More file actions
131 lines (110 loc) · 3.29 KB
/
test.py
File metadata and controls
131 lines (110 loc) · 3.29 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
from gameState import GameState
game=GameState()
def handToString(hand):
s=""
for c in hand:
s+=c.getName()+" "
return s
def printHands():
print('P hand: ', handToString(game.playerHand))
print('O hand: ', handToString(game.opponentHand))
def printMiddleFrame():
if len(game.discardPile)>0:
print('top discard card: ', game.discardPile[-1].getName())
else:
print('top discard card: EMPTY')
def labelToString(label):
pieces=label.split("_")
owner=pieces[0]
pieces=pieces[1:]
kind=pieces[0]
ans=owner+": "
if kind=="Run":
ans+=kind+" "+pieces[1]+" of "+pieces[2]
if kind=="3Kind":
ans+=kind + " of "+pieces[1]
return ans
def printMeld():
meld=game.meld
print('MELD: ')
if len(meld)>0:
meldItems=meld.getItems()
for i,j in meldItems:
print(labelToString(i))
else:
print('EMPTY')
def printState():
printHands()
printMiddleFrame()
printMeld()
####below is for player movement
def turnDraw()->bool:
choice=int(input('Draw from deck: enter 1\nDraw from discard: enter 2\n'))
if choice==1:
game.deckDeal()
return True
if choice==2:
if len(game.discardPile)>0:
game.discardDeal()
return True
else:
return False
return False
def turnMiddle()->bool:
choice =int( input('to output game state press 1\nto sort hand press 2\nto select cards to meld press 3\n to view meld options press 4\nto discard press 5\n'))
#output game state: 1
if choice==1:
printState()
return False
# sort hand : 2
elif choice == 2:
game.sortHand()
return False
# select cards to meld: 3
elif choice==3:
return False############################################## Card now has an isSelected attribute
# view runs and 3kinds : 4
elif choice==4:
runs=game.checkForRun(game.playerHand)
for h in runs:
print("run: ",handToString(h))
kinds=game.checkFor3kind(game.playerHand)
for h in kinds:
print('3kind: ', handToString(h))
return False
# go to discard phase: 5
elif choice == 5:
return True
else:
print('invalid choice, pick again')
return False
def turnEnd():
handDict={}
for i in range(len(game.playerHand)):
handDict[i]=game.playerHand[i-1].getName()
keys=handDict.keys()
cards=handDict.values()
for i, c in handDict.items():
print('i: ', i, '\t\tcardname: ', c)
choice =int( input('please enter the index of the card you would like to discard'))
if isinstance(choice, int) and choice>0 and choice <= len(game.playerHand) :
game.discardCard(handDict[choice].getName())
return True
else:
print('invalid input')
return False
def playerMove():
didPlayerDraw=turnDraw()
while(not didPlayerDraw):
print('invalid choice, pick again.')
didPlayerDraw=turnDraw()
didPlayerFinish=turnMiddle()
while(not didPlayerFinish):
didPlayerFinish=turnMiddle()
end=turnEnd()
didDiscard=turnEnd()
while( not didDiscard):
didDiscard=turnEnd()
print('\n\nNow beginning AI turn')
#game has now officially started
playerMove()