-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.lua
39 lines (29 loc) · 893 Bytes
/
example.lua
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
require 'image'
package.path = './?/init.lua;' .. package.path
local alewrap = require 'alewrap'
local function parseArgs()
local cmd = torch.CmdLine()
cmd:option('-rom', 'roms/pong.bin', 'ROM to use')
return cmd:parse(arg)
end
local function main()
local options = parseArgs()
-- Starting the env.
local env = alewrap.createEnv(options.rom, {})
local observations = env:envStart()
local reward
local win = nil
while true do
-- Displaying the atari screen.
local obs = observations[1]
win = image.display({image=env:getRgbFromPalette(obs), win=win})
-- Taking an action.
local action = torch.random(0, 17)
local actions = {torch.Tensor({action})}
reward, observations = env:envStep(actions)
if reward ~= 0 then
print("reward:", reward)
end
end
end
main()