forked from njustesen/ViZDoom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcig_bots.py
More file actions
executable file
·82 lines (55 loc) · 2.49 KB
/
cig_bots.py
File metadata and controls
executable file
·82 lines (55 loc) · 2.49 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
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
from __future__ import print_function
from random import choice
from vizdoom import *
game = DoomGame()
game.set_vizdoom_path("../../bin/vizdoom")
# Use CIG example config or your own.
game.load_config("../../examples/config/cig.cfg")
# Select game and map you want to use.
game.set_doom_game_path("../../scenarios/freedoom2.wad")
# game.set_doom_game_path("../../scenarios/doom2.wad") # Not provided with environment due to licences
game.set_doom_map("map01") # Limited deathmatch.
# game.set_doom_map("map02") # Full deathmatch.
# Start multiplayer game only with your AI (with options that will be used in the competition, details in cig_host example).
game.add_game_args("-host 1 -deathmatch +timelimit 2.0 "
"+sv_forcerespawn 1 +sv_noautoaim 1 +sv_respawnprotect 1 +sv_spawnfarthest 1")
# 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.add_game_args("+name AI +colorset 0")
# Multiplayer requires the use of asynchronous modes, but when playing only with bots, synchronous modes can also be used.
game.set_mode(Mode.ASYNC_PLAYER)
# game.set_window_visible(False)
game.init()
# Three example sample actions
actions = [[1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0]]
# Play with this many bots
bots = 7
# Run this many episodes
episodes = 10
for i in range(episodes):
print("Episode #" + str(i + 1))
# Add specific number of bots
# (file examples/bots.cfg must be placed in the same directory as the Doom executable file,
# edit this file to adjust bots).
game.send_game_command("removebots")
for i in range(bots):
game.send_game_command("addbot")
# Play until the game (episode) is over.
while not game.is_episode_finished():
if game.is_player_dead():
# Use this to respawn immediately after death, new state will be available.
game.respawn_player()
# Or observe the game until automatic respawn.
# game.advance_action();
# continue;
s = game.get_state()
# Analyze the state.
game.make_action(choice(actions))
# Make your action.
print("Frags:", game.get_game_variable(GameVariable.FRAGCOUNT))
print("Episode finished.")
print("************************")
# Starts a new episode. All players have to call new_episode() in multiplayer mode.
game.new_episode()
game.close()