-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from strakam/restructure-rendering
Restructure code
- Loading branch information
Showing
39 changed files
with
133 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,12 @@ | ||
## TODOs | ||
|
||
### Features | ||
- [x] Let user pass argument indicating what is the default opponent agent for Gymnasium environment. | ||
- [x] Extend action space by allowing user to be IDLE. | ||
- [ ] Add human control, so people can play against bots. | ||
- [x] Random agent new parameters | ||
|
||
### Improvements | ||
- [x] Let user change game speed even when the game is paused; make 'Paused' text separate in the side panel. | ||
- [x] Revisit types for observation space (np.float32 vs np.bool) | ||
- [x] Make ExpanderAgent a bit more readable if possible | ||
- [x] Test IDLE actions | ||
- [x] Should we error out when agent tries to perform an invalid move, so that it is easier to debug? | ||
- [x] Redo how replays are stored and loaded | ||
- [x] In config, resolve circular dependency in a cleaner manner | ||
- [ ] Implement .close() method in envs and instead of quitting in renderer, quit in env | ||
|
||
### Bug fixes | ||
|
||
### Documentation and CI | ||
- [ ] Create more examples of usage (Stable Baselines3 demo) | ||
- [x] Use gymnasium check_env | ||
- [x] Pre-commit hooks for conventional commit checks (enforcing conventional commits) | ||
- [x] Add CI for running tests (pre commit) | ||
- [x] Add CI passing badge to README | ||
- [x] Document agent action/move format | ||
- [x] Split game step tests into more specific tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# agents/__init__.py | ||
|
||
from .random_agent import RandomAgent | ||
from .expander_agent import ExpanderAgent | ||
from .agent import Agent | ||
|
||
# You can also define an __all__ list if you want to restrict what gets imported with * | ||
__all__ = ["Agent", "RandomAgent", "ExpanderAgent"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Agent: | ||
""" | ||
Base class for all agents. | ||
""" | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def play(self): | ||
""" | ||
This method should be implemented by the child class. | ||
It should receive an observation and return an action. | ||
""" | ||
raise NotImplementedError | ||
|
||
def reset(self): | ||
""" | ||
This method allows the agent to reset its state. | ||
If not needed, just pass. | ||
""" | ||
raise NotImplementedError | ||
|
||
def __str__(self): | ||
return self.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from .agent import Agent | ||
import numpy as np | ||
|
||
class RandomAgent(Agent): | ||
def __init__( | ||
self, idle_prob=0.05, split_prob=0.25, name="Random", color=(255, 0, 0) | ||
): | ||
self.name = name | ||
self.color = color | ||
|
||
self.idle_probability = idle_prob | ||
self.split_probability = split_prob | ||
|
||
def play(self, observation): | ||
""" | ||
Randomly selects a valid action. | ||
""" | ||
mask = observation["action_mask"] | ||
valid_actions = np.argwhere(mask == 1) | ||
if len(valid_actions) == 0: # No valid actions | ||
return np.array([1, 0, 0, 0, 0]) # Pass the move | ||
|
||
pass_turn = [0] if np.random.rand() > self.idle_probability else [1] | ||
split_army = [0] if np.random.rand() > self.split_probability else [1] | ||
|
||
action_index = np.random.choice(len(valid_actions)) | ||
|
||
action = np.concatenate((pass_turn, valid_actions[action_index], split_army)) | ||
return action | ||
|
||
def reset(self): | ||
pass |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.