From a247b5d252e038618495b73a4855ae1bc3c589ab Mon Sep 17 00:00:00 2001 From: Diego Celix Date: Thu, 2 Mar 2017 00:14:41 +0100 Subject: [PATCH 01/10] Added Street Fighter II Turbo Hyper Fighting settings --- .../StreetFighterIITurboHyperFighting.cpp | 208 ++++++++++++++++++ .../StreetFighterIITurboHyperFighting.hpp | 48 ++++ 2 files changed, 256 insertions(+) create mode 100644 src/games/supported/StreetFighterIITurboHyperFighting.cpp create mode 100644 src/games/supported/StreetFighterIITurboHyperFighting.hpp diff --git a/src/games/supported/StreetFighterIITurboHyperFighting.cpp b/src/games/supported/StreetFighterIITurboHyperFighting.cpp new file mode 100644 index 0000000..c2919a8 --- /dev/null +++ b/src/games/supported/StreetFighterIITurboHyperFighting.cpp @@ -0,0 +1,208 @@ +#include "../RomUtils.hpp" +#include + +#include "../RomUtils.hpp" +#include "StreetFighterIITurboHyperFighting.hpp" + +#include "RleSystem.hxx" +#include "RleException.h" + +using namespace rle; + + +StreetFighterIITurboHyperFightingSettings::StreetFighterIITurboHyperFightingSettings() { + reset(); + + // TODO + minimalActions = { JOYPAD_NOOP, + JOYPAD_UP, // jump + JOYPAD_DOWN, + JOYPAD_LEFT, + JOYPAD_RIGHT, + JOYPAD_R, // upper-cut + JOYPAD_A, // right Kick + JOYPAD_B, // leftkick + JOYPAD_Y, // left punch + JOYPAD_X, // right punch + JOYPAD_L, //spin-kick + JOYPAD_UP | JOYPAD_RIGHT, // jump right + JOYPAD_UP | JOYPAD_LEFT, // jump left + JOYPAD_DOWN | JOYPAD_Y, + JOYPAD_DOWN | JOYPAD_R, + JOYPAD_DOWN | JOYPAD_L, + JOYPAD_DOWN | JOYPAD_A, + JOYPAD_DOWN | JOYPAD_B, + JOYPAD_DOWN | JOYPAD_X, + + JOYPAD_LEFT | JOYPAD_A, + JOYPAD_RIGHT | JOYPAD_A, + JOYPAD_LEFT | JOYPAD_X, + JOYPAD_RIGHT | JOYPAD_X, + JOYPAD_RIGHT | JOYPAD_Y, + JOYPAD_LEFT | JOYPAD_Y, + JOYPAD_RIGHT | JOYPAD_L, + JOYPAD_LEFT | JOYPAD_L, + JOYPAD_RIGHT | JOYPAD_R, + JOYPAD_LEFT | JOYPAD_R, + JOYPAD_RIGHT | JOYPAD_B, + JOYPAD_LEFT | JOYPAD_B, + }; +} + +/* create a new instance of the rom */ +RomSettings* StreetFighterIITurboHyperFightingSettings::clone() const { + RomSettings* rval = new StreetFighterIITurboHyperFightingSettings(); + *rval = *this; + return rval; +} + +/* process the latest information from RLE */ +void StreetFighterIITurboHyperFightingSettings::step(const RleSystem& system) { + int time = getDecimalScore(0x18f3, &system); + + // update the reward + reward_t playerScore = getDecimalScore(0x6c3,0x6c4, &system); + playerScore *= 100; + + int playerHealth = getDecimalScore(0x0636, &system); + int opponentHealth = getDecimalScore(0x0836, &system); + int healthBalance = (playerHealth - m_health) - (opponentHealth - o_health); + m_health = playerHealth; + o_health = opponentHealth; + + reward_t score = playerScore; + + int scoreBalance = score - m_score; + if ((scoreBalance > 0) && (healthBalance < 0)) + m_reward = healthBalance; + else if ((scoreBalance == 0) && (healthBalance < 0)) + m_reward = healthBalance; + else if ((scoreBalance > 0) && (healthBalance > 0)) + m_reward = scoreBalance + healthBalance; + else if ((scoreBalance == 0) && (healthBalance > 0)) + m_reward = healthBalance; + else // should never happen + m_reward = 0; + // m_reward = score - m_score; + m_score = score; + + if(time == 0x1){ //shai:comparing to 1 not zero to avoid terminal upon first run + m_terminal=true; + } + + m_wins = getDecimalScore(0x5d0, &system); + o_wins = getDecimalScore(0x7d0, &system); + // cout << "player score: " << playerScore << " Time: " + // << time << " p_wins: " << m_wins << " op wins: " <= 6) { + // The character is in the bottom row + startingActions.push_back(JOYPAD_DOWN); + startingActions.push_back(JOYPAD_NOOP); + character_index = character_index - 6 ; + } + for(i = 0; i < character_index; i++) { + startingActions.push_back(JOYPAD_RIGHT); + startingActions.push_back(JOYPAD_NOOP); + } + + startingActions.push_back(JOYPAD_START); + + // Wait for animation to finish + for(i = 0; i<5*num_of_nops; i++){ + startingActions.push_back(JOYPAD_NOOP); + } + + // Skip vs screen + startingActions.push_back(JOYPAD_START); + + // Wait for transition to finish + for(i = 0; i<1*num_of_nops; i++){ + startingActions.push_back(JOYPAD_NOOP); + } + + return startingActions; +} \ No newline at end of file diff --git a/src/games/supported/StreetFighterIITurboHyperFighting.hpp b/src/games/supported/StreetFighterIITurboHyperFighting.hpp new file mode 100644 index 0000000..24caca3 --- /dev/null +++ b/src/games/supported/StreetFighterIITurboHyperFighting.hpp @@ -0,0 +1,48 @@ +#ifndef __STREET_FIGHTER_II_TURBO_HYPER_FIGHTING_SETTINGS_HPP__ +#define __STREET_FIGHTER_II_TURBO_HYPER_FIGHTING_SETTINGS_HPP__ +/* RL wrapper for AtariCollection settings */ + +#include "../SnesSettings.hpp" + +namespace rle { + +struct StreetFighterIITurboHyperFightingSettings : public SnesSettings { + + public: + + StreetFighterIITurboHyperFightingSettings(); + + // reset + virtual void reset(); + + // the rom-name + virtual const char* rom() const { return "street_fighter_ii_turbo_hyper_fighting"; } + + // create a new instance of the rom + virtual RomSettings* clone() const; + + // process the latest information from ALE + virtual void step(const RleSystem& system); + + // saves the state of the rom settings + virtual void saveState( Serializer & ser ); + + // loads the state of the rom settings + virtual void loadState( Deserializer & des ); + + virtual const int lives() { return 0; } + + virtual ActionVect getStartingActions(const RleSystem& system); + + + protected: + int m_wins; + int o_wins; + int m_health; + int o_health; + bool match_ended; +}; + +} // namespace rle + +#endif // __STREET_FIGHTER_II_TURBO_HYPER_FIGHTING_SETTINGS_HPP__ \ No newline at end of file From fa9e49f3a1a4677dfa84d52169b6dade704062f7 Mon Sep 17 00:00:00 2001 From: Diego Celix Date: Thu, 2 Mar 2017 00:15:45 +0100 Subject: [PATCH 02/10] Updated supported roms Added Street Fighter II Turbo Hyper Fighting to the supported roms --- src/games/Roms.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/games/Roms.cpp b/src/games/Roms.cpp index 8e9ad34..ccae758 100644 --- a/src/games/Roms.cpp +++ b/src/games/Roms.cpp @@ -32,6 +32,7 @@ #include "supported/Wolfenstein.hpp" #include "supported/Aladdin.hpp" #include "supported/StreetFighterII.hpp" +#include "supported/StreetFighterIITurboHyperFighting.hpp" #include "supported/BustAMove.hpp" #include "supported/SuperMarioKart.hpp" @@ -175,6 +176,7 @@ static const RomSettings *roms[] = { new WolfensteinSettings(), new AladdinSettings(), new StreetFighterIISettings(), + new StreetFighterIITurboHyperFightingSettings(), new BustAMoveSettings(), // Genesis games new SonicTheHedgehogSettings() From a5f6f9ba3b2b34e21554849cdbb985c9d0dadcf7 Mon Sep 17 00:00:00 2001 From: Diego Celix Date: Thu, 9 Mar 2017 00:10:52 +0100 Subject: [PATCH 03/10] Fix. Identation fixes --- .../StreetFighterIITurboHyperFighting.cpp | 72 +++++++++---------- .../StreetFighterIITurboHyperFighting.hpp | 2 +- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/games/supported/StreetFighterIITurboHyperFighting.cpp b/src/games/supported/StreetFighterIITurboHyperFighting.cpp index c2919a8..771e789 100644 --- a/src/games/supported/StreetFighterIITurboHyperFighting.cpp +++ b/src/games/supported/StreetFighterIITurboHyperFighting.cpp @@ -14,38 +14,38 @@ StreetFighterIITurboHyperFightingSettings::StreetFighterIITurboHyperFightingSett reset(); // TODO - minimalActions = { JOYPAD_NOOP, - JOYPAD_UP, // jump - JOYPAD_DOWN, - JOYPAD_LEFT, - JOYPAD_RIGHT, - JOYPAD_R, // upper-cut - JOYPAD_A, // right Kick - JOYPAD_B, // leftkick - JOYPAD_Y, // left punch - JOYPAD_X, // right punch - JOYPAD_L, //spin-kick - JOYPAD_UP | JOYPAD_RIGHT, // jump right - JOYPAD_UP | JOYPAD_LEFT, // jump left - JOYPAD_DOWN | JOYPAD_Y, - JOYPAD_DOWN | JOYPAD_R, - JOYPAD_DOWN | JOYPAD_L, - JOYPAD_DOWN | JOYPAD_A, - JOYPAD_DOWN | JOYPAD_B, - JOYPAD_DOWN | JOYPAD_X, - - JOYPAD_LEFT | JOYPAD_A, - JOYPAD_RIGHT | JOYPAD_A, - JOYPAD_LEFT | JOYPAD_X, - JOYPAD_RIGHT | JOYPAD_X, - JOYPAD_RIGHT | JOYPAD_Y, - JOYPAD_LEFT | JOYPAD_Y, - JOYPAD_RIGHT | JOYPAD_L, - JOYPAD_LEFT | JOYPAD_L, - JOYPAD_RIGHT | JOYPAD_R, - JOYPAD_LEFT | JOYPAD_R, - JOYPAD_RIGHT | JOYPAD_B, - JOYPAD_LEFT | JOYPAD_B, + minimalActions = { JOYPAD_NOOP, + JOYPAD_UP, + JOYPAD_DOWN, + JOYPAD_LEFT, + JOYPAD_RIGHT, + JOYPAD_R, + JOYPAD_A, + JOYPAD_B, + JOYPAD_Y, + JOYPAD_X, + JOYPAD_L, + JOYPAD_UP | JOYPAD_RIGHT, + JOYPAD_UP | JOYPAD_LEFT, + JOYPAD_DOWN | JOYPAD_Y, + JOYPAD_DOWN | JOYPAD_R, + JOYPAD_DOWN | JOYPAD_L, + JOYPAD_DOWN | JOYPAD_A, + JOYPAD_DOWN | JOYPAD_B, + JOYPAD_DOWN | JOYPAD_X, + + JOYPAD_LEFT | JOYPAD_A, + JOYPAD_RIGHT | JOYPAD_A, + JOYPAD_LEFT | JOYPAD_X, + JOYPAD_RIGHT | JOYPAD_X, + JOYPAD_RIGHT | JOYPAD_Y, + JOYPAD_LEFT | JOYPAD_Y, + JOYPAD_RIGHT | JOYPAD_L, + JOYPAD_LEFT | JOYPAD_L, + JOYPAD_RIGHT | JOYPAD_R, + JOYPAD_LEFT | JOYPAD_R, + JOYPAD_RIGHT | JOYPAD_B, + JOYPAD_LEFT | JOYPAD_B, }; } @@ -60,7 +60,7 @@ RomSettings* StreetFighterIITurboHyperFightingSettings::clone() const { void StreetFighterIITurboHyperFightingSettings::step(const RleSystem& system) { int time = getDecimalScore(0x18f3, &system); - // update the reward + // update the reward reward_t playerScore = getDecimalScore(0x6c3,0x6c4, &system); playerScore *= 100; @@ -87,7 +87,7 @@ void StreetFighterIITurboHyperFightingSettings::step(const RleSystem& system) { m_score = score; if(time == 0x1){ //shai:comparing to 1 not zero to avoid terminal upon first run - m_terminal=true; + m_terminal=true; } m_wins = getDecimalScore(0x5d0, &system); @@ -96,10 +96,10 @@ void StreetFighterIITurboHyperFightingSettings::step(const RleSystem& system) { // << time << " p_wins: " << m_wins << " op wins: " < Date: Thu, 9 Mar 2017 00:12:27 +0100 Subject: [PATCH 04/10] Added support to select character via a settings value --- src/environment/Settings.cxx | 3 + .../StreetFighterIITurboHyperFighting.cpp | 129 ++++++++++++------ .../StreetFighterIITurboHyperFighting.hpp | 4 + 3 files changed, 92 insertions(+), 44 deletions(-) diff --git a/src/environment/Settings.cxx b/src/environment/Settings.cxx index 4695cc2..dce1183 100644 --- a/src/environment/Settings.cxx +++ b/src/environment/Settings.cxx @@ -339,6 +339,9 @@ void Settings::setDefaultSettings() { // Super Mario Kart stringSettings.emplace(std::make_pair("SUPER_MARIO_KART_player1_character", "bowser")); + // Street Fighter 2 Turbo: Hyper Fighting + stringSettings.emplace(std::make_pair("SF2THF_player1_character", "ryu")); + for (map::iterator it = stringSettings.begin(); it != stringSettings.end(); it++) { this->setString(it->first, it->second); diff --git a/src/games/supported/StreetFighterIITurboHyperFighting.cpp b/src/games/supported/StreetFighterIITurboHyperFighting.cpp index 771e789..bf9ee78 100644 --- a/src/games/supported/StreetFighterIITurboHyperFighting.cpp +++ b/src/games/supported/StreetFighterIITurboHyperFighting.cpp @@ -139,70 +139,111 @@ void StreetFighterIITurboHyperFightingSettings::loadState( Deserializer & des ) match_ended = des.getBool(); } -ActionVect StreetFighterIITurboHyperFightingSettings::getStartingActions(const RleSystem& system){ - int i, num_of_nops(100); - ActionVect startingActions; +ActionVect StreetFighterIITurboHyperFightingSettings::selectChar(int character_index){ + ActionVect selectCharActions; - // wait for intro to end - for(i = 0; i<5*num_of_nops; i++){ - startingActions.push_back(JOYPAD_NOOP); - } + if (character_index >= 6) { + // The character is in the bottom row + selectCharActions.push_back(JOYPAD_DOWN); + selectCharActions.push_back(JOYPAD_NOOP); + character_index = character_index - 6 ; + } + for(int i = 0; i < character_index; i++) { + selectCharActions.push_back(JOYPAD_RIGHT); + selectCharActions.push_back(JOYPAD_NOOP); + } - // second animation - startingActions.push_back(JOYPAD_START); + selectCharActions.push_back(JOYPAD_START); - // Wait transition - for(i = 0; i<5*num_of_nops; i++){ - startingActions.push_back(JOYPAD_NOOP); - } + return selectCharActions; +} - // main Screen - startingActions.push_back(JOYPAD_START); +int StreetFighterIITurboHyperFightingSettings::getCharacterIndex(const RleSystem& system){ + int character_index = 0; // Ryu by default + string player1_character = system.settings()->getString("SF2THF_player1_character"); + if("ryu" == player1_character){ + character_index = 0; + }else if("honda" == player1_character){ + character_index = 1; + }else if("blanka" == player1_character){ + character_index = 2; + }else if("guile" == player1_character){ + character_index = 3; + }else if("balrog" == player1_character){ + character_index = 4; + }else if("vega" == player1_character){ + character_index = 5; + }else if("ken" == player1_character){ + character_index = 6; + }else if("chun-li" == player1_character){ + character_index = 7; + }else if("zangief" == player1_character){ + character_index = 8; + }else if("dhalsim" == player1_character){ + character_index = 9; + }else if("sagat" == player1_character){ + character_index = 10; + }else if("bison" == player1_character){ + character_index = 11; + }else{ + throw RleException("SF2THF_player1_character illegal"); + } + return character_index; +} - for(i = 0; i<5*num_of_nops; i++){ - startingActions.push_back(JOYPAD_NOOP); - } +ActionVect StreetFighterIITurboHyperFightingSettings::getStartingActions(const RleSystem& system){ + int i, num_of_nops(100); + ActionVect startingActions; - startingActions.push_back(JOYPAD_START); + // wait for intro to end + for(i = 0; i<5*num_of_nops; i++){ + startingActions.push_back(JOYPAD_NOOP); + } - for(i = 0; i<5*num_of_nops; i++){ - startingActions.push_back(JOYPAD_NOOP); - } + // second animation + startingActions.push_back(JOYPAD_START); - // Start the game - startingActions.push_back(JOYPAD_START); + // Wait transition + for(i = 0; i<5*num_of_nops; i++){ + startingActions.push_back(JOYPAD_NOOP); + } - for(i = 0; i<5*num_of_nops; i++){ - startingActions.push_back(JOYPAD_NOOP); - } + // main Screen + startingActions.push_back(JOYPAD_START); - // Select character by index - int character_index = 0; // Ryu - if (character_index >= 6) { - // The character is in the bottom row - startingActions.push_back(JOYPAD_DOWN); + for(i = 0; i<5*num_of_nops; i++){ startingActions.push_back(JOYPAD_NOOP); - character_index = character_index - 6 ; } - for(i = 0; i < character_index; i++) { - startingActions.push_back(JOYPAD_RIGHT); + + startingActions.push_back(JOYPAD_START); + + for(i = 0; i<5*num_of_nops; i++){ + startingActions.push_back(JOYPAD_NOOP); + } + + // Start the game + startingActions.push_back(JOYPAD_START); + + for(i = 0; i<5*num_of_nops; i++){ startingActions.push_back(JOYPAD_NOOP); - } + } - startingActions.push_back(JOYPAD_START); + // Select character by index + ActionVect selectCharActions = selectChar(getCharacterIndex(system)); + startingActions.insert(startingActions.end(), selectCharActions.begin(), selectCharActions.end()); // Wait for animation to finish - for(i = 0; i<5*num_of_nops; i++){ - startingActions.push_back(JOYPAD_NOOP); - } + for(i = 0; i<5*num_of_nops; i++){ + startingActions.push_back(JOYPAD_NOOP); + } // Skip vs screen startingActions.push_back(JOYPAD_START); // Wait for transition to finish - for(i = 0; i<1*num_of_nops; i++){ - startingActions.push_back(JOYPAD_NOOP); - } + for(i = 0; i<1*num_of_nops; i++){ + startingActions.push_back(JOYPAD_NOOP); + } - return startingActions; + return startingActions; } \ No newline at end of file diff --git a/src/games/supported/StreetFighterIITurboHyperFighting.hpp b/src/games/supported/StreetFighterIITurboHyperFighting.hpp index 8945543..86f08f2 100644 --- a/src/games/supported/StreetFighterIITurboHyperFighting.hpp +++ b/src/games/supported/StreetFighterIITurboHyperFighting.hpp @@ -32,6 +32,10 @@ struct StreetFighterIITurboHyperFightingSettings : public SnesSettings { virtual const int lives() { return 0; } + virtual ActionVect selectChar(int character_index); + + virtual int getCharacterIndex(const RleSystem& system); + virtual ActionVect getStartingActions(const RleSystem& system); From 8f407d16146beb53f16032a4730e49d5c661aebc Mon Sep 17 00:00:00 2001 From: Diego Celix Date: Thu, 9 Mar 2017 00:47:07 +0100 Subject: [PATCH 05/10] Added reward strategy selector via settings param --- src/environment/Settings.cxx | 1 + .../StreetFighterIITurboHyperFighting.cpp | 33 +++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/environment/Settings.cxx b/src/environment/Settings.cxx index dce1183..c7ae901 100644 --- a/src/environment/Settings.cxx +++ b/src/environment/Settings.cxx @@ -341,6 +341,7 @@ void Settings::setDefaultSettings() { // Street Fighter 2 Turbo: Hyper Fighting stringSettings.emplace(std::make_pair("SF2THF_player1_character", "ryu")); + stringSettings.emplace(std::make_pair("SF2THF_reward_strategy", "score")); for (map::iterator it = stringSettings.begin(); it != stringSettings.end(); it++) { diff --git a/src/games/supported/StreetFighterIITurboHyperFighting.cpp b/src/games/supported/StreetFighterIITurboHyperFighting.cpp index bf9ee78..b05ef9b 100644 --- a/src/games/supported/StreetFighterIITurboHyperFighting.cpp +++ b/src/games/supported/StreetFighterIITurboHyperFighting.cpp @@ -66,34 +66,31 @@ void StreetFighterIITurboHyperFightingSettings::step(const RleSystem& system) { int playerHealth = getDecimalScore(0x0636, &system); int opponentHealth = getDecimalScore(0x0836, &system); - int healthBalance = (playerHealth - m_health) - (opponentHealth - o_health); - m_health = playerHealth; - o_health = opponentHealth; reward_t score = playerScore; - int scoreBalance = score - m_score; - if ((scoreBalance > 0) && (healthBalance < 0)) - m_reward = healthBalance; - else if ((scoreBalance == 0) && (healthBalance < 0)) - m_reward = healthBalance; - else if ((scoreBalance > 0) && (healthBalance > 0)) - m_reward = scoreBalance + healthBalance; - else if ((scoreBalance == 0) && (healthBalance > 0)) - m_reward = healthBalance; - else // should never happen - m_reward = 0; - // m_reward = score - m_score; + string rewardStrategy = system.settings()->getString("SF2THF_reward_strategy"); + if("score" == rewardStrategy){ + m_reward = score - m_score; + }else if("health" == rewardStrategy){ + m_reward = playerHealth - m_health; + }else if("healthBalance" == rewardStrategy){ + m_reward = (playerHealth - m_health) - (opponentHealth - o_health); + }else{ + throw RleException("SF2THF_reward_strategy illegal"); + } + + // Update variables + m_health = playerHealth; + o_health = opponentHealth; m_score = score; - if(time == 0x1){ //shai:comparing to 1 not zero to avoid terminal upon first run + if(time == 0x1){ m_terminal=true; } m_wins = getDecimalScore(0x5d0, &system); o_wins = getDecimalScore(0x7d0, &system); - // cout << "player score: " << playerScore << " Time: " - // << time << " p_wins: " << m_wins << " op wins: " < Date: Fri, 10 Mar 2017 01:05:52 +0100 Subject: [PATCH 06/10] Added settings supporting speed select and difficulty --- src/environment/Settings.cxx | 2 + .../StreetFighterIITurboHyperFighting.cpp | 123 +++++++++++++++--- .../StreetFighterIITurboHyperFighting.hpp | 6 + 3 files changed, 115 insertions(+), 16 deletions(-) diff --git a/src/environment/Settings.cxx b/src/environment/Settings.cxx index c7ae901..488faf6 100644 --- a/src/environment/Settings.cxx +++ b/src/environment/Settings.cxx @@ -342,6 +342,8 @@ void Settings::setDefaultSettings() { // Street Fighter 2 Turbo: Hyper Fighting stringSettings.emplace(std::make_pair("SF2THF_player1_character", "ryu")); stringSettings.emplace(std::make_pair("SF2THF_reward_strategy", "score")); + intSettings.emplace(std::make_pair("SF2THF_speed", 3)); + intSettings.emplace(std::make_pair("SF2THF_difficulty", 3)); for (map::iterator it = stringSettings.begin(); it != stringSettings.end(); it++) { diff --git a/src/games/supported/StreetFighterIITurboHyperFighting.cpp b/src/games/supported/StreetFighterIITurboHyperFighting.cpp index b05ef9b..bb1da91 100644 --- a/src/games/supported/StreetFighterIITurboHyperFighting.cpp +++ b/src/games/supported/StreetFighterIITurboHyperFighting.cpp @@ -110,30 +110,35 @@ void StreetFighterIITurboHyperFightingSettings::reset() { m_health = 0; o_health = 0; match_ended = false; + // Avoid resetting m_speed and m_difficulty as the remain across resets. } /* saves the state of the rom settings */ void StreetFighterIITurboHyperFightingSettings::saveState( Serializer & ser ) { - ser.putInt(m_reward); - ser.putInt(m_score); - ser.putInt(m_wins); - ser.putInt(o_wins); - ser.putInt(m_health); - ser.putInt(o_health); - ser.putBool(m_terminal); - ser.putBool(match_ended); + ser.putInt(m_reward); + ser.putInt(m_score); + ser.putInt(m_wins); + ser.putInt(o_wins); + ser.putInt(m_health); + ser.putInt(o_health); + ser.putBool(m_terminal); + ser.putBool(match_ended); + ser.putInt(m_speed); + ser.putInt(m_difficulty); } // loads the state of the rom settings void StreetFighterIITurboHyperFightingSettings::loadState( Deserializer & des ) { - m_reward = des.getInt(); - m_score = des.getInt(); - m_wins = des.getInt(); - o_wins = des.getInt(); - m_health = des.getInt(); - o_health = des.getInt(); - m_terminal = des.getBool(); - match_ended = des.getBool(); + m_reward = des.getInt(); + m_score = des.getInt(); + m_wins = des.getInt(); + o_wins = des.getInt(); + m_health = des.getInt(); + o_health = des.getInt(); + m_terminal = des.getBool(); + match_ended = des.getBool(); + m_speed = des.getInt(); + m_difficulty = des.getInt(); } ActionVect StreetFighterIITurboHyperFightingSettings::selectChar(int character_index){ @@ -188,6 +193,83 @@ int StreetFighterIITurboHyperFightingSettings::getCharacterIndex(const RleSystem return character_index; } +ActionVect StreetFighterIITurboHyperFightingSettings::selectSpeedActions(const RleSystem& system){ + int target_speed = system.settings()->getInt("SF2THF_speed"); + if ((target_speed < 0) || (target_speed > 4)) { + throw RleException("SF2THF_speed illegal. Expected setting value [0 - 4]"); + } + Action action = JOYPAD_NOOP; + ActionVect actions; + if (m_speed < target_speed) { + // Move right + action = JOYPAD_RIGHT; + } else if (m_speed > target_speed) { + // Move left + action = JOYPAD_LEFT; + } + + for(int i = 0; i < abs(m_speed - target_speed); i++){ + actions.push_back(action); + actions.push_back(JOYPAD_NOOP); + } + + m_speed = target_speed; + return actions; +} + +ActionVect StreetFighterIITurboHyperFightingSettings::selectDifficultyActions(const RleSystem& system){ + int target_difficulty = system.settings()->getInt("SF2THF_difficulty"); + if ((target_difficulty < 0) || (target_difficulty > 7)) { + throw RleException("SF2THF_difficulty illegal. Expected setting value [0 - 7]"); + } + Action action = JOYPAD_NOOP; + ActionVect actions; + if (m_difficulty < target_difficulty) { + // Move right + action = JOYPAD_RIGHT; + } else if (m_difficulty > target_difficulty) { + // Move left + action = JOYPAD_LEFT; + } + + actions.push_back(JOYPAD_DOWN); + actions.push_back(JOYPAD_NOOP); + actions.push_back(JOYPAD_DOWN); + actions.push_back(JOYPAD_NOOP); + actions.push_back(JOYPAD_START); + actions.push_back(JOYPAD_NOOP); + + int num_of_nops(100); + ActionVect startingActions; + + // wait for transition to end + for(int i = 0; i<5*num_of_nops; i++){ + actions.push_back(JOYPAD_NOOP); + } + + for(int i = 0; i < abs(m_difficulty - target_difficulty); i++){ + actions.push_back(action); + actions.push_back(JOYPAD_NOOP); + } + + actions.push_back(JOYPAD_START); + + // wait for transition to end + for(int i = 0; i<5*num_of_nops; i++){ + actions.push_back(JOYPAD_NOOP); + } + + actions.push_back(JOYPAD_START); + + // wait for transition to end + for(int i = 0; i<5*num_of_nops; i++){ + actions.push_back(JOYPAD_NOOP); + } + + m_difficulty = target_difficulty; + return actions; +} + ActionVect StreetFighterIITurboHyperFightingSettings::getStartingActions(const RleSystem& system){ int i, num_of_nops(100); ActionVect startingActions; @@ -212,6 +294,15 @@ ActionVect StreetFighterIITurboHyperFightingSettings::getStartingActions(const R startingActions.push_back(JOYPAD_NOOP); } + // Select speed + ActionVect speedActions = selectSpeedActions(system); + startingActions.insert(startingActions.end(), speedActions.begin(), speedActions.end()); + + // Select difficulty + ActionVect difficultyActions = selectDifficultyActions(system); + startingActions.insert(startingActions.end(), difficultyActions.begin(), difficultyActions.end()); + + // Start startingActions.push_back(JOYPAD_START); for(i = 0; i<5*num_of_nops; i++){ diff --git a/src/games/supported/StreetFighterIITurboHyperFighting.hpp b/src/games/supported/StreetFighterIITurboHyperFighting.hpp index 86f08f2..3576a5e 100644 --- a/src/games/supported/StreetFighterIITurboHyperFighting.hpp +++ b/src/games/supported/StreetFighterIITurboHyperFighting.hpp @@ -38,6 +38,10 @@ struct StreetFighterIITurboHyperFightingSettings : public SnesSettings { virtual ActionVect getStartingActions(const RleSystem& system); + virtual ActionVect selectSpeedActions(const RleSystem& system); + + virtual ActionVect selectDifficultyActions(const RleSystem& system); + protected: int m_wins; @@ -45,6 +49,8 @@ struct StreetFighterIITurboHyperFightingSettings : public SnesSettings { int m_health; int o_health; bool match_ended; + int m_speed = 3; // Default speed value. Valid range [0-4] + int m_difficulty = 3; // Default difficulty value. Valid range [0-7] }; } // namespace rle From 0fb2329e68ac4a880c0ae44bb97ce3f6ae1467bd Mon Sep 17 00:00:00 2001 From: Diego Celix Date: Thu, 16 Mar 2017 11:55:24 +0100 Subject: [PATCH 07/10] Avoid terminal state when the time reaches zero Reaching zero time does not mean terminal state. A single fight might reach zero time, meaning that the next round should start. The terminal state, should only be reached by opponent wins. --- src/games/supported/StreetFighterIITurboHyperFighting.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/games/supported/StreetFighterIITurboHyperFighting.cpp b/src/games/supported/StreetFighterIITurboHyperFighting.cpp index bb1da91..4a8587e 100644 --- a/src/games/supported/StreetFighterIITurboHyperFighting.cpp +++ b/src/games/supported/StreetFighterIITurboHyperFighting.cpp @@ -85,10 +85,6 @@ void StreetFighterIITurboHyperFightingSettings::step(const RleSystem& system) { o_health = opponentHealth; m_score = score; - if(time == 0x1){ - m_terminal=true; - } - m_wins = getDecimalScore(0x5d0, &system); o_wins = getDecimalScore(0x7d0, &system); From ef18ba5aac54afa3d1379f99713b321d631642aa Mon Sep 17 00:00:00 2001 From: Diego Celix Date: Thu, 16 Mar 2017 11:58:39 +0100 Subject: [PATCH 08/10] Avoid terminal state when the player wins two fights When the player wins two matches, he will start a fight with the next rival. This is not terminal state as with each rival the difficulty will be increased and it is interesting for the agent to able to reach these states. --- .../StreetFighterIITurboHyperFighting.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/games/supported/StreetFighterIITurboHyperFighting.cpp b/src/games/supported/StreetFighterIITurboHyperFighting.cpp index 4a8587e..cbc8834 100644 --- a/src/games/supported/StreetFighterIITurboHyperFighting.cpp +++ b/src/games/supported/StreetFighterIITurboHyperFighting.cpp @@ -85,12 +85,21 @@ void StreetFighterIITurboHyperFightingSettings::step(const RleSystem& system) { o_health = opponentHealth; m_score = score; - m_wins = getDecimalScore(0x5d0, &system); + int wins = getDecimalScore(0x5d0, &system); o_wins = getDecimalScore(0x7d0, &system); - if (m_wins==2){ - m_terminal = true; + // If the player won, keep waiting until the next fight + + if ((m_wins == 2) && (wins == 0)) { + // When the player has won the fight + // make sure reward is zero when starting the next fight + // TODO check if the reward is zero in the transition between fights + m_reward = 0; } + + m_wins = wins; + + // When the opponent wins then is terminal state. if(o_wins == 2){ m_terminal = true; } From f391a4f4013bb1e091382216e7cdfe86fcc1517c Mon Sep 17 00:00:00 2001 From: Diego Celix Date: Sun, 9 Apr 2017 20:39:58 +0200 Subject: [PATCH 09/10] Fix. Removed warning for unnused variable Variable kept as a comment for future reference. --- src/games/supported/StreetFighterIITurboHyperFighting.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/games/supported/StreetFighterIITurboHyperFighting.cpp b/src/games/supported/StreetFighterIITurboHyperFighting.cpp index cbc8834..e11caca 100644 --- a/src/games/supported/StreetFighterIITurboHyperFighting.cpp +++ b/src/games/supported/StreetFighterIITurboHyperFighting.cpp @@ -58,7 +58,7 @@ RomSettings* StreetFighterIITurboHyperFightingSettings::clone() const { /* process the latest information from RLE */ void StreetFighterIITurboHyperFightingSettings::step(const RleSystem& system) { - int time = getDecimalScore(0x18f3, &system); + //int time = getDecimalScore(0x18f3, &system); // update the reward reward_t playerScore = getDecimalScore(0x6c3,0x6c4, &system); From 0aefa119a7c1c03521027c795b01182d1981dbcd Mon Sep 17 00:00:00 2001 From: Diego Celix Date: Sun, 30 Apr 2017 19:15:03 +0200 Subject: [PATCH 10/10] Added triple key pressed combo to the minimal action set --- .../StreetFighterIITurboHyperFighting.cpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/games/supported/StreetFighterIITurboHyperFighting.cpp b/src/games/supported/StreetFighterIITurboHyperFighting.cpp index e11caca..98c7974 100644 --- a/src/games/supported/StreetFighterIITurboHyperFighting.cpp +++ b/src/games/supported/StreetFighterIITurboHyperFighting.cpp @@ -46,6 +46,34 @@ StreetFighterIITurboHyperFightingSettings::StreetFighterIITurboHyperFightingSett JOYPAD_LEFT | JOYPAD_R, JOYPAD_RIGHT | JOYPAD_B, JOYPAD_LEFT | JOYPAD_B, + + JOYPAD_LEFT | JOYPAD_DOWN | JOYPAD_A, + JOYPAD_LEFT | JOYPAD_DOWN | JOYPAD_B, + JOYPAD_LEFT | JOYPAD_DOWN | JOYPAD_X, + JOYPAD_LEFT | JOYPAD_DOWN | JOYPAD_Y, + JOYPAD_LEFT | JOYPAD_DOWN | JOYPAD_R, + JOYPAD_LEFT | JOYPAD_DOWN | JOYPAD_L, + + JOYPAD_RIGHT | JOYPAD_DOWN | JOYPAD_A, + JOYPAD_RIGHT | JOYPAD_DOWN | JOYPAD_B, + JOYPAD_RIGHT | JOYPAD_DOWN | JOYPAD_X, + JOYPAD_RIGHT | JOYPAD_DOWN | JOYPAD_Y, + JOYPAD_RIGHT | JOYPAD_DOWN | JOYPAD_R, + JOYPAD_RIGHT | JOYPAD_DOWN | JOYPAD_L, + + JOYPAD_LEFT | JOYPAD_UP | JOYPAD_A, + JOYPAD_LEFT | JOYPAD_UP | JOYPAD_B, + JOYPAD_LEFT | JOYPAD_UP | JOYPAD_X, + JOYPAD_LEFT | JOYPAD_UP | JOYPAD_Y, + JOYPAD_LEFT | JOYPAD_UP | JOYPAD_R, + JOYPAD_LEFT | JOYPAD_UP | JOYPAD_L, + + JOYPAD_RIGHT | JOYPAD_UP | JOYPAD_A, + JOYPAD_RIGHT | JOYPAD_UP | JOYPAD_B, + JOYPAD_RIGHT | JOYPAD_UP | JOYPAD_X, + JOYPAD_RIGHT | JOYPAD_UP | JOYPAD_Y, + JOYPAD_RIGHT | JOYPAD_UP | JOYPAD_R, + JOYPAD_RIGHT | JOYPAD_UP | JOYPAD_L, }; }