mirror of
https://github.com/libretro/RetroArch.git
synced 2025-04-02 10:51:52 -04:00
* Add dummy game ai subsystem * First working prototype of a machine learning model that can override player input * Update README.md * Update README.md * Fix loading path on Windows * Change ai override to player 2 * Added quick menu show game ai option * Implemented Quick Menu entry for Game AI options * Redirect debug logs to retroarch log system + properly support player override * Added support to use framebuffer as input to the AI * Added pixel format parameter to API * Fix game name * code clean-up of game_ai.cpp * Update README.md - Windows Build * Update README.md * Update README.md * Update README.md * Update config.params.sh turn off GAME_AI feature by default * Fix compile error in menu_displaylist.c * Add missing #define in menu_cbs_title.c * Added new game_ai entry in griffin_cpp * Remove GAME_AI entry in msg_hash_us.c * Fix compile error in menu_displaylist.h * Removed GAME AI references from README.md * Fixes coding style + add GameAI lib API header * Convert comment to legacy + remove unused code * Additional coding style fixes to game_ai.cpp * Fix identation issues in game_ai.cpp * Removed some debug code in game_ai.cpp * Add game_ai_lib in deps * Replace assert with retro_assert * Update Makefile.common * Converting game_ai from cpp to c. First step. * Convert game_ai from CPP to C. STEP 2: add C function calls * Convert game_ai from CPP to C. Final Step * Added shutdown function for game ai lib * Update game_ai_lib README * Fix crash when loading/unloading multiple games
55 lines
No EOL
1.4 KiB
C++
55 lines
No EOL
1.4 KiB
C++
#include "DefaultGameAI.h"
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
#include <assert.h>
|
|
#include <random>
|
|
|
|
enum DefaultButtons {
|
|
INPUT_B = 0,
|
|
INPUT_A = 1,
|
|
INPUT_MODE = 2,
|
|
INPUT_START = 3,
|
|
INPUT_UP = 4,
|
|
INPUT_DOWN = 5,
|
|
INPUT_LEFT = 6,
|
|
INPUT_RIGHT = 7,
|
|
INPUT_C = 8,
|
|
INPUT_Y = 9,
|
|
INPUT_X = 10,
|
|
INPUT_Z = 11,
|
|
INPUT_MAX = 12
|
|
};
|
|
|
|
//=======================================================
|
|
// DefaultGameAI::Init
|
|
//=======================================================
|
|
void DefaultGameAI::Init(void * ram_ptr, int ram_size)
|
|
{
|
|
LoadConfig();
|
|
|
|
InitRAM(ram_ptr, ram_size);
|
|
}
|
|
|
|
//=======================================================
|
|
// DefaultGameAI::Think
|
|
//=======================================================
|
|
void DefaultGameAI::Think(bool buttons[GAMEAI_MAX_BUTTONS], int player, const void *frame_data, unsigned int frame_width, unsigned int frame_height, unsigned int frame_pitch, unsigned int pixel_format)
|
|
{
|
|
std::vector<float> output(DefaultButtons::INPUT_MAX);
|
|
|
|
input.data = (void *) frame_data;
|
|
input.width = frame_width;
|
|
input.height = frame_height;
|
|
input.pitch = frame_pitch;
|
|
input.format = pixel_format;
|
|
|
|
models["Model"]->Forward(output, input);
|
|
|
|
for (int i=0; i < output.size(); i++)
|
|
{
|
|
buttons[i] = output[i] >= 1.0 ? 1 : 0;
|
|
}
|
|
|
|
buttons[DefaultButtons::INPUT_START] = 0;
|
|
buttons[DefaultButtons::INPUT_MODE] = 0;
|
|
} |