From a70dcdc5abd674f856e136ff0ea6679487b0e6b2 Mon Sep 17 00:00:00 2001 From: Filippos Christianos Date: Fri, 15 Oct 2021 12:45:57 +0100 Subject: [PATCH] Fixes agents not spawning in last row and bumps version. --- README.md | 23 +++++++++++++---------- lbforaging.py | 9 ++++----- lbforaging/__init__.py | 2 +- lbforaging/foraging/environment.py | 4 ++-- setup.py | 2 +- tests/test_env.py | 20 ++++++++++---------- 6 files changed, 31 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 311caed..8079691 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,17 @@ ## Table of Contents -* [About the Project](#about-the-project) - * [Built With](#built-with) -* [Getting Started](#getting-started) - * [Installation](#installation) -* [Usage](#usage) -* [Citation](#citation) -* [Contributing](#contributing) -* [Contact](#contact) +- [Level-Based Foraging Environment](#level-based-foraging-environment) + - [A multi-agent environment for Reinforcement Learning](#a-multi-agent-environment-for-reinforcement-learning) + - [Table of Contents](#table-of-contents) + - [About The Project](#about-the-project) + - [Built With](#built-with) + - [Getting Started](#getting-started) + - [Installation](#installation) + - [Usage](#usage) + - [Citation](#citation) + - [Contributing](#contributing) + - [Contact](#contact) @@ -66,7 +69,7 @@ import lbforaging Then create an environment: ```python -env = gym.make("Foraging-8x8-2p-1f-v0") +env = gym.make("Foraging-8x8-2p-1f-v2") ``` We offer a variety of environments using this template: @@ -79,7 +82,7 @@ But you can register your own variation using (change parameters as needed): from gym.envs.registration register register( - id="Foraging-{0}x{0}-{1}p-{2}f{3}-v0".format(s, p, f, "-coop" if c else ""), + id="Foraging-{0}x{0}-{1}p-{2}f{3}-v2".format(s, p, f, "-coop" if c else ""), entry_point="lbforaging.foraging:ForagingEnv", kwargs={ "players": p, diff --git a/lbforaging.py b/lbforaging.py index 40231d2..037e9d7 100644 --- a/lbforaging.py +++ b/lbforaging.py @@ -4,7 +4,7 @@ import time import gym import numpy as np -import lbforaging.foraging +import lbforaging logger = logging.getLogger(__name__) @@ -22,9 +22,8 @@ def _game_loop(env, render): while not done: - actions = [] - for i, player in enumerate(env.players): - actions.append(env.action_space.sample()) + actions = env.action_space.sample() + nobs, nreward, ndone, _ = env.step(actions) if sum(nreward) > 0: print(nreward) @@ -38,7 +37,7 @@ def _game_loop(env, render): def main(game_count=1, render=False): - env = gym.make("Foraging-8x8-2p-v0") + env = gym.make("Foraging-8x8-2p-2f-v2") obs = env.reset() for episode in range(game_count): diff --git a/lbforaging/__init__.py b/lbforaging/__init__.py index dfd39a0..3885a30 100644 --- a/lbforaging/__init__.py +++ b/lbforaging/__init__.py @@ -9,7 +9,7 @@ for s, p, f, c, po in product(sizes, players, foods, coop, partial_obs): register( - id="Foraging{4}-{0}x{0}-{1}p-{2}f{3}-v1".format(s, p, f, "-coop" if c else "", "-2s" if po else ""), + id="Foraging{4}-{0}x{0}-{1}p-{2}f{3}-v2".format(s, p, f, "-coop" if c else "", "-2s" if po else ""), entry_point="lbforaging.foraging:ForagingEnv", kwargs={ "players": p, diff --git a/lbforaging/foraging/environment.py b/lbforaging/foraging/environment.py index 24b15b3..c04fddd 100644 --- a/lbforaging/foraging/environment.py +++ b/lbforaging/foraging/environment.py @@ -258,8 +258,8 @@ def spawn_players(self, max_player_level): player.reward = 0 while attempts < 1000: - row = self.np_random.randint(0, self.rows - 1) - col = self.np_random.randint(0, self.cols - 1) + row = self.np_random.randint(0, self.rows) + col = self.np_random.randint(0, self.cols) if self._is_empty_location(row, col): player.setup( (row, col), diff --git a/setup.py b/setup.py index d49569f..99a6898 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="lbforaging", - version="1.0.15", + version="1.0.16", description="Level Based Foraging Environment", author="Filippos Christianos", url="https://github.com/semitable/lb-foraging", diff --git a/tests/test_env.py b/tests/test_env.py index 0eb8f4e..266ac8f 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -10,7 +10,7 @@ def manhattan_distance(x,y): @pytest.fixture def simple2p1f(): - env = gym.make("Foraging-8x8-2p-1f-v0") + env = gym.make("Foraging-8x8-2p-1f-v2") _ = env.reset() import time @@ -29,7 +29,7 @@ def simple2p1f(): @pytest.fixture def simple2p1f_sight1(): - env = gym.make("Foraging-8x8-2p-1f-v0", sight=1) + env = gym.make("Foraging-8x8-2p-1f-v2", sight=1) _ = env.reset() import time @@ -48,7 +48,7 @@ def simple2p1f_sight1(): @pytest.fixture def simple2p1f_sight2(): - env = gym.make("Foraging-8x8-2p-1f-v0", sight=2) + env = gym.make("Foraging-8x8-2p-1f-v2", sight=2) _ = env.reset() import time @@ -67,10 +67,10 @@ def simple2p1f_sight2(): def test_make(): - env = gym.make("Foraging-8x8-2p-1f-v0") - env = gym.make("Foraging-5x5-2p-1f-v0") - env = gym.make("Foraging-8x8-3p-1f-v0") - env = gym.make("Foraging-8x8-3p-1f-coop-v0") + env = gym.make("Foraging-8x8-2p-1f-v2") + env = gym.make("Foraging-5x5-2p-1f-v2") + env = gym.make("Foraging-8x8-3p-1f-v2") + env = gym.make("Foraging-8x8-3p-1f-coop-v2") def test_spaces(): @@ -78,7 +78,7 @@ def test_spaces(): def test_seed(): - env = gym.make("Foraging-8x8-2p-2f-v0") + env = gym.make("Foraging-8x8-2p-2f-v2") for seed in range(10): obs1 = [] obs2 = [] @@ -94,7 +94,7 @@ def test_seed(): def test_food_spawning_0(): - env = gym.make("Foraging-6x6-2p-2f-v0") + env = gym.make("Foraging-6x6-2p-2f-v2") for i in range(1000): _ = env.reset() @@ -113,7 +113,7 @@ def test_food_spawning_0(): assert foods[1][1] not in [0, 7] def test_food_spawning_1(): - env = gym.make("Foraging-8x8-2p-3f-v0") + env = gym.make("Foraging-8x8-2p-3f-v2") for i in range(1000): _ = env.reset()