-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtarot_class.py
More file actions
156 lines (135 loc) · 4.2 KB
/
Copy pathtarot_class.py
File metadata and controls
156 lines (135 loc) · 4.2 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
import queue
from random import*
class Carte:
def __init__(self,numero,types):
self.numero=numero
self.types=types
def __str__(self):
return str(chr(self.numero+65)+self.types)
def __eq__(self, o: object) -> bool:
if isinstance(o,Carte):
return self.numero == o.numero and self.types == o.types
return False
def convertstrcarte(s):
l1=s[0]
num=ord(l1)-65
return Carte(num,s[1:])
class Tas:
def __init__(self, cartes= []):
self.cartes=cartes
def toList(self):
"""From liste de cartes to affichage"""
a=[]
for el in self.cartes:
a.append(str(el))
return a
def addCartestr(self, carte):
return self.cartes.append(convertstrcarte(carte))
def removeCartestr(self, carte):
for el in self.cartes :
if carte==str(el) :
return self.cartes.remove(el)
print("yp nn effectif")
def filtre(self,f):
T = Tas()
for i in range(len(self.cartes)):
el = self.cartes[i]
if f(el,i):
T.append(el)
return T
def append(self, v):
self.cartes.append(v)
def remove(self,v):
self.cartes.remove(v)
def __str__(self):
s = "["
for el in self.cartes:
s+=str(el)+", "
s=s[:-1]
return s+"]"
def trycarte(s):
print(s)
c= input("donne carte ")
try:
t = convertstrcarte(c)
if not t.types in c:
raise IndexError()
return c
except:
print("ptiote error tkt")
return trycarte(s)
def cartejouablepremiertour(carte,cartesjeu):
for cartejeu in cartesjeu :
if str(cartejeu) == carte:
return True
return False
class Joueur (Tas):
def __init__ (self,ws,s,q:queue.Queue,nom,terminal:bool):
Tas.__init__(self,[])
self.pris=False
self.ws = ws
self.queue = q
self.server = s
self.nom = nom
self.terminal =terminal
def sendmsg(self,msg):
if not self.terminal:
self.server.send_message(self.ws,msg)
def waitmsg(self,op,l=[]):
if not self.terminal:
while self.queue.qsize()>0:
self.queue.get()
return waitq(self.queue)
else:
if op ==2:
tuprendsoupas = input(self.nom+" Voulez-vous prendre ? ")
if tuprendsoupas=="non":
res =-1
else:
res=0
return res
elif op ==3:
r=[]
while len(r)!=6:
jouable=True
while jouable :
print(str(self))
print(r)
cartestr=trycarte("Quel carte voulez-vous retirer ?")
carteaenlever=convertstrcarte(cartestr) #PAS DATOUT NI ROI
# carteaenlever = self.cartes[randint(0,len(self.cartes)-1)]
# cartestr = str(carteaenlever)
if cartejouablepremiertour(cartestr,self.cartes)==True:
if carteaenlever.numero==14 or carteaenlever.types=="at":
print("Vous ne pouvez pas déposer de roi ni d'atout")
else:
r.append(cartestr)
jouable=False
else:
print("pas dans le jeu")
return r
elif op==4:
return l[0]
# return trycarte(self.nom+" Quel carte voulez-vous déposer ? ")
def waitq(q:queue.Queue):
try:
return q.get(timeout=1)
except queue.Empty:
return waitq(q)
class fakePlayer(Tas):
def __init__ (self,nom):
Tas.__init__(self,[])
self.pris=False
self.nom = nom
def sendmsg(self,msg):
return msg
def waitmsg(self):
return
c1=Carte(1,"ca")
#print(c1)
c2=Tas([c1])
#print(c2.toList())
c2.addCartestr("Cca")
#print(c2.toList())
c2.removeCartestr("Bca")
#print(c2.toList())