-
Notifications
You must be signed in to change notification settings - Fork 8
/
agent.py
37 lines (29 loc) · 850 Bytes
/
agent.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
"""
Agent interface
"""
class Agent:
"""
An agent defined by a strategy.
"""
def __init__(self, name, strategy):
self.name = name
self.strategy = strategy
self.player_id = None
def __str__(self):
return self.name
def setPlayerId(self, i):
self.player_id = i
def getPlayerId(self):
return self.player_id
def nextAction(self, state):
if self.player_id is None:
raise("Player ID missing")
return self.strategy(self.player_id, state)
def lastReward(self, game):
if self.player_id is None:
raise("Player ID missing")
return game.agentLastReward(self.player_id)
def isAlive(self, game):
if self.player_id is None:
raise("Player ID missing")
return game.isAlive(self.player_id)