-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
52 lines (37 loc) · 1022 Bytes
/
player.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
import random
class IPlayer():
""" Interface for the players """
def propose(self, total):
# how much money I want for myself
pass
def respond(self, fraction):
# agree or disagree on the other user proposition
pass
class RandomPlayer:
""" Random UG player
offers:
random
accepts:
random
"""
def propose(self, total):
return random.randrange(1, total-1)
def respond(self, fraction):
return bool(random.getrandbits(1))
class WeightedPlayer:
""" Same as random, but the probability of acceptance
is adjusted for the fraction being proposed
offers:
random
accepts:
random, more likely for better offers
"""
def propose(self, total):
return random.randrange(1, total-1)
def respond(self, fraction):
return random.uniform(0, 1) <= fraction
class EmotionalPlayer:
def propose(self, total):
pass
def respond(self, fraction):
pass