-
Notifications
You must be signed in to change notification settings - Fork 0
/
baraja.py
70 lines (53 loc) · 1.74 KB
/
baraja.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
import random
_palos = ['o', 'c', 'e', 'b']
_cartas = ['A', '2','3', '4', '5', '6','7', 'S', 'C', 'R']
def baraja():
result = []
for palo in _palos:
for carta in _cartas:
result.append(carta + palo)
return result
def elige_carta(i, longitud):
return random.randint(0, longitud-1)
def mezclar(b):
for i in range(len(b)):
al_azar = elige_carta(i, len(b))
aux = b[i]
b[i] = b[al_azar]
b[al_azar] = aux
return b
class Baraja():
naipes = []
__palos = ['o', 'c', 'e', 'b']
__cartas = ['A', '2','3', '4', '5', '6','7', 'S', 'C', 'R']
def __init__(self):
self.naipes = []
for palo in self.__palos:
for carta in self.__cartas:
self.naipes.append(carta + palo)
def elige_carta(self, i):
return random.randint(0, len(self.naipes)-1)
def mezclar(self):
for i in range(len(self.naipes)):
al_azar = self.elige_carta(i)
aux = self.naipes[i]
self.naipes[i] = self.naipes[al_azar]
self.naipes[al_azar] = aux
def repartir(self, mano, jugadores):
res = []
for j in range(jugadores):
res.append([])
for c in range(mano):
for item in res:
carta = self.naipes.pop(0)
item.append(carta)
return res
def repartirF(self, mano, jugadores):
jugadas = []
for i in range(jugadores):
jugadas.append([])
for j in range(mano):
jugadas[i].append(self.naipes[j*jugadores+i])
cartas = mano * jugadores
self.naipes = self.naipes[cartas:]
return jugadas