-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayer.py
More file actions
29 lines (24 loc) · 852 Bytes
/
player.py
File metadata and controls
29 lines (24 loc) · 852 Bytes
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
from random import uniform
class Player:
def __init__(self, probability):
self.probability = probability
self.count_blue = 0
self.count_red = 0
self.score = 0
self.average = 0
def get_choice(self):
return int(uniform(0, 1) > self.probability)
def reinforcement(self, color, value):
if color:
self.count_blue += value
else:
self.count_red += value
self.probability = self.count_red / (self.count_red + self.count_blue)
def punishment(self, color, value):
if color:
self.count_blue -= value
else:
self.count_red -= value
self.count_blue = max(self.count_blue, 0)
self.count_red = max(self.count_red, 0)
self.probability = self.count_red / (self.count_red + self.count_blue)