-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrincadeira_alocacao.py
66 lines (56 loc) · 2.16 KB
/
brincadeira_alocacao.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
from random import randint
class Aloca:
def __init__(self, voluntarios, leitores, som):
self.voluntarios = voluntarios
self.leitores = leitores
self.som = som
self._idx = [0, 0, 0]
self._max = [len(voluntarios), len(leitores), len(som)]
def __inc_and_get_idx(self, indice):
result = self._idx[indice]
self._idx[indice] += 1
if self._idx[indice] >= self._max[indice]:
self._idx[indice] = 0
return result
def __pega_item(self, ignorar, lista, indice):
idx = self.__inc_and_get_idx(indice)
i = lista[idx]
while i in ignorar:
idx = self.__inc_and_get_idx(indice)
i = lista[idx]
return i
def pega_voluntario(self, ignorar=[]):
yield self.__pega_item(ignorar, self.voluntarios, 0)
def pega_leitor(self, ignorar=[]):
yield self.__pega_item(ignorar, self.leitores, 1)
def pega_som(self, ignorar=[]):
yield self.__pega_item(ignorar, self.som, 2)
def _base_alocacao(self):
ignorar = []
i1 = next(self.pega_voluntario(ignorar))
ignorar.append(i1)
i2 = next(self.pega_voluntario(ignorar))
ignorar.append(i2)
v1 = next(self.pega_voluntario(ignorar))
ignorar.append(v1)
v2 = next(self.pega_voluntario(ignorar))
ignorar.append(v2)
s = next(self.pega_som(ignorar))
ignorar.append(s)
return {
'indicadores': [i1, i2],
'volantes': [v1, v2],
'operador_som': [s],
'leitor': []
}, ignorar
def monta_quinta(self):
return self._base_alocacao()[0]
def monta_domingo(self):
b, ignorar = self._base_alocacao()
l = next(self.pega_leitor(ignorar))
b['leitor'].append(l)
return b
voluntarios = [ 'Alexandre', 'João', 'Natanael', 'Renato', 'Eduardo', 'Leonardo', 'Ronaldo', 'Ferreira', 'Santos', 'Monticelli', 'Claudio', 'Nelson']
leitores = ['Alexandre', 'Leonardo', 'Ronaldo', 'Renato', 'Eduardo', 'Nelson', 'Monticelli']
som = ['Alexandre', 'Leonardo', 'Eduardo', 'Natanael']
alocacao = Aloca(voluntarios, leitores, som)