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

Sor2 #35

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open

Sor2 #35

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1ebbdb4
added SOR2 cpp and hpp files
jmichaux Dec 12, 2017
7876ffc
updated Roms.cpp to include SOR2
jmichaux Dec 12, 2017
552791f
updated SOR2 specific settings
jmichaux Dec 12, 2017
627d6d0
updated SOR2 header file
jmichaux Dec 12, 2017
a959ba1
updated Roms.cpp with SOR2
jmichaux Dec 12, 2017
24dbecd
fixed but in Settings.cxx
jmichaux Dec 13, 2017
cae3f75
made changes to facilate testing SOR2
jmichaux Dec 17, 2017
04da36e
changed minimal action list temporarily
jmichaux Dec 17, 2017
32f45cb
more small changes for testing
jmichaux Dec 17, 2017
6825b29
changed code for testing
jmichaux Dec 17, 2017
f0faaf5
more changes to sor2
jmichaux Dec 18, 2017
49652b5
added conditions to make the game as easy as possible
jmichaux Dec 18, 2017
bb189ab
updated SOR2 starting actions
jmichaux Dec 18, 2017
7e8a200
fixed terminal conditions
jmichaux Dec 18, 2017
eed33e1
added game_type setting. will be used for coop/duel gameplay.
jmichaux Dec 18, 2017
e6a5b34
fixed typo
jmichaux Dec 18, 2017
32fb454
changing SOR2 terminal conditions to eliminate unnecessary frames
jmichaux Dec 22, 2017
89293e5
finally finished SOR2
jmichaux Dec 24, 2017
a3c619f
added getExtraActions
jmichaux Dec 24, 2017
edbe32c
renamed SOR2 files
jmichaux Dec 24, 2017
7c66d1d
added SOR2 2 players
jmichaux Dec 24, 2017
0d5f890
updated SOR settings
jmichaux Dec 24, 2017
da6a69d
added SOR2 multiplayer. updated settings to work for SOR1-3.
jmichaux Dec 24, 2017
6030230
adding more SOR stuff
jmichaux Dec 24, 2017
3c0c545
adding SOR3
jmichaux Dec 25, 2017
9d0aa9b
updated SOR2 2 players and fixed SOR3 reset problem
jmichaux Dec 26, 2017
9c845ca
added SOR single and two players
jmichaux Dec 26, 2017
5250cba
finished adding SOR3 two players
jmichaux Dec 26, 2017
c942b67
fixed minimal actions
jmichaux Dec 27, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def run_cmake():
new_dir = op.join(op.split(__file__)[0], 'build')
dd.mkpath(new_dir)
os.chdir(new_dir)
cmake_args = ' -DBUILD_EXAMPLES=OFF -DBUILD_PYTHON=ON'
cmake_args = '-DUSE_SDL=ON -DBUILD_EXAMPLES=OFF -DBUILD_PYTHON=ON'
cores_to_use = max(1, multiprocessing.cpu_count() - 1)

try:
Expand Down
34 changes: 24 additions & 10 deletions src/environment/Settings.cxx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
Expand Down Expand Up @@ -329,19 +329,33 @@ void Settings::setDefaultSettings() {

// Game-Specific Settings

// Mortal Kombat
boolSettings.emplace(std::make_pair("MK_random_position", true));
// Mortal Kombat
boolSettings.emplace(std::make_pair("MK_random_position", false));
stringSettings.emplace(std::make_pair("MK_difficulty", "medium"));
stringSettings.emplace(std::make_pair("MK_player1_character", "cage"));
stringSettings.emplace(std::make_pair("MK_player2_character", "scorpion"));
intSettings.emplace(std::make_pair("MK_opponent_character", 0));

// Super Mario Kart
stringSettings.emplace(std::make_pair("SUPER_MARIO_KART_player1_character", "bowser"));

//Super Double Dragon
stringSettings.emplace(std::make_pair("DDRAGON_reward_strategy", "score"));

// Streets of Rage
boolSettings.emplace(std::make_pair("SOR_verbose", false));
boolSettings.emplace(std::make_pair("SOR_test", false));
intSettings.emplace(std::make_pair("SOR_start_level", 2));
intSettings.emplace(std::make_pair("SOR_end_level", 2));
intSettings.emplace(std::make_pair("SOR_difficulty", 1));
intSettings.emplace(std::make_pair("SOR_lives", 3));
stringSettings.emplace(std::make_pair("SOR_player_1_character", "axel"));
stringSettings.emplace(std::make_pair("SOR_player_2_character", "blaze"));
boolSettings.emplace(std::make_pair("SOR_round_clear", false));
boolSettings.emplace(std::make_pair("SOR_2p_terminal_both_win", true));


// Super Mario Kart
stringSettings.emplace(std::make_pair("SUPER_MARIO_KART_player1_character", "bowser"));

//Super Double Dragon
stringSettings.emplace(std::make_pair("DDRAGON_reward_strategy", "score"));

for (map<string, string>::iterator it = stringSettings.begin();
it != stringSettings.end(); it++) {
this->setString(it->first, it->second);
Expand Down
19 changes: 15 additions & 4 deletions src/environment/retro_environment.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* *****************************************************************************
* A.L.E (Arcade Learning Environment)
* Copyright (c) 2009-2013 by Yavar Naddaf, Joel Veness, Marc G. Bellemare and
* Copyright (c) 2009-2013 by Yavar Naddaf, Joel Veness, Marc G. Bellemare and
* the Reinforcement Learning and Artificial Intelligence Laboratory
* Released under the GNU General Public License; see License.txt for details.
* Released under the GNU General Public License; see License.txt for details.
*
* Based on: Stella -- "An Atari 2600 VCS Emulator"
* Copyright (c) 1995-2007 by Bradford W. Mott and the Stella team
Expand All @@ -12,7 +12,7 @@
*
* A class that wraps around the Stella core to provide users with a typical
* reinforcement learning environment interface.
*
*
**************************************************************************** */

#include "retro_environment.hpp"
Expand Down Expand Up @@ -117,9 +117,21 @@ void RetroEnvironment::reset() {
// m_rlesystem->p_display_screen->display_screen();
}
m_settings->startingOperations(*m_rlesystem);

startingActions = m_settings->getExtraActions(*m_rlesystem);
for (size_t i = 0; i < startingActions.size(); i++){
if((startingActions[i] & PLAYER_B) > 0){
emulateStart(JOYPAD_NOOP, startingActions[i]);
}else{
emulateStart(startingActions[i], PLAYER_B | JOYPAD_NOOP);
}


m_rlesystem->getRetroAgent()->audioEnable(audio);
}

}

/** Save/restore the environment state. */
void RetroEnvironment::save() {
// Store the current state into a new object
Expand Down Expand Up @@ -275,4 +287,3 @@ void RetroEnvironment::processScreen() {
memcpy((uint8_t*)m_screen.getArray() + i*width *Bpp , buffer + i*pitch, width * Bpp);
}
}

8 changes: 5 additions & 3 deletions src/games/RomSettings.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* *****************************************************************************
* A.L.E (Arcade Learning Environment)
* Copyright (c) 2009-2013 by Yavar Naddaf, Joel Veness, Marc G. Bellemare and
* Copyright (c) 2009-2013 by Yavar Naddaf, Joel Veness, Marc G. Bellemare and
* the Reinforcement Learning and Artificial Intelligence Laboratory
* Released under the GNU General Public License; see License.txt for details.
* Released under the GNU General Public License; see License.txt for details.
*
* Based on: Stella -- "An Atari 2600 VCS Emulator"
* Copyright (c) 1995-2007 by Bradford W. Mott and the Stella team
Expand All @@ -29,7 +29,9 @@ ActionVect RomSettings::getStartingActions() {
return ActionVect();
}


ActionVect RomSettings::getExtraActions() {
return ActionVect();
}
ActionVect RomSettings::getMinimalActionSet() {
ActionVect actions;
for (unsigned a = 0; a < AllActionsVector.size(); a++) {
Expand Down
8 changes: 6 additions & 2 deletions src/games/RomSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* *****************************************************************************
* A.L.E (Arcade Learning Environment)
* Copyright (c) 2009-2013 by Yavar Naddaf, Joel Veness, Marc G. Bellemare and
* Copyright (c) 2009-2013 by Yavar Naddaf, Joel Veness, Marc G. Bellemare and
* the Reinforcement Learning and Artificial Intelligence Laboratory
* Released under the GNU General Public License; see License.txt for details.
* Released under the GNU General Public License; see License.txt for details.
*
* Based on: Stella -- "An Atari 2600 VCS Emulator"
* Copyright (c) 1995-2007 by Bradford W. Mott and the Stella team
Expand Down Expand Up @@ -107,6 +107,10 @@ struct RomSettings {
// Optionally perform starting operations such as modifying the game's RAM
virtual void startingOperations(RleSystem& system){};

// Optionall get extra starting actions AFTER modifying the game's RAM
virtual ActionVect getExtraActions();
virtual ActionVect getExtraActions(const RleSystem& system){ return getExtraActions();}

// below functions used to belong to RomUtils
// reads a byte at a memory location
virtual int readRam(const RleSystem* system, int offset);
Expand Down
17 changes: 15 additions & 2 deletions src/games/Roms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@

// genesis games
#include "supported/SonicTheHedgehog.hpp"
#include "supported/StreetsOfRage.hpp"
#include "supported/StreetsOfRage2Players.hpp"
#include "supported/StreetsOfRageII.hpp"
#include "supported/StreetsOfRageII2Players.hpp"
#include "supported/StreetsOfRageIII.hpp"
#include "supported/StreetsOfRageIII2Players.hpp"

// Atari Games
//#include "supported/Breakout.hpp"
Expand Down Expand Up @@ -182,8 +188,15 @@ static const RomSettings *roms[] = {
new AladdinSettings(),
new StreetFighterIISettings(),
new BustAMoveSettings(),
// Genesis games
new SonicTheHedgehogSettings()

//Genesis games
new SonicTheHedgehogSettings(),
new StreetsOfRageSettings(),
new StreetsOfRage2PlayersSettings(),
new StreetsOfRageIISettings(),
new StreetsOfRageII2PlayersSettings(),
new StreetsOfRageIIISettings(),
new StreetsOfRageIII2PlayersSettings(),
};


Expand Down
182 changes: 182 additions & 0 deletions src/games/supported/StreetsOfRage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/* *****************************************************************************
* A.L.E (Arcade Learning Environment)
* Copyright (c) 2009-2013 by Yavar Naddaf, Joel Veness, Marc G. Bellemare and
* the Reinforcement Learning and Artificial Intelligence Laboratory
* Released under the GNU General Public License; see License.txt for details.
*
* Based on: Stella -- "An Atari 2600 VCS Emulator"
* Copyright (c) 1995-2007 by Bradford W. Mott and the Stella team
*
* *****************************************************************************
*/
#include "../RomUtils.hpp"
#include <iomanip>

#include "../RomUtils.hpp"

#include "RleSystem.hxx"
#include "RleException.h"

#include "StreetsOfRage.hpp"
#include <iostream>


using namespace rle;


StreetsOfRageSettings::StreetsOfRageSettings() {
reset();

minimalActions = {JOYPAD_NOOP,
JOYPAD_DOWN, //Walk down
JOYPAD_UP, // Walk up
JOYPAD_LEFT, // Walk left
JOYPAD_RIGHT, // Walk right

JOYPAD_GENESIS_C, // Jump
JOYPAD_GENESIS_C | JOYPAD_LEFT, // Jump left
JOYPAD_GENESIS_C | JOYPAD_RIGHT, // Jump right

JOYPAD_GENESIS_A, // Special attack
JOYPAD_LEFT | JOYPAD_GENESIS_A,
JOYPAD_RIGHT |JOYPAD_GENESIS_A,

JOYPAD_GENESIS_B, // Regular attack
JOYPAD_GENESIS_B | JOYPAD_GENESIS_C, // Rear attack or Super slam
JOYPAD_GENESIS_B | JOYPAD_LEFT,//Blitz attack or
JOYPAD_GENESIS_B | JOYPAD_RIGHT,

};
}


/* create a new instance of the rom */
RomSettings* StreetsOfRageSettings::clone() const {
RomSettings* rval = new StreetsOfRageSettings();
*rval = *this;
return rval;
}


void StreetsOfRageSettings::step(const RleSystem& system) {
// Read out current score, health, lives, stage progress
reward_t score = 0;
reward_t health = readRam(&system, 0xB832);
reward_t screen = readRam(&system, 0xFF00);
reward_t distance = getDecimalScore(0xB810, &system);
m_lives = readRam(&system, 0xFF21);

// update the reward
m_reward = score;

// Update terminal status
if ((m_lives == 0) && (health == 0) && (screen == 22)){
std::cout << "fail" << std::endl;
m_terminal = true;
}

// Get level information
m_current_level = readRam(&system, 0xFF02) + 1;
int m_end_level = system.settings()->getInt("SOR_end_level");

// Update terminal status
if ((m_current_level == m_end_level) && (screen == 24)){
m_terminal=true;
}
}
/* reset the state of the game */
void StreetsOfRageSettings::reset(){
m_reward = 0;
// m_score = 0;
m_terminal = false;
m_distance = 0;
}


/* saves the state of the rom settings */
void StreetsOfRageSettings::saveState( Serializer & ser ) {
ser.putInt(m_reward);
ser.putInt(m_score);
ser.putBool(m_terminal);
}


// loads the state of the rom settings
void StreetsOfRageSettings::loadState( Deserializer & des ) {
m_reward = des.getInt();
m_score = des.getInt();
m_terminal = des.getBool();
}


ActionVect StreetsOfRageSettings::getStartingActions(const RleSystem& system){
int num_of_nops(100);
ActionVect startingActions;

// wait for intro to end
INSERT_NOPS(5*num_of_nops)
INSERT_ACTION_SINGLE_A(JOYPAD_START)
INSERT_NOPS(0.4*num_of_nops)
INSERT_ACTION_SINGLE_A(JOYPAD_START)


// select 1 player
INSERT_NOPS(1*num_of_nops)
INSERT_ACTION_SINGLE_A(JOYPAD_START)
INSERT_NOPS(4*num_of_nops)


// choose character
string player_1_character = system.settings()->getString("SOR_player_1_character");
if("adam" == player_1_character){
INSERT_ACTION_SINGLE_A(JOYPAD_START)
}else if("axel" == player_1_character){
INSERT_ACTION_SINGLE_A(JOYPAD_RIGHT)
INSERT_ACTION_SINGLE_A(JOYPAD_NOOP)
INSERT_ACTION_SINGLE_A(JOYPAD_START)
}else if("blaze" == player_1_character){
INSERT_ACTION_SINGLE_A(JOYPAD_LEFT)
INSERT_ACTION_SINGLE_A(JOYPAD_NOOP)
INSERT_ACTION_SINGLE_A(JOYPAD_START)
}

INSERT_NOPS(0.5 * num_of_nops)

return startingActions;
}



void StreetsOfRageSettings::startingOperations(RleSystem& system){
//set number of lives (Can be 1, 3, 5, or 7)
int num_lives = system.settings()->getInt("SOR_lives");
writeRam(&system, 0xFFCA, ((num_lives - 1) / 2 ) * 0x1);

//set difficulty
int difficulty = system.settings()->getInt("SOR_difficulty");
if(1 == difficulty){
writeRam(&system, 0xFFC6, 0x0);
}else if(2 == difficulty){
writeRam(&system, 0xFFC6, 0x1);
}else if(3 == difficulty){
writeRam(&system, 0xFFC6, 0x2);
}else if(4 == difficulty){
writeRam(&system, 0xFFC6, 0x3);
}

//set start level
int start_level = system.settings()->getInt("SOR_start_level");
writeRam(&system, 0xFF02, (start_level-1)* 0x1);

}

ActionVect StreetsOfRageSettings::getExtraActions(const RleSystem& system){
int num_of_nops(100);
ActionVect startingActions;

// wait for level to begin
INSERT_NOPS(4.5 * num_of_nops)


return startingActions;
}
Loading