-
Notifications
You must be signed in to change notification settings - Fork 0
/
cig.lua
executable file
·65 lines (48 loc) · 1.75 KB
/
cig.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
#!/usr/bin/env th
require "vizdoom"
require "torch"
-- Check arguments for a host's ip.
local ip = "127.0.0.1"
for a = 1, #arg do
if arg[a] == "-ip" and type(arg[a + 1]) == "string" then
ip = arg[a + 1]
end
end
-- Create DoomGame instance. It will run the game and communicate with you.
local game = vizdoom.DoomGame()
-- Use CIG example config or your own.
game:loadConfig("../../scenarios/cig.cfg")
-- Select game and map you want to use.
game:setDoomMap("map01") -- Limited deathmatch.
--game:setDoomMap("map02") -- Full deathmatch.
-- Join existing game.
game:addGameArgs("-join " .. ip) -- Connect to a host for a multiplayer game.
-- Name your agent and select color
-- colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
game:addGameArgs("+name AI +colorset 0")
game:setMode(vizdoom.Mode.ASYNC_PLAYER) -- During the competition, async mode will be forced for all agents.
--game:setWindowVisible(false)
game:init();
-- Three example sample actions
local actions = {
[1] = torch.IntTensor({1,0,0,0,0,0,0,0,0}),
[2] = torch.IntTensor({0,1,0,0,0,0,0,0,0}),
[3] = torch.IntTensor({0,0,1,0,0,0,0,0,0})
}
-- To be used by the main game loop
local state, reward
-- Play until the game (episode) is over.
while not game:isEpisodeFinished() do
-- Analyze the state
state = game:getState()
-- Make a random action
local action = actions[torch.random(#actions)]
local reward = game:makeAction(action)
-- Check if player is dead
if game:isPlayerDead() then
-- Respawn immediately after death, new state will be available.
game:respawnPlayer()
end
--print("Frags:", game:getGameVariable(vizdoom.GameVariable.FRAGCOUNT))
end
game:close()