Farama-Foundation / PettingZoo

An API standard for multi-agent reinforcement learning environments, with popular reference environments and related utilities
https://pettingzoo.farama.org
Other
2.62k stars 414 forks source link

[Proposal] Add example codes to the environments in the documentation #1056

Closed Qardruss closed 1 year ago

Qardruss commented 1 year ago

Proposal

I'm new to using PettingZoo, and so far the documentation has done me a fat lot of good. It's nearly useless for me as there is literally no example code for the individual environments for some reason. Could you at least make a universal API for PettingZoo that works with every environment?

Motivation

It really frustrates me that THERE. IS. NO. EXAMPLE. CODE. What exact reason is there for not having example code? To intentionally anger newbies like myself?

Pitch

It would be a lot easier to use PettingZoo if the documentation had example code for environments. Currently it only has the documentation for the env and raw_env functions for individual environments, which to me, is (as I said previously) a fat lot of good.

Alternatives

An alternative is to make a universal API that works with every environment! Or maybe just simplify the documentation?

Additional context

I can't just copy one of the example programs, because, for example, if I take the program for Chess and replace Chess with, let's say, Gin Rummy, it doesn't work. And I don't know how to fix it as I'm new to PettingZoo and have literally no knowledge of how anything works with it.

Checklist

elliottower commented 1 year ago

Hi, sorry you've found the docs to be lacking for your use case. We do have example code for each of the types of environments (atari, butterfly, classic, mpe, SISL) but adding a script for each individual environment wouldn't be too hard given that. I can try to implement this before the next release, as I understand it must be frustrating trying to figure out how to even load an environment.

For your use right now though you can simply use the example script here https://pettingzoo.farama.org/environments/classic/ and replace all of the occurrences of texas_holdem_v4 with connect_four_v3 or whatever other classic environment:

Original example:

from pettingzoo.classic import texas_holdem_v4

env = texas_holdem_v4.env(render_mode="human")
env.reset(seed=42)

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

    if termination or truncation:
        break

    mask = observation["action_mask"]
    action = env.action_space(agent).sample(mask)  # this is where you would insert your policy

    env.step(action)
env.close()

Modified example (find and replace):

from pettingzoo.classic import connect_four_v3

env = connect_four_v3.env(render_mode="human")
env.reset(seed=42)

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

    if termination or truncation:
        break

    mask = observation["action_mask"]
    action = env.action_space(agent).sample(mask)  # this is where you would insert your policy

    env.step(action)
env.close()
elliottower commented 1 year ago

Fixed in https://github.com/Farama-Foundation/PettingZoo/pull/1057