forked from Farama-Foundation/ViZDoom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shaping.lua
executable file
·62 lines (42 loc) · 1.46 KB
/
shaping.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env th
require "vizdoom"
require "torch"
-- Create DoomGame instance. It will run the game and communicate with you.
local game = vizdoom.DoomGame()
game:loadConfig("../../scenarios/health_gathering.cfg")
game:setViZDoomPath("../../bin/vizdoom")
game:setScreenResolution(vizdoom.ScreenResolution.RES_640X480)
game:init()
-- Define actions
local actions = {
[1] = torch.IntTensor({1,0,0}),
[2] = torch.IntTensor({0,1,0}),
[3] = torch.IntTensor({0,0,1})
}
lastTotalShapingReward = 0
local episodes = 10
for i = 1, 10 do
print("Episode #" .. i .. "\n")
game:newEpisode()
while not game:isEpisodeFinished() do
-- Get the state.
local state = game:getState()
local action = actions[torch.random(#actions)]
local reward = game:makeAction(action)
local _ssr = game:getGameVariable(vizdoom.GameVariable.USER1)
local ssr = vizdoom.doomFixedToNumber(_ssr)
local sr = ssr - lastTotalShapingReward
lastTotalShapingReward = ssr;
print("State #" .. state.number)
print("Healt: ", state.gameVariables[1])
print("Action reward: ", reward);
print("Action shaping reward: ", sr);
print("=====================")
end
print("Episode finished.\n")
print("Total reward: " .. game:getTotalReward() .. "\n")
print("************************\n")
end
-- It will be done automatically in destructor but after close You can
-- init it again with different settings.
game:close()