Skip to content

Multiagent CPP API - #584

Draft
jjshoots wants to merge 315 commits into
Farama-Foundation:mainfrom
jjshoots:jet/multiagent_api
Draft

Multiagent CPP API#584
jjshoots wants to merge 315 commits into
Farama-Foundation:mainfrom
jjshoots:jet/multiagent_api

Conversation

@jjshoots

@jjshoots jjshoots commented Dec 14, 2024

Copy link
Copy Markdown
Contributor

This updates the CPP interface to allow a 2 player interface. Work for the 4 player interface is left as a future PR because that's quite a bit more complicated.

AFAICT, these are the 2 player games available:

  1. Air Raid
  2. Combat
  3. Double Dunk
  4. Human Cannonball
  5. Ice Hockey
  6. Joust
  7. Maze Craze
  8. Surround
  9. Tennis
  10. Video Checkers
  11. Video Chess

And these are games with 4 players:

  1. Warlords
  2. Flag Capture

I believe we should be able to just copy the games that support multiplayer from the MALE repo since they already have the modifications required. I have modified Surround to support 2 player mode for the testing script below.

The more difficult question is how the Python interface for this should look, since, I presume, the gymnasium API is not sufficient.

Testing

import gymnasium as gym
import ale_py

gym.register_envs(ale_py)

# Initialise the environment
env = gym.make("ALE/Surround-v5", render_mode="human", mode=4)  # mode here controls multiplayer. I believe mode 2 is single player

# Reset the environment to generate the first observation
observation, info = env.reset(seed=42)
for _ in range(300):
    # this is where you would insert your policy
    action = env.action_space.sample()

    # step (transition) through the environment with the action
    # receiving the next observation, reward and if the episode has terminated or truncated
    observation, reward, terminated, truncated, info = env.step(action)

    # If the episode has ended then we can reset to start a new episode
    if terminated or truncated:
        observation, info = env.reset()

env.close()

Expected Behaviour:
Since the gymnasium API by default makes player B's actions NOOP, setting mode=4 means that player B won't have any actions.
Conversely, setting mode=2 would mean that player B will be controlled by the emulator, therefore moving in random directions.

tkoeppe and others added 30 commits March 11, 2020 15:59
Previously, ROM-modified settings could only affect a subset of keys,
since the emulator was already set up before the modifications were
even applied (by way of ALEInterface::loadRom).

This change improves on 80783f5,
where it should have belonged.
This change adds observer functions to StellaEnvironment and
ALEInterface to retrieve the current "difficulty" and "mode"
settings. Previously, these values could be set, but not queried.
Fixes const correctness, removes user-defined special members (the
implied definitions already copy and assign arrays); replaces a macro
with a member constant.
Previously, those were leaked when their only reference was
overwritten as part of reloading the ROM.
The call was moved unconditionally by 3bee0b6,
which left the Console (and its properties) uninitialized on
the error path "wrapper == NULL". This change reinstates that
call locally only on this path, which ends in program exit.
The default argument was not used and not useful in the .cpp file;
it is reasonable and useful in the interface.

The relevant documentation is also moved.
* Cartridge::create did not check whether a catridge had been created
  before using it (introduced by 2121bf7).

* Cartridge::autodetectType did not check that the "AR" cartridge ROM
  had non-zero size.

* Cartridge::autodetectType did not check that the fallback choice of
  "4K" cartridge had the correct ROM size. Since the size-checked case
  is already handled earlier, we remove the entire fallback case.

* Cartridge::searchForBytes did not check whether the search term was
  within the bounds of the search range.

* OSystem::createConsole and OSystem::getROMInfo failed to deallocate
  the image memory in case of a cartridge loading error.

Note that this change does not provide complete checking for ROM
validity: if the conditional block at Cart.cxx:79 is skipped, no
autodetection is performed and the provided ROM data is assumed to be
valid for the specified cartridge type (with potential out of bounds
accesses otherwise). The block is skipped if the "rominfo" setting is
not set to true and if the cartridge type has been set to something
other than its default of "AUTO-DETECT".
This change adds support code for the following games:

  * Atlantis2
  * Backgammon
  * BasicMath
  * Blackjack
  * Casino
  * Crossbow
  * DarkChambers
  * Earthworld
  * Entombed
  * ET
  * FlagCapture
  * Hangman
  * HauntedHouse
  * HumanCannonball
  * Klax
  * MarioBros
  * MiniatureGolf
  * Othello
  * Pacman
  * Pitfall2
  * SpaceWar
  * Superman
  * Surround
  * TicTacToe3D
  * VideoCheckers
  * VideoChess
  * VideoCube
  * WordZapper

All available game difficulty settings and single-player game modes
should be advertised.
…ut-v2

Bump Github Actions actions/checkout to v2
* Removed RLGlue interface. Its own website says it's deprecated, it hasn't been updated in over a decade and I searched Github and couldn't find a project which actually used it.

* Removed FIFOInterface. It seemed to be in a dire state, the examples didn't work, the interface segfault's, and I couldn't find a single project using this interface. This also means I removed the Java example we previously had.

* Since I removed both the interfaces I also removed the CLI build along with its corresponding functions in emucore/Settings.
With the removal of controllers many of the examples are no longer
relevant. The remaining Python and C++ examples have been updated
accordingly.
pseudo-rnd-thoughts and others added 20 commits September 24, 2024 16:38
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mark Towers <mark.m.towers@gmail.com>
Co-authored-by: Mark Towers <mark.m.towers@gmail.com>
@jjshoots
jjshoots marked this pull request as ready for review December 14, 2024 11:02

@pseudo-rnd-thoughts pseudo-rnd-thoughts left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to change the actions? I don't see where that is necessary?
Could you add tests that PettingZoo can work with this?

@jjshoots

jjshoots commented Dec 15, 2024

Copy link
Copy Markdown
Contributor Author

@pseudo-rnd-thoughts Yeah we do, both players use different action idx and the game will throw an error here. Although now that you mention it, maybe that's not needed afterall and we can just do a remapping within the C stack. I'll work on that.
Updated to use just one set of actions.

Roger on the PZ tests.

@pseudo-rnd-thoughts

pseudo-rnd-thoughts commented Jan 9, 2025

Copy link
Copy Markdown
Member

@jjshoots I took your PR and worked out the issue, pybind is a mess - https://github.com/pseudo-rnd-thoughts/Arcade-Learning-Environment/tree/multiagent_api-new

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.