forked from Farama-Foundation/ViZDoom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.lua
executable file
·77 lines (59 loc) · 2.31 KB
/
seed.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env th
--------------------------------------------------------------------------------
-- Seed example
-- This script presents how to run deterministic episodes by setting
-- seed. After setting the seed every episode will look the same (if
-- agent will behave deterministicly of course).
-- Config is loaded from "../../scenarios/<SCENARIO_NAME>.cfg" file.
-- <episodes> number of episodes are played.
-- Random combination of buttons is chosen for every action.
-- Game variables from state and last reward are printed.
-- To see the scenario description go to "../../scenarios/README.md"
--------------------------------------------------------------------------------
require "vizdoom"
require "torch"
local game = vizdoom.DoomGame()
game:loadConfig("../../scenarios/basic.cfg")
-- game:loadConfig("../../scenarios/deadly_corridor.cfg")
-- game:loadConfig("../../scenarios/defend_the_center.cfg")
-- game:loadConfig("../../scenarios/defend_the_line.cfg")
-- game:loadConfig("../../scenarios/health_gathering.cfg")
-- game:loadConfig("../../scenarios/my_way_home.cfg")
-- game:loadConfig("../../scenarios/predict_position.cfg")
-- Lets make episode shorter and observe starting position of Cacodemon.
game:setEpisodeTimeout(50)
game:setScreenResolution(vizdoom.ScreenResolution.RES_640X480)
local seed = 666 -- Appropriate seed for Doom.
game:setSeed(seed) -- It can be changed after init.
game:init()
-- Three example sample actions
local actions = {
[1] = torch.IntTensor({1,0,0}),
[2] = torch.IntTensor({0,1,0}),
[3] = torch.IntTensor({0,0,1})
}
local episodes = 10
local sleepTime = 0.028
-- To be used by the main game loop
local state, reward
for i=1, episodes do
print("Episode #"..i)
-- Seed can be changed anytime. It will take effect from next episodes.
-- game.set_seed(seed)
game:newEpisode()
while not game:isEpisodeFinished() do
state = game:getState()
-- Make a random action
local action = actions[torch.random(#actions)]
reward = game:makeAction(action)
print("Seed:", game:getSeed())
if sleepTime > 0 then
sys.sleep(sleepTime)
end
end
-- Check how the episode went.
print("Episode finished.")
print("total reward:", game:getTotalReward())
print("************************")
end
game:close()