-
Notifications
You must be signed in to change notification settings - Fork 0
/
ticrate.lua
executable file
·99 lines (78 loc) · 2.31 KB
/
ticrate.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env th
local threads = require 'threads'
local noOfPlayers = 2
local episodes = 10
local pool = threads.Threads(
-- spawned threads
noOfPlayers,
-- Set-up the environment on each thread
function()
-- for some reason 'require' has an unexpected behavior when called
-- from 'threads' to execute a module outside this director.
require "vizdoom"
actions = {
[1] = torch.IntTensor({1,0,0}),
[2] = torch.IntTensor({0,1,0}),
[3] = torch.IntTensor({0,0,1})
}
end,
function()
function player1()
-- Create DoomGame instance.
game = vizdoom.DoomGame()
-- Config
game:loadConfig("../config/basic.cfg")
game:setMode(vizdoom.Mode.ASYNC_PLAYER)
-- Default Doom's ticrate is 35 per second,
-- so this one will work 2 times faster.
game:setTicrate(70)
game:init()
for i = 1, episodes do
game:newEpisode()
print("New episode: ", __threadid)
while not game:isEpisodeFinished() do
-- Make a random action
local action = actions[torch.random(#actions)]
reward = game:makeAction(action)
end
end
game:close()
end
function player2()
-- Create DoomGame instance.
game = vizdoom.DoomGame()
-- Config
game:loadConfig("../config/basic.cfg")
game:setMode(vizdoom.Mode.ASYNC_PLAYER)
-- And this one will work 2 times slower.
game:setTicrate(17)
game:init()
for i = 1, episodes do
game:newEpisode()
print("New episode: ", __threadid)
while not game:isEpisodeFinished() do
-- Make a random action
local action = actions[torch.random(#actions)]
reward = game:makeAction(action)
end
end
game:close()
end
end
)
pool:specific(true)
pool:addjob(
1,
function()
player1()
end
)
pool:addjob(
2,
function()
player2()
end
)
pool:synchronize()
pool:terminate()
print("Done")