Skip to content

Commit

Permalink
Merge pull request #32 from mhauskn/master
Browse files Browse the repository at this point in the history
Refactored RomSettings to remove the ActionVects.
  • Loading branch information
mgbellemare committed Feb 22, 2015
2 parents e25878d + 9951ed2 commit ee82663
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/agents/PlayerAgent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class PlayerAgent {
int episode_frame_number;
int episode_number;

ActionVect & available_actions;
ActionVect available_actions;

bool record_trajectory;
ActionVect trajectory;
Expand Down
30 changes: 13 additions & 17 deletions src/games/RomSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,28 @@
*/
#include "RomSettings.hpp"

ActionVect RomSettings::actions;
ActionVect RomSettings::all_actions;

bool RomSettings::isLegal(const Action& a) const {
return true;
}

ActionVect& RomSettings::getMinimalActionSet() {
if (actions.empty()) {
for (int a = 0; a < PLAYER_B_NOOP; a++)
if (isMinimal((Action)a) && isLegal((Action)a))
actions.push_back((Action)a);
ActionVect RomSettings::getMinimalActionSet() {
ActionVect actions;
for (int a = 0; a < PLAYER_B_NOOP; a++) {
if (isMinimal((Action)a) && isLegal((Action)a)) {
actions.push_back((Action)a);
}
}

return actions;
}

ActionVect& RomSettings::getAllActions() {
// Generate the set of all actions
if (all_actions.empty()) {
for (int a = 0; a < PLAYER_B_NOOP; a++)
if (isLegal((Action)a))
all_actions.push_back((Action)a);
ActionVect RomSettings::getAllActions() {
ActionVect actions;
for (int a = 0; a < PLAYER_B_NOOP; a++) {
if (isLegal((Action)a)) {
actions.push_back((Action)a);
}
}

return all_actions;
return actions;
}

ActionVect RomSettings::getStartingActions() {
Expand Down
14 changes: 4 additions & 10 deletions src/games/RomSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,23 @@ struct RomSettings {

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

// loads the state of the rom settings
virtual void loadState(Deserializer & ser) = 0;

// is an action legal (default: yes)
virtual bool isLegal(const Action &a) const;
virtual bool isLegal(const Action &a) const;

// Returns a restricted (minimal) set of actions. If not overriden, this is all actions.
virtual ActionVect &getMinimalActionSet();
virtual ActionVect getMinimalActionSet();

// Returns the set of all legal actions
ActionVect &getAllActions();
ActionVect getAllActions();

// Returns a list of actions that are required to start the game.
// By default this is an empty list.
virtual ActionVect getStartingActions();

protected:
static ActionVect actions;
static ActionVect all_actions;
};


#endif // __ROMSETTINGS_HPP__


0 comments on commit ee82663

Please sign in to comment.