-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpickers.py
More file actions
69 lines (51 loc) · 1.79 KB
/
pickers.py
File metadata and controls
69 lines (51 loc) · 1.79 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
import random
# TODO Fusion KillerPicker and VictimPicker into a generic StatPicker using __getAttrib__
from errors import PickerError
class KillerPicker:
def pick(self, harpies):
if harpies is None:
raise PickerError("Argument error: No harpies received")
threshold = random.random()
random.shuffle(harpies)
remainingPercKiller = sum(c.percKill for c in harpies)
threshold = threshold * remainingPercKiller
pot = harpies[0].percKill
i = 0
while pot < threshold:
i += 1
pot = pot + harpies[i].percKill
killer = harpies[i]
del harpies[i]
return killer
class VictimPicker:
def pick(self, harpies):
if harpies is None:
raise PickerError("Argument error: No harpies received")
threshold = random.random()
random.shuffle(harpies)
remainingPercVictim = sum(c.percVictim for c in harpies)
threshold = threshold * remainingPercVictim
pot = harpies[0].percVictim
i = 0
while pot < threshold:
i += 1
pot += harpies[i].percVictim
victim = harpies[i]
del harpies[i]
return victim
class RandomPicker:
def pick(self, harpies):
if harpies is None:
raise PickerError("Argument error: No harpies received")
random.shuffle(harpies)
harpy = random.choice(harpies)
harpies.remove(harpy)
return harpy
# Deprecated: All pickers MUST remove the picked element from the original list
class RandomPickerNoDelete:
def pick(selfs, harpies):
if harpies is None:
raise PickerError("Argument error: No harpies received")
random.shuffle(harpies)
harpy = random.choice(harpies)
return harpy