Skip to content

Commit

Permalink
Fixes agents not spawning in last row and bumps version.
Browse files Browse the repository at this point in the history
  • Loading branch information
semitable committed Oct 15, 2021
1 parent 79593d8 commit a70dcdc
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 29 deletions.
23 changes: 13 additions & 10 deletions README.md
Expand Up @@ -5,14 +5,17 @@
<!-- 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)
- [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)



Expand Down Expand Up @@ -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:
Expand All @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions lbforaging.py
Expand Up @@ -4,7 +4,7 @@
import time
import gym
import numpy as np
import lbforaging.foraging
import lbforaging


logger = logging.getLogger(__name__)
Expand All @@ -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)
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion lbforaging/__init__.py
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lbforaging/foraging/environment.py
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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",
Expand Down
20 changes: 10 additions & 10 deletions tests/test_env.py
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -67,18 +67,18 @@ 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():
pass


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 = []
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit a70dcdc

Please sign in to comment.