-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbet.py
More file actions
59 lines (56 loc) · 2.25 KB
/
bet.py
File metadata and controls
59 lines (56 loc) · 2.25 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
from toolbox import get_total
class Bet:
def __init__(self, _id_proposeur, _sujet : str, _sujet1 : str, _sujet2 : str, _durée : int):
self.id_proposeur = _id_proposeur
self.sujet = _sujet
self.durée = _durée
self.sujet1 = _sujet1
self.sujet2 = _sujet2
self.bet1 = {}
self.bet2 = {}
def parier(self, id_parieur, montant, option, Banque):
if (id_parieur == self.id_proposeur):
return "Vous avez proposé le pari, vous ne pouvez pas bet :'("
if (self.durée <= 0 ):
return "Les jeux sont faits, vous ne pouvez plus bet :'("
if ((id_parieur in self.bet1 and option == 2) or (id_parieur in self.bet2 and option == 1)):
return "Vous ne pouvez pas re-choisir une option apres avoir parié"
if (option == 1):
if (id_parieur in self.bet1):
tmp = self.bet1[id_parieur]
else:
tmp = 0
self.bet1[id_parieur] = tmp + montant
else:
if (id_parieur in self.bet2):
tmp = self.bet2[id_parieur]
else:
tmp = 0
self.bet2[id_parieur] = tmp + montant
Banque[id_parieur] -= montant
return "Le bet à été ajouté"
def fin(self, option_gagnante):
ret = []
if (option_gagnante == 1):
total_looser = get_total(self.bet2)
total_gagant = get_total(self.bet1)
if (total_looser == 0):
for _id in self.bet1:
ret.append((_id, self.bet1[_id]))
else:
for _id in self.bet1:
gain = (self.bet1[_id] * total_looser) // total_gagant
gain += self.bet1[_id]
ret.append((_id, gain))
else:
total_looser = get_total(self.bet1)
total_gagant = get_total(self.bet2)
if (total_looser == 0):
for _id in self.bet2:
ret.append((_id, self.bet2[_id]))
else:
for _id in self.bet2:
gain = (self.bet2[_id] * total_looser) // total_gagant
gain += self.bet1[_id]
ret.append((_id, gain))
return ret