Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: Override player input with machine learning models #17407

Merged
merged 41 commits into from
Jan 21, 2025

Conversation

MatPoliquin
Copy link
Contributor

@MatPoliquin MatPoliquin commented Jan 13, 2025

This PR adds support for overriding player 1 and/or 2 controller input with custom AI.
For example, NHL94 Sega Genesis community wants to be able to play against better AI, this feature address their needs.
The AI/machine learning part is in an external library so that way there is no need to update RA code base every time there is changes made to a game's AI, updates to pytorch, changes in model format, etc

Users can toggle on/off overriding input with the "Game AI" section in the quick menu.

This is an experimental feature at an early stage and should be turned off by default
Only works on Windows and Linux for now (x86), but eventually more platforms will be supported

Question:
This feature needs an external lib that I made + data (models/ram info). Where is best to put the build instructions for this?
https://github.com/MatPoliquin/stable-retro-scripts/tree/main/ef_lib

game_ai_menu

@LibretroAdmin
Copy link
Contributor

Seems like the CI checks failed.

intl/msg_hash_us.c Outdated Show resolved Hide resolved
@MatPoliquin
Copy link
Contributor Author

Seems like the CI checks failed.

Fixed

ai/game_ai.cpp Outdated Show resolved Hide resolved
ai/game_ai.cpp Outdated Show resolved Hide resolved
ai/game_ai.cpp Outdated Show resolved Hide resolved
ai/game_ai.cpp Outdated Show resolved Hide resolved
ai/game_ai.cpp Outdated Show resolved Hide resolved
ai/game_ai.cpp Outdated Show resolved Hide resolved
ai/game_ai.cpp Outdated Show resolved Hide resolved
ai/game_ai.cpp Outdated Show resolved Hide resolved
configuration.c Outdated Show resolved Hide resolved
runloop.c Outdated Show resolved Hide resolved
@viachaslavic
Copy link
Contributor

As far as I understand it requires a manually launching separate instance from https://github.com/MatPoliquin/stable-retro-scripts? This may not be very user-friendly. Maybe it makes sense to make it as a dynamic library or run/control the subprocess directly from RA?

@MatPoliquin
Copy link
Contributor Author

As far as I understand it requires a manually launching separate instance from https://github.com/MatPoliquin/stable-retro-scripts? This may not be very user-friendly. Maybe it makes sense to make it as a dynamic library or run/control the subprocess directly from RA?

It's already a dynamic lib, only this part of the stable-retro-scripts repo is used with retroarch (ef_lib folder):
https://github.com/MatPoliquin/stable-retro-scripts/tree/main/ef_lib

The python scripts you see are used to train and test the models shipped with the lib

@viachaslavic
Copy link
Contributor

viachaslavic commented Jan 14, 2025

It's already a dynamic lib, only this part of the stable-retro-scripts repo is used with retroarch (ef_lib folder): https://github.com/MatPoliquin/stable-retro-scripts/tree/main/ef_lib

Perhaps it makes sense to place it in deps folder? (excluding the models, which will apparently be able to be added downloads in the future via the online updater)

@MatPoliquin
Copy link
Contributor Author

MatPoliquin commented Jan 14, 2025

It's already a dynamic lib, only this part of the stable-retro-scripts repo is used with retroarch (ef_lib folder): https://github.com/MatPoliquin/stable-retro-scripts/tree/main/ef_lib

Perhaps it makes sense to place it in deps folder? (excluding the models, apparently)

Added the ef_lib folder (named it game_ai_lib) in deps

@MatPoliquin
Copy link
Contributor Author

It's already a dynamic lib, only this part of the stable-retro-scripts repo is used with retroarch (ef_lib folder): https://github.com/MatPoliquin/stable-retro-scripts/tree/main/ef_lib

Perhaps it makes sense to place it in deps folder? (excluding the models, which will apparently be able to be added downloads in the future via the online updater)

Just saw your edit about online updater downloading the models... that would be very cool!

ai/game_ai.cpp Outdated Show resolved Hide resolved
@zoltanvb
Copy link
Contributor

deps/ef_lib does not get compiled during RetroArch build process, even if HAVE_AI is enabled, if I understand correctly? User is expected to have/manually build the library that is invoked. The integration can be allowed some time to mature, just saying that existing dependencies are usually directly added to the RA makefiles.

@MatPoliquin
Copy link
Contributor Author

deps/ef_lib does not get compiled during RetroArch build process, even if HAVE_AI is enabled, if I understand correctly? User is expected to have/manually build the library that is invoked. The integration can be allowed some time to mature, just saying that existing dependencies are usually directly added to the RA makefiles.

Yes, users are expected to build the library themselves for now. I plan to integrate it in the RA makefiles in the future

ai/game_ai.cpp Outdated
@@ -0,0 +1,224 @@
#include "game_ai.h"
#include <stdio.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you rewrite this entire file into C? The 'dep' can still be C++ I guess as long as the RetroArch glue here is at least C.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@LibretroAdmin LibretroAdmin merged commit 66e23fc into libretro:master Jan 21, 2025
30 checks passed
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.

4 participants