Skip to content

Commit

Permalink
Merge pull request #35 from rradules/mo-games
Browse files Browse the repository at this point in the history
Merge Mo-Games into main
  • Loading branch information
hiazmani authored Jan 23, 2024
2 parents 69a5872 + 869dabf commit 3d9c587
Show file tree
Hide file tree
Showing 21 changed files with 1,462 additions and 4 deletions.
2 changes: 1 addition & 1 deletion momaland/envs/beach_domain/beach_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class MOBeachDomain(MOParallelEnv):
These attributes should not be changed after initialization.
"""

metadata = {"render_modes": ["human"], "name": "mobeach_v0"}
metadata = {"render_modes": ["human"], "name": "mobeach_v0", "is_parallelizable": True}

# TODO does this environment require max_cycle?
def __init__(
Expand Down
1 change: 1 addition & 0 deletions momaland/envs/breakthrough/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Adaptation of the Breakthrough game to multi-objective settings."""
350 changes: 350 additions & 0 deletions momaland/envs/breakthrough/breakthrough.py

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions momaland/envs/breakthrough/breakthrough_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""MO Breakthrough check."""

import numpy as np
from breakthrough import MOBreakthrough


def check_env():
"""Check the environment."""
environment = MOBreakthrough(board_width=6, board_height=6, num_objectives=4, render_mode="ansi")
environment.reset(seed=42)

for agent in environment.agent_iter():
observation, reward, termination, truncation, info = environment.last()

print("rewards from the last timestep", reward)
print("cumulative rewards before action", environment._cumulative_rewards)
if termination or truncation:
action = None
else:
if observation:
print("environment before action:")
environment.render()
# print("observation:")
# print(observation)
# this is where you would insert your policy
action = np.where(observation["action_mask"] != 0)[0][0]
print("action: ", action)

environment.step(action)
print("environment after action:")
environment.render()
print("cumulative rewards after action", environment._cumulative_rewards)

# print("observation: ", observation)
# print("reward: ", reward)
print("game end: rewards", environment.rewards)
print("game end: cumulative rewards", environment._cumulative_rewards)
# name = input("Press key to end\n")
environment.close()


if __name__ == "__main__":
(check_env())
5 changes: 5 additions & 0 deletions momaland/envs/breakthrough/mobreakthrough_v0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Breakthrough environment with multiple objectives."""
from momaland.envs.breakthrough.breakthrough import env, raw_env


__all__ = ["env", "raw_env"]
2 changes: 1 addition & 1 deletion momaland/envs/congestion_game/congestion_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __init__(
self.cost_function = dict()
self._create_latency_and_cost_function(nx.get_edge_attributes(self.graph, "latency_function"), num_agents)

metadata = {"render_modes": ["human"], "name": "mocongestion_v0"}
metadata = {"render_modes": ["human"], "name": "mocongestion_v0", "is_parallelizable": True}

# this cache ensures that same space object is returned for the same agent
# allows action space seeding to work as expected
Expand Down
1 change: 1 addition & 0 deletions momaland/envs/connect4/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Adaptation of the Connect4 game to multi-objective settings."""
Loading

0 comments on commit 3d9c587

Please sign in to comment.