Git Product home page Git Product logo

gridenvs's Introduction

Gridenvs

Gridenvs is an open-source library that allows to easily create gym gridworld environments. To test some examples, run keyboard_agent.py.

Creating your own environments

You can easily create an environment by implementing the following three functions:

  • get_init_state(): returns a dictionary containing the internal state of the environment. The state dict will contain all the necessary information of the game, and has to come with at least two elements: "world" (the GridWorld object) and "hero" (the agent GridObject).
  • get_next_state(state, action): implements the logic of the environment, and returns a tuple (state, reward, end_of_episode, info) just as gym's env.step() function, except for the observation, that is automatically generated from the returned state.
  • get_gridstate(state): returns a tuple consisting of the grid size and a list of objects to be rendered. This is used to generate the observation from the state.

Most environments consist of a single agent that moves in a grid (i.e. action affect a single object). If this is your case, consider inheriting from the HeroEnv class. To easily create a grid map, we provide a function that takes as input a list of strings, such as:

["WWWWWWWWWW",
 "WD.W....KW",
 "W..W.....W",
 "W..W..WWWW",
 "W........W",
 "W........W",
 "W..WWWW..W",
 "W........W",
 "WH.......W",
 "WWWWWWWWWW"]

See, for instance, the key-door examples.

To be able to create your environment with gym.make() you will need to register it. See gym's creating environments guide or check examples/__init__.py.

For other types of games, consider deriving directly from the Env class.

Installation

Clone the repository:

git clone https://github.com/aig-upf/gridenvs.git
cd gridenvs 

(Optional) If you want to create a virtual environment, you can do it by:

python3 -m venv my_venv
source my_venv/bin/activate

Install gridenvs:

pip3 install -r requirements.txt

When using it in other projects, make sure gridenvs is in your $PYTHONPATH (e.g. by adding it with export PYTHONPATH=\my\path\to\gridenvs).

If you are using an environment from the examples package, import it so that environments get registered to gym (i.e. import gridenvs.examples).

gridenvs's People

Contributors

mjunyentb avatar neko0 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gridenvs's Issues

check_collision dictionary in gridworld_map.py

hi guys,
I find the check_collision dictionary quite hard to read.
You are using this dictionary only once : in "collides_with" method. Thus, maybe you should implement directly the check_collision lambda functions into the "collides_with" method.

__floordiv__ in utils.py

@mjunyentb are you sure about your function floordiv ? It seems that you copy pasted the function truediv without replacing "/" by "//". Is that made on purpose ?

classes instead of dictionaries ?

In the keybord_controller.py file, you create classes with no init and no methods (Key and Controls). This sould be reimplemented as just plain dictionaries I think.

render_gym function issue

Here is the reported bug that I have found (see gridworl.py, function render_gym)

Sometimes the environment is closed just after being created (gym does that?) and raises an exception after calling _render(close=True). Check it out!

Documentation

TODO : make a READ_ME file and comment the classes a little bit more

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.