-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathbots.py
144 lines (120 loc) · 4.35 KB
/
bots.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from Player import BasePlayer
import random
class Pushover(BasePlayer):
'''Player that always hunts.'''
def __init__(self):
self.name = "Pushover"
def hunt_choices(
self,
round_number,
current_food,
current_reputation,
m,
player_reputations,
):
return ['h']*len(player_reputations)
class Freeloader(BasePlayer):
'''Player that always slacks.'''
def __init__(self):
self.name = "Freeloader"
def hunt_choices(
self,
round_number,
current_food,
current_reputation,
m,
player_reputations,
):
return ['s']*len(player_reputations)
class Alternator(BasePlayer):
'''Player that alternates between hunting and slacking.'''
def __init__(self):
self.name = "Alternator"
self.last_played = 's'
def hunt_choices(
self,
round_number,
current_food,
current_reputation,
m,
player_reputations,
):
hunt_decisions = []
for i in range(len(player_reputations)):
self.last_played = 'h' if self.last_played == 's' else 's'
hunt_decisions.append(self.last_played)
return hunt_decisions
class MaxRepHunter(BasePlayer):
'''Player that hunts only with people with max reputation.'''
def __init__(self):
self.name = "MaxRepHunter"
def hunt_choices(
self,
round_number,
current_food,
current_reputation,
m,
player_reputations,
):
threshold = max(player_reputations)
return ['h' if rep == threshold else 's' for rep in player_reputations]
class Random(BasePlayer):
'''
Player that hunts with probability p_hunt and
slacks with probability 1-p_hunt
'''
def __init__(self, p_hunt):
assert p_hunt >= 0.00 and p_hunt <= 1.00, "p_hunt must be at least 0 and at most 1"
self.name = "Random" + str(p_hunt)
self.p_hunt = p_hunt
def hunt_choices(
self,
round_number,
current_food,
current_reputation,
m,
player_reputations,
):
return ['h' if random.random() < self.p_hunt else 's' for p in player_reputations]
class FairHunter(BasePlayer):
'''Player that tries to be fair by hunting with same probability as each opponent'''
def __init__(self):
self.name = "FairHunter"
def hunt_choices(
self,
round_number,
current_food,
current_reputation,
m,
player_reputations,
):
return ['h' if random.random() < rep else 's' for rep in player_reputations]
class BoundedHunter(BasePlayer):
'''Player that hunts whenever the other's reputation is within some range.'''
def __init__(self,lower,upper):
self.name = "BoundedHunter" + str(lower)+'-'+str(upper)
self.low = lower
self.up = upper
def hunt_choices(
self,
round_number,
current_food,
current_reputation,
m,
player_reputations,
):
return ['h' if self.low <= rep <= self.up else 's' for rep in player_reputations]
class AverageHunter(BasePlayer):
'''Player that tries to maintain the average reputation, but spreads its hunts randomly.'''
def __init__(self):
self.name = "AverageHunter"
def hunt_choices(
self,
round_number,
current_food,
current_reputation,
m,
player_reputations,
):
avg_rep = sum(player_reputations) / float(len(player_reputations))
return ['h' if random.random() < avg_rep else 's' for rep in player_reputations]