Skip to content

Commit

Permalink
refactor: Improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Puckoland committed Oct 1, 2024
1 parent a4713b0 commit 38b0266
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion generals/agents/expander_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def play(self, observation):

valid_actions = np.argwhere(mask == 1)
if len(valid_actions) == 0: # No valid actions
return (1, np.array([0, 0]), 0, 0)
return 1, np.array([0, 0]), 0, 0

army = observation["army"]
opponent = observation["opponent_cells"]
Expand Down
2 changes: 1 addition & 1 deletion generals/agents/random_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def play(self, observation):

valid_actions = np.argwhere(mask == 1)
if len(valid_actions) == 0: # No valid actions
return (1, (0, 0), 0, 0)
return 1, (0, 0), 0, 0

pass_turn = 0 if np.random.rand() > self.idle_probability else 1
split_army = 0 if np.random.rand() > self.split_probability else 1
Expand Down
2 changes: 1 addition & 1 deletion generals/gui/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def render_stats(self):
)
# add opacity to the color, where color is a tuple (r,g,b)
if name in self.agent_fov and not self.agent_fov[name]:
color = tuple([int(0.5 * c) for c in color])
color = tuple([int(0.5 * rgb) for rgb in color])
self.render_cell_text(self.score_cols["Agent"][i], name, bg_color=color)

# Write other columns
Expand Down
4 changes: 4 additions & 0 deletions generals/integrations/gymnasium_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def __init__(
reward_fn: RewardFn = None,
render_mode=None,
):
self.game = None
self.gui = None
self.replay = None

self.render_mode = render_mode
self.reward_fn = self.default_reward if reward_fn is None else reward_fn
self.grid_factory = grid_factory
Expand Down
4 changes: 4 additions & 0 deletions generals/integrations/pettingzoo_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def __init__(
reward_fn: RewardFn = None,
render_mode=None,
):
self.game = None
self.gui = None
self.replay = None

self.render_mode = render_mode
self.grid_factory = grid_factory

Expand Down

0 comments on commit 38b0266

Please sign in to comment.