Skip to content

Commit 1b301f6

Browse files
committed
refactor simple opponents out of players file
1 parent bb437ee commit 1b301f6

File tree

1 file changed

+0
-83
lines changed

1 file changed

+0
-83
lines changed

src/players.py

-83
Original file line numberDiff line numberDiff line change
@@ -22,89 +22,6 @@ def get_dim_generic(parameter_groups):
2222
return total
2323

2424

25-
class ConstantPlayer():
26-
"""
27-
Always play same move
28-
"""
29-
def __init__(self, constant_choice):
30-
self.constant_choice = constant_choice
31-
32-
def move(self, last_opponent_action):
33-
return self.constant_choice
34-
35-
36-
class RandomStrategyChangePlayer():
37-
"""
38-
Switches strategy with probability p
39-
"""
40-
def __init__(self, p=0.1):
41-
self.p = p
42-
self.choice = random.randint(0, 2)
43-
44-
def move(self, last_opponent_action):
45-
if random.random() < self.p:
46-
self.choice = random.randint(0, 2)
47-
return self.choice
48-
49-
50-
class RoundRobinPlayer():
51-
"""
52-
Rock, paper, scissors, rock, paper, scissors, ...
53-
"""
54-
def __init__(self):
55-
self.choice = random.randint(0, 2)
56-
self.update_rule = random.choice([-1, 1])
57-
58-
def move(self, last_opponent_action):
59-
self.choice += self.update_rule # be able to cycle both directions
60-
self.choice = self.choice % 3
61-
return self.choice
62-
63-
64-
class ReverseRoundRobinDoubleTapPlayer():
65-
"""
66-
Rock, rock, scissors, scissors, paper, paper, ...
67-
"""
68-
def __init__(self):
69-
self.random_offset = random.randint(0, 5)
70-
self.pattern = [0, 0, 2, 2, 1, 1]
71-
self.round_num = 0
72-
73-
def move(self, last_opponent_action):
74-
choice = self.pattern[(self.round_num + self.random_offset)% len(self.pattern)]
75-
self.round_num += 1
76-
return choice
77-
78-
79-
class RandomPlayer():
80-
"""
81-
The classic Nash equilibrium strategy that cannot be exploited
82-
if we assume symmetrical rewards.
83-
"""
84-
def move(self, last_opponent_action):
85-
return random.randint(0, 2)
86-
87-
88-
class BiasedRandomPlayer():
89-
"""
90-
Similar to the RandomPlayer, but can learn to stochastically favor
91-
certain actions more than others
92-
"""
93-
def __init__(self):
94-
self.bias = None
95-
96-
def get_dim(self):
97-
return 3
98-
99-
def set_parameters(self, x: torch.Tensor):
100-
self.bias = x
101-
102-
def move(self, last_opponent_action):
103-
softmax_output = F.softmax(self.bias)
104-
choice = torch.multinomial(softmax_output, 1).item()
105-
return choice
106-
107-
10825
class Rnn():
10926
"""
11027
A very simple one layer LSTM with a (configurable) argmax or softmax

0 commit comments

Comments
 (0)