Skip to content

Commit

Permalink
Merge pull request #24 from dcelix/feature/arkanoid_iii
Browse files Browse the repository at this point in the history
Added Arkanoid III SNES game support
  • Loading branch information
nadavbh12 authored Dec 3, 2017
2 parents 76ac2f9 + 703a5d9 commit 7a60811
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/games/Roms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "supported/SuperMarioKart.hpp"
#include "supported/SuperDoubleDragon.hpp"
#include "supported/ContraIII.hpp"
#include "supported/ArkanoidDohItAgain.hpp"

// genesis games
#include "supported/SonicTheHedgehog.hpp"
Expand Down Expand Up @@ -161,6 +162,7 @@ static const RomSettings *roms[] = {

// SNES games
new AtariCollectionSettings(),
new ArkanoidDohItAgainSettings(),
new ClassicKongSettings(),
new ContraIIISettings(),
new FinalFightSettings(),
Expand Down
124 changes: 124 additions & 0 deletions src/games/supported/ArkanoidDohItAgain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#include "../RomUtils.hpp"
#include <iomanip>

#include "../RomUtils.hpp"
#include "ArkanoidDohItAgain.hpp"

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

using namespace rle;

ArkanoidDohItAgainSettings::ArkanoidDohItAgainSettings() {
reset();

// TODO
minimalActions = { JOYPAD_NOOP,
JOYPAD_LEFT,
JOYPAD_RIGHT,
JOYPAD_A,
JOYPAD_B,
JOYPAD_Y,
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_B,
JOYPAD_LEFT | JOYPAD_B,
};
}

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

/* process the latest information from RLE */
void ArkanoidDohItAgainSettings::step(const RleSystem& system) {

// update the player posiiton
reward_t playerPosition = getDecimalScore(0x1a32, 0x1a33, &system);

//Selecting reward score strategy as the diff with the previous position
reward_t playerScore = playerPosition;

//Reward is positive if the player wins one position
m_reward = playerPosition - m_prevPosition;
m_prevPosition = playerPosition;

m_score = playerScore;

int current_lives = getDecimalScore(0x0168, &system);

if (current_lives == 0)
{
//Reached a terminal state
m_terminal = true;
}
}

/* reset the state of the game */
void ArkanoidDohItAgainSettings::reset() {
m_reward = 0;
m_score = 0;
m_terminal = false;
}

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

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

ActionVect ArkanoidDohItAgainSettings::getStartingActions(const RleSystem& system){
int i, num_of_nops(100);
ActionVect startingActions;
// wait for intro to end
for(i = 0; i<15 * num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}

// second animation
startingActions.push_back(JOYPAD_START);

for(i = 0; i< 1 * num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}

// second animation
startingActions.push_back(JOYPAD_START);

for(i = 0; i<1 * num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}

// Selecting 1 player mode
startingActions.push_back(JOYPAD_START);

for(i = 0; i<5 * num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}

// Jump Intro
startingActions.push_back(JOYPAD_START);

for(i = 0; i<1 * num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}

return startingActions;
}

44 changes: 44 additions & 0 deletions src/games/supported/ArkanoidDohItAgain.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef __ARKANOID_DOH_IT_AGAIN_SETTINGS_HPP__
#define __ARKANOID_DOH_IT_AGAIN_SETTINGS_HPP__
/* RL wrapper for AtariCollection settings */

#include "../SnesSettings.hpp"

namespace rle {

struct ArkanoidDohItAgainSettings : public SnesSettings {

public:

ArkanoidDohItAgainSettings();

// reset
virtual void reset();

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

// 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_lives = 3;
int m_prevPosition = 0; //previous position
};

} // namespace rle

#endif // __ARKANOID_DOH_IT_AGAIN_SETTINGS_HPP__

0 comments on commit 7a60811

Please sign in to comment.