-
-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:mwydmuch/ViZDoom
- Loading branch information
Showing
13 changed files
with
798 additions
and
668 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,95 @@ | ||
#!/usr/bin/env python | ||
#!/usr/bin/env python3 | ||
|
||
from __future__ import print_function | ||
|
||
from random import choice | ||
from vizdoom import * | ||
|
||
import vizdoom as vzd | ||
from argparse import ArgumentParser | ||
import cv2 | ||
|
||
game = DoomGame() | ||
DEFAULT_CONFIG = "../../scenarios/defend_the_center.cfg" | ||
|
||
if __name__ == "__main__": | ||
parser = ArgumentParser("ViZDoom example showing how to use the 'automap' (top-down view map).") | ||
parser.add_argument(dest="config", | ||
default=DEFAULT_CONFIG, | ||
nargs="?", | ||
help="Path to the configuration file of the scenario." | ||
" Please see " | ||
"../../scenarios/*cfg for more scenarios.") | ||
|
||
args = parser.parse_args() | ||
game = vzd.DoomGame() | ||
|
||
# Use other config file if you wish. | ||
# game.load_config("../../scenarios/basic.cfg") | ||
# game.load_config("../../scenarios/simpler_basic.cfg") | ||
# game.load_config("../../scenarios/rocket_basic.cfg") | ||
# game.load_config("../../scenarios/deadly_corridor.cfg") | ||
# game.load_config("../../scenarios/deathmatch.cfg") | ||
game.load_config("../../scenarios/defend_the_center.cfg") | ||
# game.load_config("../../scenarios/defend_the_line.cfg") | ||
# game.load_config("../../scenarios/health_gathering.cfg") | ||
# game.load_config("../../scenarios/my_way_home.cfg") | ||
# game.load_config("../../scenarios/predict_position.cfg") | ||
# game.load_config("../../scenarios/take_cover.cfg") | ||
game.set_render_hud(False) | ||
game.load_config(args.config) | ||
game.set_render_hud(False) | ||
|
||
game.set_screen_resolution(ScreenResolution.RES_640X480) | ||
game.set_screen_resolution(vzd.ScreenResolution.RES_640X480) | ||
|
||
# Set cv2 friendly format. | ||
game.set_screen_format(ScreenFormat.BGR24) | ||
# Set cv2 friendly format. | ||
game.set_screen_format(vzd.ScreenFormat.BGR24) | ||
|
||
# Enables rendering of automap. | ||
game.set_automap_buffer_enabled(True) | ||
# Enables rendering of automap. | ||
game.set_automap_buffer_enabled(True) | ||
|
||
# All map's geometry and objects will be displayed. | ||
game.set_automap_mode(AutomapMode.OBJECTS_WITH_SIZE) | ||
# All map's geometry and objects will be displayed. | ||
game.set_automap_mode(vzd.AutomapMode.OBJECTS_WITH_SIZE) | ||
|
||
game.add_available_game_variable(GameVariable.POSITION_X) | ||
game.add_available_game_variable(GameVariable.POSITION_Y) | ||
game.add_available_game_variable(GameVariable.POSITION_Z) | ||
game.add_available_game_variable(vzd.GameVariable.POSITION_X) | ||
game.add_available_game_variable(vzd.GameVariable.POSITION_Y) | ||
game.add_available_game_variable(vzd.GameVariable.POSITION_Z) | ||
|
||
# Disables game window (FPP view), we just want to see the automap. | ||
game.set_window_visible(False) | ||
# Disables game window (FPP view), we just want to see the automap. | ||
game.set_window_visible(False) | ||
|
||
# This CVAR can be used to make a map follow a player. | ||
game.add_game_args("+am_followplayer 1") | ||
# This CVAR can be used to make a map follow a player. | ||
game.add_game_args("+am_followplayer 1") | ||
|
||
# This CVAR controls scale of rendered map (higher valuer means bigger zoom). | ||
game.add_game_args("+viz_am_scale 10") | ||
# This CVAR controls scale of rendered map (higher valuer means bigger zoom). | ||
game.add_game_args("+viz_am_scale 10") | ||
|
||
# This CVAR shows the whole map centered (overrides am_followplayer and viz_am_scale). | ||
game.add_game_args("+viz_am_center 1") | ||
# This CVAR shows the whole map centered (overrides am_followplayer and viz_am_scale). | ||
game.add_game_args("+viz_am_center 1") | ||
|
||
# Map's colors can be changed using CVARs, full list is available here: https://zdoom.org/wiki/CVARs:Automap#am_backcolor | ||
game.add_game_args("+am_backcolor 000000") | ||
game.init() | ||
# Map's colors can be changed using CVARs, full list is available here: https://zdoom.org/wiki/CVARs:Automap#am_backcolor | ||
game.add_game_args("+am_backcolor 000000") | ||
game.init() | ||
|
||
actions = [[True, False, False], [False, True, False], [False, False, True]] | ||
actions = [[True, False, False], [False, True, False], [False, False, True]] | ||
|
||
episodes = 10 | ||
episodes = 10 | ||
|
||
# Sleep time between actions in ms | ||
sleep_time = 28 | ||
# Sleep time between actions in ms | ||
sleep_time = 28 | ||
|
||
for i in range(episodes): | ||
print("Episode #" + str(i + 1)) | ||
seen_in_this_episode = set() | ||
for i in range(episodes): | ||
print("Episode #" + str(i + 1)) | ||
seen_in_this_episode = set() | ||
|
||
# Not needed for the first episode but the loop is nicer. | ||
game.new_episode() | ||
# Not needed for the first episode but the loop is nicer. | ||
game.new_episode() | ||
|
||
while not game.is_episode_finished(): | ||
# Gets the state | ||
state = game.get_state() | ||
while not game.is_episode_finished(): | ||
# Gets the state | ||
state = game.get_state() | ||
|
||
# Shows automap buffer | ||
map = state.automap_buffer | ||
if map is not None: | ||
cv2.imshow('ViZDoom Automap Buffer', map) | ||
# Shows automap buffer | ||
map = state.automap_buffer | ||
if map is not None: | ||
cv2.imshow('ViZDoom Automap Buffer', map) | ||
|
||
cv2.waitKey(sleep_time) | ||
cv2.waitKey(sleep_time) | ||
|
||
game.make_action(choice(actions)) | ||
game.make_action(choice(actions)) | ||
|
||
print("State #" + str(state.number)) | ||
print("Player position X:", state.game_variables[0], "Y:", state.game_variables[1], "Z:", state.game_variables[2]) | ||
print("State #" + str(state.number)) | ||
print("Player position X:", state.game_variables[0], "Y:", state.game_variables[1], "Z:", | ||
state.game_variables[2]) | ||
|
||
print("=====================") | ||
print("=====================") | ||
|
||
print("Episode finished!") | ||
print("Episode finished!") | ||
|
||
print("************************") | ||
print("************************") | ||
|
||
cv2.destroyAllWindows() | ||
cv2.destroyAllWindows() |
Oops, something went wrong.