-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.py
87 lines (69 loc) · 2.63 KB
/
worker.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import time, random, namegen
class Worker():
MIN_HAPPY = 0
MAX_HAPPY = 100
PROMOTION_GAIN = 10
NAME_GEN = namegen.NameGen('./name_gen/Languages/elven.txt')
MIN_EFFECT_UP = 0
MAX_EFFECT_UP = 0.5
MIN_EFFECT_ACROSS = 0.25
MAX_EFFECT_ACROSS = 0.75
MIN_EFFECT_DOWN = 0.5
MAX_EFFECT_DOWN = 1
# @TODO
# Add a resistance to effect value
def __init__(self, boss=None, happiness=100, name=False):
if( not name ): name = self.NAME_GEN.gen_word()
self.name = name
self.happiness = happiness
self.boss = boss
self.effect_up = round(random.uniform(self.MIN_EFFECT_UP,
self.MAX_EFFECT_UP),2)
self.effect_down = round(random.uniform(self.MIN_EFFECT_DOWN,
self.MAX_EFFECT_DOWN),2)
self.effect_across = round(random.uniform(self.MIN_EFFECT_ACROSS,
self.MAX_EFFECT_ACROSS),2)
def update(self, happiness):
self.happiness = happiness
self.correct_happiness()
self.happiness = round(self.happiness,1)
def promote(self):
self.level += 1
self.happiness += happiness / Worker.PROMOTION_GAIN
def disposition(self, amount):
self.happiness += amount
self.correct_happiness()
def affect(self, worker):
outlook = self.happiness - worker.happiness
effect = outlook * self.effect_across
worker.update(worker.happiness + effect)
def correct_happiness(self):
if self.happiness > Worker.MAX_HAPPY: self.happiness = Worker.MAX_HAPPY
if self.happiness < Worker.MIN_HAPPY: self.happiness = Worker.MIN_HAPPY
def status(self):
status = self.name + " is " + str(self.happiness) + '% happy ( up=' + str(self.effect_up) + '; down=' + str(self.effect_down) + '; across=' + str(self.effect_across) + ')'
return status
def main():
workers = []
for i in range(10):
workers.append(Worker(None,
random.random(),
random.randint(0,100)))
num_workers = len(workers)
i=0
while True:
happy_total = 0
for worker in workers:
worker.affect(workers[random.randint(0, num_workers-1)])
worker.status()
time.sleep(0.1)
happy_total += worker.happiness
avg_happiness = happy_total / num_workers
print "AVERAGE HAPPINESS =", str(avg_happiness) + "%"
cls()
i += 1
def cls():
#clear the screen
print chr(27) + "[2J"
if __name__ == '__main__':
main()