Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace relative paths with absolute ones #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ def __init__(self, agent_name, code_name, display_name, train: bool, backend: "A
self.backend = backend

# Load custom avatar or standard robot avatar of assigned color
game_dir = os.path.dirname(__file__)
try:
if isinstance(avatar_sprite_desc, bytes):
self.avatar = pygame.image.load(BytesIO(avatar_sprite_desc))
else:
self.avatar = pygame.image.load(f'agent_code/{code_name}/avatar.png')
self.avatar = pygame.image.load(f'{game_dir}/agent_code/{code_name}/avatar.png')
assert self.avatar.get_size() == (30, 30)
except Exception as e:
self.avatar = pygame.image.load(s.ASSET_DIR / f'robot_{avatar_sprite_desc}.png')
Expand All @@ -70,7 +71,7 @@ def __init__(self, agent_name, code_name, display_name, train: bool, backend: "A
if isinstance(avatar_sprite_desc, bytes):
self.bomb_sprite = pygame.image.load(BytesIO(bomb_sprite_desc))
else:
self.bomb_sprite = pygame.image.load(f'agent_code/{code_name}/bomb.png')
self.bomb_sprite = pygame.image.load(f'{game_dir}/agent_code/{code_name}/bomb.png')
assert self.bomb_sprite.get_size() == (30, 30)
except Exception as e:
self.bomb_sprite = pygame.image.load(s.ASSET_DIR / f'bomb_{bomb_sprite_desc}.png')
Expand Down Expand Up @@ -201,9 +202,9 @@ def __init__(self, train, agent_name, code_name, result_queue):
self.code_name = code_name
self.result_queue = result_queue

self.callbacks = importlib.import_module('agent_code.' + self.code_name + '.callbacks')
self.callbacks = importlib.import_module(f'agent_code.{self.code_name}.callbacks')
if train:
self.train = importlib.import_module('agent_code.' + self.code_name + '.train')
self.train = importlib.import_module(f'agent_code.{self.code_name}.train')
for module_name in ["callbacks"] + (["train"] if train else []):
module = getattr(self, module_name)
for event_name, event_args in AGENT_API[module_name].items():
Expand All @@ -218,12 +219,11 @@ def __init__(self, train, agent_name, code_name, result_queue):

self.fake_self = SimpleNamespace()
self.fake_self.train = train

self.wlogger = logging.getLogger(self.agent_name + '_wrapper')
self.wlogger.setLevel(s.LOG_AGENT_WRAPPER)
self.fake_self.logger = logging.getLogger(self.agent_name + '_code')
self.fake_self.logger.setLevel(s.LOG_AGENT_CODE)
log_dir = f'agent_code/{self.code_name}/logs/'
log_dir = f'{os.path.dirname(__file__)}/agent_code/{self.code_name}/logs/'
if not os.path.exists(log_dir): os.makedirs(log_dir)
handler = logging.FileHandler(f'{log_dir}{self.agent_name}.log', mode="w")
handler.setLevel(logging.DEBUG)
Expand Down