forked from njustesen/ViZDoom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspectator.lua
More file actions
executable file
·71 lines (50 loc) · 2.15 KB
/
spectator.lua
File metadata and controls
executable file
·71 lines (50 loc) · 2.15 KB
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
#!/usr/bin/env lua
----------------------------------------------------------------------
-- This script presents SPECTATOR mode. In SPECTATOR mode you play and
-- your agent can learn from it.
-- Configuration is loaded from "../../examples/config/<SCENARIO_NAME>.cfg" file.
--
-- To see the scenario description go to "../../scenarios/README.md"
----------------------------------------------------------------------
require("vizdoom")
game = vizdoom.DoomGame()
-- Choose scenario config file you wish to watch.
-- Don't load two configs cause the second will overrite the first one.
-- Multiple config files are ok but combining these ones doesn't make much sense.
--game:loadConfig("../../examples/config/basic.cfg")
--game:loadConfig("../../examples/config/deadly_corridor.cfg")
game:loadConfig("../../examples/config/deathmatch.cfg")
--game:loadConfig("../../examples/config/defend_the_center.cfg")
--game:loadConfig("../../examples/config/defend_the_line.cfg")
--game:loadConfig("../../examples/config/health_gathering.cfg")
--game:loadConfig("../../examples/config/my_way_home.cfg")
--game:loadConfig("../../examples/config/predict_position.cfg")
--game:loadConfig("../../examples/config/take_cover.cfg")
-- Enables freelook in engine
game:addGameArgs("+freelook 1")
game:setScreenResolution(vizdoom.ScreenResolution.RES_640X480)
-- Enables spectator mode, so you can play. Sounds strange but it is agent who is supposed to watch not you.
game:setWindowVisible(true)
game:setMode(vizdoom.Mode.SPECTATOR)
game:init()
episodes = 10
for i = 1, episodes do
print("Episode #" .. i)
game:newEpisode()
while not game:isEpisodeFinished() do
state = game:getState()
game:advanceAction()
action = game:getLastAction()
reward = game:getLastReward()
print("State # " .. state.number)
print("Reward: " .. reward)
actionStr = "Action:"
for k, a in pairs(action) do actionStr = actionStr .. " " .. a end
print(actionStr)
print("=====================")
end
print("Episode finished.")
print("total reward: " .. game:getTotalReward())
print("************************")
end
game:close()