ale_ruby_interface 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ale.cfg +11 -0
- data/lib/ale_ruby_interface.rb +186 -88
- data/lib/libale_c.so +0 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 460fc42c858e6b2e6e280e3aef39ce81597e49ca
|
4
|
+
data.tar.gz: e096cd1c6227c663e3ff24f7b661586b8d09bdb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94f1348040a3e64c02d6b00fb3b2788b649df46b446cbdcb891bc898c6c105096d12546f7be66e5f76494e53838019723fe708907b4588d6b9996fc3f1764504
|
7
|
+
data.tar.gz: 650dbc2e4916accbfd91ee4283146881b4efe9831cd442ab308ca7e1d621e3cac3b9b41e3959075c1f626ba4936ed5c333069103a2e137ad44d90e843eb6ecca
|
data/lib/ale.cfg
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Use this file to set default options for ALE.
|
2
|
+
# One setting per line.
|
3
|
+
# Format: option-name=option-value
|
4
|
+
#
|
5
|
+
# Example.
|
6
|
+
#
|
7
|
+
# cpu=low
|
8
|
+
# repeat_action_probability=0.25
|
9
|
+
#
|
10
|
+
# Note that, for the Python and C++ interface, these options are set when the interface is
|
11
|
+
# first created (i.e. within ALEInterface's constructor), and not when the ROM is loaded.
|
data/lib/ale_ruby_interface.rb
CHANGED
@@ -1,78 +1,91 @@
|
|
1
1
|
require 'ffi'
|
2
2
|
require 'nmatrix'
|
3
|
+
require 'fileutils'
|
3
4
|
|
4
5
|
module ALELib
|
5
6
|
extend FFI::Library
|
6
|
-
ffi_lib '/Users/happybai/Arcade-Learning-Environment/ale_python_interface/libale_c.so'
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
attach_function :
|
11
|
-
attach_function :
|
12
|
-
attach_function :
|
13
|
-
attach_function :
|
14
|
-
attach_function :
|
15
|
-
attach_function :
|
16
|
-
attach_function :
|
17
|
-
attach_function :
|
18
|
-
attach_function :
|
19
|
-
attach_function :
|
20
|
-
attach_function :
|
21
|
-
attach_function :
|
22
|
-
attach_function :
|
23
|
-
attach_function :
|
24
|
-
attach_function :
|
25
|
-
attach_function :
|
26
|
-
attach_function :
|
27
|
-
attach_function :
|
28
|
-
attach_function :
|
29
|
-
attach_function :
|
30
|
-
attach_function :
|
31
|
-
attach_function :
|
32
|
-
attach_function :
|
33
|
-
attach_function :
|
34
|
-
attach_function :
|
35
|
-
attach_function :
|
36
|
-
attach_function :
|
37
|
-
attach_function :
|
38
|
-
attach_function :
|
39
|
-
attach_function :
|
40
|
-
attach_function :
|
41
|
-
attach_function :
|
42
|
-
attach_function :
|
43
|
-
attach_function :
|
44
|
-
attach_function :
|
45
|
-
attach_function :
|
46
|
-
attach_function :
|
47
|
-
attach_function :
|
48
|
-
attach_function :
|
49
|
-
attach_function :
|
50
|
-
attach_function :
|
51
|
-
attach_function :
|
52
|
-
attach_function :
|
7
|
+
# ffi_lib '/Users/happybai/Arcade-Learning-Environment/ale_python_interface/libale_c.so'
|
8
|
+
# ffi_lib File.expand_path(File.join(File.dirname(__FILE__), "lib", "libale_c.so"))
|
9
|
+
# ffi_lib './lib/libale_c.so'
|
10
|
+
ffi_lib File.join(File.dirname(__FILE__), "libale_c.so")
|
11
|
+
attach_function :ALE_new, [], :pointer
|
12
|
+
attach_function :ALE_del, [:pointer], :pointer
|
13
|
+
attach_function :getString, [:pointer, :string], :string
|
14
|
+
attach_function :getInt, [:pointer, :string], :int
|
15
|
+
attach_function :getBool, [:pointer, :string], :bool
|
16
|
+
attach_function :getFloat, [:pointer, :string], :float
|
17
|
+
attach_function :setString, [:pointer, :string, :string], :pointer
|
18
|
+
attach_function :setInt, [:pointer, :string, :int], :pointer
|
19
|
+
attach_function :setBool, [:pointer, :string, :bool], :pointer
|
20
|
+
attach_function :setFloat, [:pointer, :string, :float], :pointer
|
21
|
+
attach_function :loadROM, [:pointer, :string], :pointer
|
22
|
+
attach_function :act, [:pointer, :int], :long
|
23
|
+
attach_function :game_over, [:pointer], :bool
|
24
|
+
attach_function :reset_game, [:pointer], :pointer
|
25
|
+
attach_function :getAvailableModes, [:pointer, :pointer], :pointer
|
26
|
+
attach_function :getAvailableModesSize, [:pointer], :int
|
27
|
+
attach_function :setMode, [:pointer, :int], :pointer
|
28
|
+
attach_function :getAvailableDifficulties, [:pointer, :pointer], :pointer
|
29
|
+
attach_function :getAvailableDifficultiesSize, [:pointer], :int
|
30
|
+
attach_function :setDifficulty, [:pointer, :int], :pointer
|
31
|
+
attach_function :getLegalActionSet, [:pointer, :pointer], :pointer
|
32
|
+
attach_function :getLegalActionSize, [:pointer], :int
|
33
|
+
attach_function :getMinimalActionSet, [:pointer, :pointer], :pointer
|
34
|
+
attach_function :getMinimalActionSize, [:pointer], :int
|
35
|
+
attach_function :getFrameNumber, [:pointer], :int
|
36
|
+
attach_function :lives, [:pointer], :int
|
37
|
+
attach_function :getEpisodeFrameNumber, [:pointer], :int
|
38
|
+
attach_function :getScreen, [:pointer, :pointer], :pointer
|
39
|
+
attach_function :getRAM, [:pointer, :pointer], :pointer
|
40
|
+
attach_function :getRAMSize, [:pointer], :int
|
41
|
+
attach_function :getScreenWidth, [:pointer], :int
|
42
|
+
attach_function :getScreenHeight, [:pointer], :int
|
43
|
+
attach_function :getScreenRGB, [:pointer, :pointer], :pointer
|
44
|
+
attach_function :getScreenGrayscale, [:pointer, :pointer], :pointer
|
45
|
+
attach_function :saveState, [:pointer], :pointer
|
46
|
+
attach_function :loadState, [:pointer], :pointer
|
47
|
+
attach_function :cloneState, [:pointer], :pointer
|
48
|
+
attach_function :restoreState, [:pointer, :pointer], :pointer
|
49
|
+
attach_function :cloneSystemState, [:pointer], :pointer
|
50
|
+
attach_function :restoreSystemState, [:pointer, :pointer], :pointer
|
51
|
+
attach_function :deleteState, [:pointer], :pointer
|
52
|
+
attach_function :saveScreenPNG, [:pointer, :string], :pointer
|
53
|
+
attach_function :encodeState, [:pointer, :pointer, :int], :pointer
|
54
|
+
attach_function :encodeStateLen, [:pointer], :int
|
55
|
+
attach_function :decodeState, [:pointer, :int], :pointer
|
56
|
+
attach_function :setLoggerMode, [:int], :pointer
|
53
57
|
end
|
54
58
|
|
55
59
|
class ALEInterface
|
56
|
-
# include ALELib
|
57
|
-
|
58
60
|
def initialize
|
61
|
+
# setup config file manually
|
62
|
+
# ale_path = ENV['ale_path'] || '/Users/happybai/Arcade-Learning-Environment'
|
63
|
+
# base_path = "#{Dir.pwd}/lib"
|
64
|
+
# Dir.chdir base_path
|
65
|
+
src = File.join(File.dirname(__FILE__), "ale.cfg")
|
66
|
+
dest = './ale.cfg'
|
67
|
+
if !File.exist?('./ale.cfg')
|
68
|
+
FileUtils.cp(src, dest)
|
69
|
+
puts "Created ale.cfg successfully"
|
70
|
+
end
|
59
71
|
@obj = ALELib.ALE_new
|
72
|
+
# Dir.chdir base_path
|
60
73
|
end
|
61
74
|
|
62
75
|
def get_string(key)
|
63
|
-
|
76
|
+
ALELib.getString(@obj, key)
|
64
77
|
end
|
65
78
|
|
66
79
|
def get_int(key)
|
67
|
-
|
80
|
+
ALELib.getInt(@obj, key)
|
68
81
|
end
|
69
82
|
|
70
83
|
def get_bool(key)
|
71
|
-
|
84
|
+
ALELib.getBool(@obj, key)
|
72
85
|
end
|
73
86
|
|
74
87
|
def get_float(key)
|
75
|
-
|
88
|
+
ALELib.getFloat(@obj, key)
|
76
89
|
end
|
77
90
|
|
78
91
|
def set_string(key, value)
|
@@ -91,16 +104,16 @@ class ALEInterface
|
|
91
104
|
ALELib.setFloat(@obj, key, value)
|
92
105
|
end
|
93
106
|
|
94
|
-
def
|
107
|
+
def load_ROM(rom_file)
|
95
108
|
ALELib.loadROM(@obj, rom_file)
|
96
109
|
end
|
97
110
|
|
98
111
|
def act(action)
|
99
|
-
|
112
|
+
ALELib.act(@obj, action.to_i)
|
100
113
|
end
|
101
114
|
|
102
115
|
def game_over
|
103
|
-
|
116
|
+
ALELib.game_over(@obj)
|
104
117
|
end
|
105
118
|
|
106
119
|
def reset_game
|
@@ -109,90 +122,175 @@ class ALEInterface
|
|
109
122
|
|
110
123
|
def get_legal_action_set
|
111
124
|
act_size = ALELib.getLegalActionSize(@obj)
|
112
|
-
act = NMatrix.zeros[act_size]
|
113
|
-
|
114
|
-
|
125
|
+
act = NMatrix.zeros [act_size]
|
126
|
+
FFI::MemoryPointer.new(:int, act.size) do |p|
|
127
|
+
p.put_array_of_int(0, act)
|
128
|
+
ALELib.getLegalActionSet(@obj, p)
|
129
|
+
return p.read_array_of_int(act_size)
|
130
|
+
end
|
115
131
|
end
|
116
132
|
|
117
133
|
def get_minimal_action_set
|
134
|
+
act_size = ALELib.getMinimalActionSize(@obj)
|
135
|
+
act = NMatrix.zeros [act_size]
|
136
|
+
FFI::MemoryPointer.new(:int, act.size) do |p|
|
137
|
+
p.put_array_of_int(0, act)
|
138
|
+
ALELib.getMinimalActionSet(@obj, p)
|
139
|
+
return p.read_array_of_int(act_size)
|
140
|
+
end
|
118
141
|
end
|
119
142
|
|
120
143
|
def get_available_modes
|
144
|
+
modes_size = ALELib.getAvailableModesSize(@obj)
|
145
|
+
modes = NMatrix.zeros [modes_size]
|
146
|
+
FFI::MemoryPointer.new(:int, modes.size) do |p|
|
147
|
+
p.put_array_of_int(0, modes)
|
148
|
+
ALELib.getAvailableModes(@obj, p)
|
149
|
+
return p.read_array_of_int(modes_size)
|
150
|
+
end
|
121
151
|
end
|
122
152
|
|
123
|
-
def set_mode
|
124
|
-
|
125
|
-
|
126
|
-
def get_available_difficuties
|
127
|
-
end
|
128
|
-
|
129
|
-
def set_difficulty
|
153
|
+
def set_mode(mode)
|
154
|
+
ALELib.set_mode(@obj, mode)
|
130
155
|
end
|
131
156
|
|
132
|
-
def
|
157
|
+
def get_available_difficulties
|
158
|
+
difficulties_size = ALELib.getAvailableDifficultiesSize(@obj)
|
159
|
+
difficulties = NMatrix.zeros [difficulties_size]
|
160
|
+
FFI::MemoryPointer.new(:int, difficulties.size) do |p|
|
161
|
+
p.put_array_of_int(0, difficulties)
|
162
|
+
ALELib.getAvailableDifficulties(@obj, p)
|
163
|
+
return p.read_array_of_int(difficulties_size)
|
164
|
+
end
|
133
165
|
end
|
134
166
|
|
135
|
-
def
|
167
|
+
def set_difficulty(difficulty)
|
168
|
+
ALELib.set_mode(@obj, difficulty)
|
136
169
|
end
|
137
170
|
|
138
171
|
def get_frame_number
|
172
|
+
ALELib.getFrameNumber(@obj)
|
139
173
|
end
|
140
174
|
|
141
175
|
def lives
|
176
|
+
ALELib.lives(@obj)
|
142
177
|
end
|
143
178
|
|
144
179
|
def get_episode_frame_number
|
180
|
+
ALELib.getEpisodeFrameNumber(@obj)
|
145
181
|
end
|
146
182
|
|
147
183
|
def get_screen_dims
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
end
|
152
|
-
|
153
|
-
def
|
154
|
-
|
155
|
-
|
156
|
-
|
184
|
+
width = ALELib.getScreenWidth(@obj)
|
185
|
+
height = ALELib.getScreenHeight(@obj)
|
186
|
+
{ width: width, height: height }
|
187
|
+
end
|
188
|
+
|
189
|
+
def get_screen(screen_data = nil)
|
190
|
+
# This function fills screen_data with the RAW Pixel data
|
191
|
+
width = ALELib.getScreenWidth(@obj)
|
192
|
+
height = ALELib.getScreenHeight(@obj)
|
193
|
+
size = width * height
|
194
|
+
FFI::MemoryPointer.new(:uint8, size) do |p|
|
195
|
+
ALELib.getScreen(@obj, p)
|
196
|
+
return NMatrix.new(
|
197
|
+
[width * height],
|
198
|
+
p.read_array_of_uint8(size),
|
199
|
+
dtype: :int16
|
200
|
+
)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def get_screen_RGB()
|
205
|
+
# This function fills screen_data with the data in RGB format
|
206
|
+
width = ALELib.getScreenWidth(@obj)
|
207
|
+
height = ALELib.getScreenHeight(@obj)
|
208
|
+
size = width * height * 3
|
209
|
+
FFI::MemoryPointer.new(:uint8, size) do |p|
|
210
|
+
ALELib.getScreenRGB(@obj, p)
|
211
|
+
return NMatrix.new(
|
212
|
+
[width, height, 3],
|
213
|
+
p.read_array_of_uint8(size),
|
214
|
+
dtype: :int16
|
215
|
+
)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def get_screen_grayscale(screen_data = nil)
|
220
|
+
width = ALELib.getScreenWidth(@obj)
|
221
|
+
height = ALELib.getScreenHeight(@obj)
|
222
|
+
size = width * height * 1
|
223
|
+
FFI::MemoryPointer.new(:uint8, size) do |p|
|
224
|
+
ALELib.getScreenGrayscale(@obj, p)
|
225
|
+
return NMatrix.new(
|
226
|
+
[width, height, 1],
|
227
|
+
p.read_array_of_uint8(size),
|
228
|
+
dtype: :int16
|
229
|
+
)
|
230
|
+
end
|
157
231
|
end
|
158
232
|
|
159
233
|
def get_RAM_size
|
234
|
+
ALELib.getRAMSize(@obj)
|
160
235
|
end
|
161
236
|
|
162
|
-
def get_RAM
|
237
|
+
def get_RAM()
|
238
|
+
ram_size = ALELib.getRAMSize(@obj)
|
239
|
+
FFI::MemoryPointer.new(:uint64, ram_size) do |p|
|
240
|
+
ALELib.getRAM(@obj, p)
|
241
|
+
return NMatrix.new(
|
242
|
+
[ram_size],
|
243
|
+
p.read_array_of_uint8(ram_size),
|
244
|
+
dtype: :int16
|
245
|
+
)
|
246
|
+
end
|
163
247
|
end
|
164
248
|
|
165
|
-
def save_screen_PNG
|
249
|
+
def save_screen_PNG(filename)
|
250
|
+
return ALELib.saveScreenPNG(@obj, filename)
|
166
251
|
end
|
167
252
|
|
168
253
|
def save_state
|
254
|
+
return ALELib.saveState(@obj)
|
169
255
|
end
|
170
256
|
|
171
257
|
def load_state
|
258
|
+
return ALELib.loadState(@obj)
|
172
259
|
end
|
173
260
|
|
174
261
|
def clone_state
|
262
|
+
# This makes a copy of the environment state. This copy does *not*
|
263
|
+
# include pseudorandomness, making it suitable for planning
|
264
|
+
# purposes. By contrast, see cloneSystemState.
|
265
|
+
return ALELib.cloneState(@obj)
|
175
266
|
end
|
176
267
|
|
177
|
-
def restore_state
|
268
|
+
def restore_state(state)
|
269
|
+
ALELib.restoreState(@obj, state)
|
178
270
|
end
|
179
271
|
|
180
272
|
def clone_system_state
|
273
|
+
return ALELib.cloneSystemState(@obj)
|
181
274
|
end
|
182
275
|
|
183
276
|
def restore_system_state
|
277
|
+
ALELib.restoreSystemState(@obj)
|
184
278
|
end
|
185
279
|
|
186
|
-
def delete_state
|
280
|
+
def delete_state(state)
|
281
|
+
ALELib.deleteState(state)
|
187
282
|
end
|
188
283
|
|
189
|
-
def encode_state_len
|
284
|
+
def encode_state_len(state)
|
285
|
+
return ALELib.encodeStateLen(state)
|
190
286
|
end
|
191
287
|
|
192
|
-
|
193
|
-
end
|
194
|
-
|
195
|
-
def decode_state
|
196
|
-
end
|
288
|
+
# TBD
|
289
|
+
def encode_state; end
|
290
|
+
|
291
|
+
def decode_state; end
|
197
292
|
|
198
|
-
|
293
|
+
private
|
294
|
+
|
295
|
+
def as_types; end
|
296
|
+
end
|
data/lib/libale_c.so
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ale_ruby_interface
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Byron Bai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: '0.2'
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 0.2.
|
42
|
+
version: 0.2.4
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: '0.2'
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: 0.2.
|
52
|
+
version: 0.2.4
|
53
53
|
description: This directly implements a ruby version of the arcade learning environment
|
54
54
|
interface.
|
55
55
|
email: byron.bai@aol.com
|
@@ -57,7 +57,9 @@ executables: []
|
|
57
57
|
extensions: []
|
58
58
|
extra_rdoc_files: []
|
59
59
|
files:
|
60
|
+
- lib/ale.cfg
|
60
61
|
- lib/ale_ruby_interface.rb
|
62
|
+
- lib/libale_c.so
|
61
63
|
homepage: http://rubygems.org/gems/ale_ruby_interface
|
62
64
|
licenses:
|
63
65
|
- MIT
|