Skip to content

Commit

Permalink
added aladdin, street fighter2 and bust-a-move
Browse files Browse the repository at this point in the history
  • Loading branch information
shairoz committed Feb 16, 2017
1 parent 4cb7bd0 commit 38d86fa
Show file tree
Hide file tree
Showing 7 changed files with 639 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/games/Roms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include "supported/TetrisAndDrMario.hpp"
#include "supported/Boxing.hpp"
#include "supported/Wolfenstein.hpp"
#include "supported/Aladdin.hpp"
#include "supported/StreetFighterII.hpp"
#include "supported/BustAMove.hpp"

// genesis games
#include "supported/SonicTheHedgehog.hpp"
Expand Down Expand Up @@ -168,12 +171,15 @@ static const RomSettings *roms[] = {
new SuperMarioWorldSettings(),
new TetrisAndDrMarioSettings(),
new WolfensteinSettings(),

new AladdinSettings(),
new StreetFighterIISettings(),
new BustAMoveSettings(),
// Genesis games
new SonicTheHedgehogSettings()
};



/* looks for the RL wrapper corresponding to a particular rom title */
RomSettings *rle::buildRomRLWrapper(const std::string &rom, bool twoPlayers) {

Expand Down
132 changes: 132 additions & 0 deletions src/games/supported/Aladdin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/* *****************************************************************************
* 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 "Aladdin.hpp"

using namespace rle;


AladdinSettings::AladdinSettings() {
reset();

minimalActions = { JOYPAD_NOOP,
JOYPAD_UP, // only relavent when hanging
JOYPAD_DOWN, //duck
JOYPAD_LEFT,
JOYPAD_RIGHT,
JOYPAD_B, // Jump
JOYPAD_B | JOYPAD_RIGHT, // jump right
JOYPAD_B | JOYPAD_LEFT, // jump left
JOYPAD_Y | JOYPAD_RIGHT, // Run right
JOYPAD_Y | JOYPAD_LEFT, // Run left
JOYPAD_A, //throw apple
JOYPAD_A | JOYPAD_B, // Jump
JOYPAD_A | JOYPAD_B | JOYPAD_RIGHT, // jump right
JOYPAD_A | JOYPAD_B | JOYPAD_LEFT, // jump left, // jump & Shoot
};
}


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


/* process the latest information from ALE */
void AladdinSettings::step(const RleSystem& system) {
// update the reward
reward_t playerScore = 256*readRam(&system, 0xF411) + readRam(&system, 0xF410); //based solely on moving right
reward_t healthBonus = m_health - readRam(&system, 0x366); // adding health bonus to discourage getting hit
int apples = readRam(&system, 0x368);
int dimonds = readRam(&system, 0x36a);
playerScore += healthBonus;
int current_lives = readRam(&system, 0x363)-1;
m_reward = playerScore - m_score;
m_score = playerScore;
if( current_lives != m_lives) { //adding "previous lives" since lives=0 until game starts
m_prev_lives = m_lives;
}
m_lives = current_lives;
m_health = readRam(&system, 0x366);

// cout <<"Score is: " << playerScore << " Health is: " << m_health << " lives are: " << m_lives << " m_prev_lives " << m_prev_lives<<endl;

if ((m_prev_lives == 1) && (m_lives == 0) && (m_health == 0)){ //lives doesn't reach 0, condition is last life and no health
m_terminal = true;
}

}


/* reset the state of the game */
void AladdinSettings::reset() {

m_reward = 0;
m_score = 0;
m_health = 3;
m_lives = 3;
m_prev_lives = 3;

m_terminal = false;
}



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

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


ActionVect AladdinSettings::getStartingActions(){
int i, num_of_nops(100);
ActionVect startingActions;

// wait for intro to end
for(i = 0; i<5*num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}
// main Screen
startingActions.push_back(JOYPAD_START);
// wait for character select screen
for(i = 0; i<3.5*num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}
//start game
startingActions.push_back(JOYPAD_START);

for(i = 0; i<3.5*num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}
//start game
startingActions.push_back(JOYPAD_START);
return startingActions;
}

73 changes: 73 additions & 0 deletions src/games/supported/Aladdin.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* *****************************************************************************
* The line 67 is based on Xitari's code, from Google Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* 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
* 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
*
* *****************************************************************************
*/

#ifndef __ALADDIN_SETTINGS_HPP__
#define __ALADDIN_SETTINGS_HPP__
/* RL wrapper for AtariCollection settings */

#include "../SnesSettings.hpp"
#include <unordered_set>

namespace rle {

class AladdinSettings : public SnesSettings {

public:

AladdinSettings();

// reset
void reset();

// the rom-name
const char* rom() const { return "aladdin"; }

// create a new instance of the rom
RomSettings* clone() const;

// process the latest information from ALE
void step(const RleSystem& system);

// saves the state of the rom settings
void saveState( Serializer & ser );

// loads the state of the rom settings
void loadState( Deserializer & des );

virtual const int lives() { return 0; }

virtual ActionVect getStartingActions();

private:
int m_lives;
int m_prev_lives;
int m_health;
};

} // namespace rle

#endif // __ALADDIN_SETTINGS_HPP__
113 changes: 113 additions & 0 deletions src/games/supported/BustAMove.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* *****************************************************************************
* 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 "BustAMove.hpp"

using namespace rle;


BustAMoveSettings::BustAMoveSettings() {
reset();

minimalActions = { JOYPAD_NOOP,
JOYPAD_LEFT,
JOYPAD_RIGHT,
JOYPAD_A, //shoot
};
}


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


/* process the latest information from ALE */
void BustAMoveSettings::step(const RleSystem& system) {
// update the reward
reward_t playerScore = getDecimalScore(0x954,0x955,0x956, &system);

m_reward = playerScore - m_score;
m_score = playerScore;
// cout << "Score: " << playerScore<<endl;
// update terminal status
int isAlive = readRam(&system, 0x906);
if (isAlive > 0){
m_terminal = true;
}
}


/* reset the state of the game */
void BustAMoveSettings::reset() {

m_reward = 0;
m_score = 0;
m_terminal = false;
}



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

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


ActionVect BustAMoveSettings::getStartingActions(){
int i, num_of_nops(100);
ActionVect startingActions;

// wait for intro to end
for(i = 0; i<2*num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}
// main Screen
startingActions.push_back(JOYPAD_START);
// wait for character select screen
for(i = 0; i<2*num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}
//start game
startingActions.push_back(JOYPAD_START);

for(i = 0; i<2*num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}
//start game
startingActions.push_back(JOYPAD_START);
for(i = 0; i<2*num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}
//start game
startingActions.push_back(JOYPAD_START);

return startingActions;
}


Loading

0 comments on commit 38d86fa

Please sign in to comment.