#include "SirLancelot.hpp"
#include "../RomUtils.hpp"
namespace ale {
SirLancelotSettings::SirLancelotSettings() { reset(); }
RomSettings* SirLancelotSettings::clone() const {
RomSettings* rval = new SirLancelotSettings();
*rval = *this;
return rval;
}
void SirLancelotSettings::step(const System& system) {
int score = getDecimalScore(0xA0, 0x9F, 0x9E, &system);
int reward = score - m_score;
m_reward = reward;
m_score = score;
m_lives = readRam(&system, 0xA9);
m_terminal = (m_lives == 0) && readRam(&system, 0xA7) == 0xA0;
}
bool SirLancelotSettings::isTerminal() const { return m_terminal; };
reward_t SirLancelotSettings::getReward() const { return m_reward; }
bool SirLancelotSettings::isMinimal(const Action& a) const {
switch (a) {
case PLAYER_A_NOOP:
case PLAYER_A_FIRE:
case PLAYER_A_RIGHT:
case PLAYER_A_LEFT:
case PLAYER_A_RIGHTFIRE:
case PLAYER_A_LEFTFIRE:
return true;
default:
return false;
}
}
void SirLancelotSettings::reset() {
m_reward = 0;
m_score = 0;
m_terminal = false;
m_lives = 3;
}
void SirLancelotSettings::saveState(Serializer& ser) {
ser.putInt(m_reward);
ser.putInt(m_score);
ser.putBool(m_terminal);
ser.putInt(m_lives);
}
void SirLancelotSettings::loadState(Deserializer& ser) {
m_reward = ser.getInt();
m_score = ser.getInt();
m_terminal = ser.getBool();
m_lives = ser.getInt();
}
ActionVect SirLancelotSettings::getStartingActions() {
ActionVect startingActions;
startingActions.push_back(RESET);
startingActions.push_back(PLAYER_A_LEFT);
return startingActions;
}
}