Class: ALEInterface
- Inherits:
-
Object
- Object
- ALEInterface
- Defined in:
- lib/ale_ruby_interface.rb
Instance Method Summary collapse
- #act(action) ⇒ Object
- #clone_state ⇒ Object
- #clone_system_state ⇒ Object
- #decode_state ⇒ Object
- #delete_state(state) ⇒ Object
-
#encode_state ⇒ Object
TBD.
- #encode_state_len(state) ⇒ Object
- #game_over ⇒ Object
- #get_available_difficulties ⇒ Object
- #get_available_modes ⇒ Object
- #get_bool(key) ⇒ Object
- #get_episode_frame_number ⇒ Object
- #get_float(key) ⇒ Object
- #get_frame_number ⇒ Object
- #get_int(key) ⇒ Object
- #get_legal_action_set ⇒ Object
- #get_minimal_action_set ⇒ Object
- #get_RAM ⇒ Object
- #get_RAM_size ⇒ Object
- #get_screen(screen_data = nil) ⇒ Object
- #get_screen_dims ⇒ Object
- #get_screen_grayscale(screen_data = nil) ⇒ Object
- #get_screen_RGB ⇒ Object
- #get_string(key) ⇒ Object
-
#initialize ⇒ ALEInterface
constructor
A new instance of ALEInterface.
- #lives ⇒ Object
- #load_ROM(rom_file) ⇒ Object
- #load_state ⇒ Object
- #reset_game ⇒ Object
- #restore_state(state) ⇒ Object
- #restore_system_state ⇒ Object
- #save_screen_PNG(filename) ⇒ Object
- #save_state ⇒ Object
- #set_bool(key, value) ⇒ Object
- #set_difficulty(difficulty) ⇒ Object
- #set_float(key, value) ⇒ Object
- #set_int(key, value) ⇒ Object
- #set_mode(mode) ⇒ Object
- #set_string(key, value) ⇒ Object
Constructor Details
#initialize ⇒ ALEInterface
Returns a new instance of ALEInterface.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ale_ruby_interface.rb', line 60 def initialize # setup config file manually # ale_path = ENV['ale_path'] || '/Users/happybai/Arcade-Learning-Environment' # base_path = "#{Dir.pwd}/lib" # Dir.chdir base_path src = File.join(File.dirname(__FILE__), "ale.cfg") dest = './ale.cfg' if !File.exist?('./ale.cfg') FileUtils.cp(src, dest) puts "Created ale.cfg successfully" end @obj = ALELib.ALE_new # Dir.chdir base_path end |
Instance Method Details
#act(action) ⇒ Object
111 112 113 |
# File 'lib/ale_ruby_interface.rb', line 111 def act(action) ALELib.act(@obj, action.to_i) end |
#clone_state ⇒ Object
261 262 263 264 265 266 |
# File 'lib/ale_ruby_interface.rb', line 261 def clone_state # This makes a copy of the environment state. This copy does *not* # include pseudorandomness, making it suitable for planning # purposes. By contrast, see cloneSystemState. return ALELib.cloneState(@obj) end |
#clone_system_state ⇒ Object
272 273 274 |
# File 'lib/ale_ruby_interface.rb', line 272 def clone_system_state return ALELib.cloneSystemState(@obj) end |
#decode_state ⇒ Object
291 |
# File 'lib/ale_ruby_interface.rb', line 291 def decode_state; end |
#delete_state(state) ⇒ Object
280 281 282 |
# File 'lib/ale_ruby_interface.rb', line 280 def delete_state(state) ALELib.deleteState(state) end |
#encode_state ⇒ Object
TBD
289 |
# File 'lib/ale_ruby_interface.rb', line 289 def encode_state; end |
#encode_state_len(state) ⇒ Object
284 285 286 |
# File 'lib/ale_ruby_interface.rb', line 284 def encode_state_len(state) return ALELib.encodeStateLen(state) end |
#game_over ⇒ Object
115 116 117 |
# File 'lib/ale_ruby_interface.rb', line 115 def game_over ALELib.game_over(@obj) end |
#get_available_difficulties ⇒ Object
157 158 159 160 161 162 163 164 165 |
# File 'lib/ale_ruby_interface.rb', line 157 def get_available_difficulties difficulties_size = ALELib.getAvailableDifficultiesSize(@obj) difficulties = NMatrix.zeros [difficulties_size] FFI::MemoryPointer.new(:int, difficulties.size) do |p| p.put_array_of_int(0, difficulties) ALELib.getAvailableDifficulties(@obj, p) return p.read_array_of_int(difficulties_size) end end |
#get_available_modes ⇒ Object
143 144 145 146 147 148 149 150 151 |
# File 'lib/ale_ruby_interface.rb', line 143 def get_available_modes modes_size = ALELib.getAvailableModesSize(@obj) modes = NMatrix.zeros [modes_size] FFI::MemoryPointer.new(:int, modes.size) do |p| p.put_array_of_int(0, modes) ALELib.getAvailableModes(@obj, p) return p.read_array_of_int(modes_size) end end |
#get_bool(key) ⇒ Object
83 84 85 |
# File 'lib/ale_ruby_interface.rb', line 83 def get_bool(key) ALELib.getBool(@obj, key) end |
#get_episode_frame_number ⇒ Object
179 180 181 |
# File 'lib/ale_ruby_interface.rb', line 179 def get_episode_frame_number ALELib.getEpisodeFrameNumber(@obj) end |
#get_float(key) ⇒ Object
87 88 89 |
# File 'lib/ale_ruby_interface.rb', line 87 def get_float(key) ALELib.getFloat(@obj, key) end |
#get_frame_number ⇒ Object
171 172 173 |
# File 'lib/ale_ruby_interface.rb', line 171 def get_frame_number ALELib.getFrameNumber(@obj) end |
#get_int(key) ⇒ Object
79 80 81 |
# File 'lib/ale_ruby_interface.rb', line 79 def get_int(key) ALELib.getInt(@obj, key) end |
#get_legal_action_set ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'lib/ale_ruby_interface.rb', line 123 def get_legal_action_set act_size = ALELib.getLegalActionSize(@obj) act = NMatrix.zeros [act_size] FFI::MemoryPointer.new(:int, act.size) do |p| p.put_array_of_int(0, act) ALELib.getLegalActionSet(@obj, p) return p.read_array_of_int(act_size) end end |
#get_minimal_action_set ⇒ Object
133 134 135 136 137 138 139 140 141 |
# File 'lib/ale_ruby_interface.rb', line 133 def get_minimal_action_set act_size = ALELib.getMinimalActionSize(@obj) act = NMatrix.zeros [act_size] FFI::MemoryPointer.new(:int, act.size) do |p| p.put_array_of_int(0, act) ALELib.getMinimalActionSet(@obj, p) return p.read_array_of_int(act_size) end end |
#get_RAM ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/ale_ruby_interface.rb', line 237 def get_RAM() ram_size = ALELib.getRAMSize(@obj) FFI::MemoryPointer.new(:uint64, ram_size) do |p| ALELib.getRAM(@obj, p) return NMatrix.new( [ram_size], p.read_array_of_uint8(ram_size), dtype: :int16 ) end end |
#get_RAM_size ⇒ Object
233 234 235 |
# File 'lib/ale_ruby_interface.rb', line 233 def get_RAM_size ALELib.getRAMSize(@obj) end |
#get_screen(screen_data = nil) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/ale_ruby_interface.rb', line 189 def get_screen(screen_data = nil) # This function fills screen_data with the RAW Pixel data width = ALELib.getScreenWidth(@obj) height = ALELib.getScreenHeight(@obj) size = width * height FFI::MemoryPointer.new(:uint8, size) do |p| ALELib.getScreen(@obj, p) return NMatrix.new( [width * height], p.read_array_of_uint8(size), dtype: :int16 ) end end |
#get_screen_dims ⇒ Object
183 184 185 186 187 |
# File 'lib/ale_ruby_interface.rb', line 183 def get_screen_dims width = ALELib.getScreenWidth(@obj) height = ALELib.getScreenHeight(@obj) { width: width, height: height } end |
#get_screen_grayscale(screen_data = nil) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/ale_ruby_interface.rb', line 219 def get_screen_grayscale(screen_data = nil) width = ALELib.getScreenWidth(@obj) height = ALELib.getScreenHeight(@obj) size = width * height * 1 FFI::MemoryPointer.new(:uint8, size) do |p| ALELib.getScreenGrayscale(@obj, p) return NMatrix.new( [width, height, 1], p.read_array_of_uint8(size), dtype: :int16 ) end end |
#get_screen_RGB ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/ale_ruby_interface.rb', line 204 def get_screen_RGB() # This function fills screen_data with the data in RGB format width = ALELib.getScreenWidth(@obj) height = ALELib.getScreenHeight(@obj) size = width * height * 3 FFI::MemoryPointer.new(:uint8, size) do |p| ALELib.getScreenRGB(@obj, p) return NMatrix.new( [width, height, 3], p.read_array_of_uint8(size), dtype: :int16 ) end end |
#get_string(key) ⇒ Object
75 76 77 |
# File 'lib/ale_ruby_interface.rb', line 75 def get_string(key) ALELib.getString(@obj, key) end |
#lives ⇒ Object
175 176 177 |
# File 'lib/ale_ruby_interface.rb', line 175 def lives ALELib.lives(@obj) end |
#load_ROM(rom_file) ⇒ Object
107 108 109 |
# File 'lib/ale_ruby_interface.rb', line 107 def load_ROM(rom_file) ALELib.loadROM(@obj, rom_file) end |
#load_state ⇒ Object
257 258 259 |
# File 'lib/ale_ruby_interface.rb', line 257 def load_state return ALELib.loadState(@obj) end |
#reset_game ⇒ Object
119 120 121 |
# File 'lib/ale_ruby_interface.rb', line 119 def reset_game ALELib.game_over(@obj) end |
#restore_state(state) ⇒ Object
268 269 270 |
# File 'lib/ale_ruby_interface.rb', line 268 def restore_state(state) ALELib.restoreState(@obj, state) end |
#restore_system_state ⇒ Object
276 277 278 |
# File 'lib/ale_ruby_interface.rb', line 276 def restore_system_state ALELib.restoreSystemState(@obj) end |
#save_screen_PNG(filename) ⇒ Object
249 250 251 |
# File 'lib/ale_ruby_interface.rb', line 249 def save_screen_PNG(filename) return ALELib.saveScreenPNG(@obj, filename) end |
#save_state ⇒ Object
253 254 255 |
# File 'lib/ale_ruby_interface.rb', line 253 def save_state return ALELib.saveState(@obj) end |
#set_bool(key, value) ⇒ Object
99 100 101 |
# File 'lib/ale_ruby_interface.rb', line 99 def set_bool(key, value) ALELib.setBool(@obj, key, value) end |
#set_difficulty(difficulty) ⇒ Object
167 168 169 |
# File 'lib/ale_ruby_interface.rb', line 167 def set_difficulty(difficulty) ALELib.set_mode(@obj, difficulty) end |
#set_float(key, value) ⇒ Object
103 104 105 |
# File 'lib/ale_ruby_interface.rb', line 103 def set_float(key, value) ALELib.setFloat(@obj, key, value) end |
#set_int(key, value) ⇒ Object
95 96 97 |
# File 'lib/ale_ruby_interface.rb', line 95 def set_int(key, value) ALELib.setInt(@obj, key, value) end |
#set_mode(mode) ⇒ Object
153 154 155 |
# File 'lib/ale_ruby_interface.rb', line 153 def set_mode(mode) ALELib.set_mode(@obj, mode) end |
#set_string(key, value) ⇒ Object
91 92 93 |
# File 'lib/ale_ruby_interface.rb', line 91 def set_string(key, value) ALELib.setString(@obj, key, value) end |