Skip to content

Commit

Permalink
Merge pull request #57 from Puckoland/agentAbstractClassImprovements
Browse files Browse the repository at this point in the history
refactor: Move common attributes to Agent class
  • Loading branch information
strakam authored Sep 30, 2024
2 parents 1e761d4 + e48a39b commit 6618580
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
7 changes: 4 additions & 3 deletions generals/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ class Agent:
Base class for all agents.
"""

def __init__(self):
pass
def __init__(self, name, color):
self.name = name
self.color = color

@abstractmethod
def play(self):
def play(self, observation):
"""
This method should be implemented by the child class.
It should receive an observation and return an action.
Expand Down
3 changes: 1 addition & 2 deletions generals/agents/expander_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

class ExpanderAgent(Agent):
def __init__(self, name="Expander", color=(0, 130, 255)):
self.name = name
self.color = color
super().__init__(name, color)

def play(self, observation):
"""
Expand Down
3 changes: 1 addition & 2 deletions generals/agents/random_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ class RandomAgent(Agent):
def __init__(
self, name="Random", color=(255, 0, 0), split_prob=0.25, idle_prob=0.05
):
self.name = name
self.color = color
super().__init__(name, color)

self.idle_probability = idle_prob
self.split_probability = split_prob
Expand Down

0 comments on commit 6618580

Please sign in to comment.