forked from Farama-Foundation/ViZDoom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cig_singleplayer_host.py
executable file
·105 lines (80 loc) · 3.48 KB
/
cig_singleplayer_host.py
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
100
101
102
103
104
105
#!/usr/bin/env python3
#####################################################################
# This script presents how to host a singleplayer game
# with scenario generated by PyOblige map generator.
# https://github.com/mwydmuch/PyOblige
#####################################################################
from __future__ import print_function
from random import choice
from time import sleep
from vizdoom import *
from oblige import *
game = DoomGame()
# Use your config
game.load_config("../../scenarios/cig.cfg")
game.set_doom_map("map01")
game.set_doom_skill(3)
# Create Doom Level Generator instance and set optional seed.
generator = DoomLevelGenerator()
# There are few predefined sets of settings already defined in Oblige package for CIG competition
generator.set_config(cig2018_test)
generator.set_config(cig2018_difficulty_1) # aka childs_play_wad
#generator.set_config(cig2018_difficulty_2) # aka painless_wad
#generator.set_config(cig2018_difficulty_3) # aka too_young_to_die_wad
#generator.set_config(cig2018_difficulty_4) # aka no_sweat_wad
#generator.set_config(cig2018_difficulty_5) # aka easy_wad
# Tell generator to generate few maps (options for "length": "single", "few", "episode", "game").
generator.set_config({"length": "few"})
# Generate method will return number of maps inside wad file.
wad_path = "cig_singleplayer.wad"
maps = generator.generate(wad_path)
# Set Scenario to the new generated WAD
game.set_doom_scenario_path(wad_path)
game.add_game_args("-host 2 "
# This machine will function as a host for a singleplayer game with host as spectator and player.
# It will wait for player's machine to connect using the -join parameter and then start the game.
"-skill 3 " # The game will run on normal difficulty setting
"+timelimit 10.0 " # The game (episode) will end after this many minutes have elapsed.
"+sv_forcerespawn 1 " # Players will respawn automatically after they die.
"+sv_noautoaim 1 " # Autoaim is disabled for all players.
"+sv_nocrouch 1 ") # Disables crouching.
game.add_game_args("+name Host")
# Host will only be a spectator of singleplayer game.
game.add_game_args("+viz_spectator 1")
# Sets up game for spectator (you)
game.add_game_args("+freelook 1")
game.set_screen_resolution(ScreenResolution.RES_640X480)
game.set_window_visible(True)
#game.set_mode(Mode.SPECTATOR)
game.set_mode(Mode.ASYNC_SPECTATOR)
game.init()
# Play as many episodes as maps in the new generated WAD file.
episodes = maps
# Play until the game (episode) is over.
for i in range(1, episodes + 1):
print("Map {}/{}".format(i, episodes))
time = 0
while not game.is_episode_finished():
time = game.get_episode_time()
state = game.get_state()
game.advance_action()
last_action = game.get_last_action()
reward = game.get_last_reward()
print("State #" + str(state.number))
print("Game variables: ", state.game_variables)
print("Action:", last_action)
print("Reward:", reward)
print("=====================")
print("Episode finished!")
print("Time:", time / 35, "s")
print("************************")
sleep(1.0)
# Set next map
map = "map{:02}".format(i + 1)
game.set_doom_map(map)
game.new_episode()
game.close()
# Remove output of generator
os.remove(wad_path)
os.remove(wad_path.replace("wad", "old"))
os.remove(wad_path.replace("wad", "txt"))