-
Notifications
You must be signed in to change notification settings - Fork 40
/
SuperMarioWorld.cpp
158 lines (132 loc) · 4.34 KB
/
SuperMarioWorld.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* *****************************************************************************
* 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 "SuperMarioWorld.hpp"
#include "RleSystem.hxx"
using namespace rle;
SuperMarioWorldSettings::SuperMarioWorldSettings() {
reset();
minimalActions = { JOYPAD_NOOP,
JOYPAD_UP, // look up
JOYPAD_DOWN,
JOYPAD_LEFT,
JOYPAD_RIGHT,
JOYPAD_R, // move slightly right
JOYPAD_L, // move slightly left
JOYPAD_A, // spin jump
JOYPAD_B, // standard jump
JOYPAD_Y, // run/pick-up shell/open door...
JOYPAD_B | JOYPAD_RIGHT, // jump right
JOYPAD_B | JOYPAD_LEFT, // jump left
JOYPAD_A | JOYPAD_RIGHT, // jump right
JOYPAD_A | JOYPAD_LEFT, // jump left
JOYPAD_SELECT, // drop stock item
// samve as above while running
JOYPAD_Y | JOYPAD_LEFT,
JOYPAD_Y | JOYPAD_RIGHT,
JOYPAD_Y | JOYPAD_B | JOYPAD_RIGHT,
JOYPAD_Y | JOYPAD_B | JOYPAD_LEFT,
JOYPAD_Y | JOYPAD_A | JOYPAD_RIGHT,
JOYPAD_Y | JOYPAD_A | JOYPAD_LEFT,
};
m_lastTime = {-1, -1, -1};
}
/* create a new instance of the rom */
RomSettings* SuperMarioWorldSettings::clone() const {
RomSettings* rval = new SuperMarioWorldSettings();
*rval = *this;
return rval;
}
/* process the latest information from ALE */
void SuperMarioWorldSettings::step(const RleSystem& system) {
int time = getDecimalScoreWords({0xf33, 0xf32, 0xf31}, &system);
// DEBUG2("time: " << std::dec << time);
m_lastTime.erase(m_lastTime.begin());
m_lastTime.push_back(readRam(&system, 0xf30));
// update the reward
reward_t score = 10 * getDecimalScoreWords({0xf34, 0xf35, 0xf36}, &system);
m_reward = score - m_score;
m_score = score;
if(time == 0x1){ //shai:comparing to 1 not zero to avoid terminal upon first run
m_terminal=true;
}
else{ // check if the timer has stopped
if ( (0 < time && time < 300) && (std::adjacent_find( m_lastTime.begin(), m_lastTime.end(), std::not_equal_to<int>() ) == m_lastTime.end()) ){
m_terminal=true;
}
}
}
/* reset the state of the game */
void SuperMarioWorldSettings::reset() {
m_reward = 0;
m_score = 0;
m_terminal = false;
}
/* saves the state of the rom settings */
void SuperMarioWorldSettings::saveState( Serializer & ser ) {
ser.putInt(m_reward);
ser.putInt(m_score);
ser.putBool(m_terminal);
}
// loads the state of the rom settings
void SuperMarioWorldSettings::loadState( Deserializer & des ) {
m_reward = des.getInt();
m_score = des.getInt();
m_terminal = des.getBool();
}
ActionVect SuperMarioWorldSettings::getStartingActions(){
int i, num_of_nops(100);
ActionVect startingActions;
// startingActions.reserve(num_of_xs*num_of_nops);
// wait for intro to end
for(i = 0; i<3*num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}
startingActions.push_back(JOYPAD_B);
for(i = 0; i<0.3*num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}
// // select first save slot
startingActions.push_back(JOYPAD_B);
for(i = 0; i<0.3*num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}
// select 1 player
startingActions.push_back(JOYPAD_B);
for(i = 0; i<0.3*num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}
// wait for text to end
for(i = 0; i<10*num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}
startingActions.push_back(JOYPAD_B);
// wait for text to end
for(i = 0; i<2*num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}
// select level
startingActions.push_back(JOYPAD_LEFT);
for(i = 0; i<1.5*num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}
// start level
startingActions.push_back(JOYPAD_B);
// wait for level to load
startingActions.push_back(JOYPAD_LEFT);
for(i = 0; i<2*num_of_nops; i++){
startingActions.push_back(JOYPAD_NOOP);
}
return startingActions;
}