Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save OlegJakushkin/8e6d04e55532b08b67f2dd1ba6e1a017 to your computer and use it in GitHub Desktop.
Save OlegJakushkin/8e6d04e55532b08b67f2dd1ba6e1a017 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#####################################################################
# python -m pip install --upgrade pip
# pip install -U numpy
#####################################################################
from __future__ import print_function
from random import choice
from vizdoom import *
import cv2
import numpy
game = DoomGame()
game.load_config("basic.cfg")
#game.set_window_visible(False)
# This is most fun. It looks best if you inverse colors.
#game.set_screen_format(ScreenFormat.CBCGCRDB)
game.set_screen_format(ScreenFormat.DEPTH_BUFFER8)
game.set_screen_resolution(ScreenResolution.RES_640X480)
game.init()
episodes = 10
# sleep time in ms
sleep_time = 20
for i in range(episodes):
print("Episode #" + str(i + 1))
# Not needed for the first episdoe but the loop is nicer.
game.new_episode()
while not game.is_episode_finished():
#todo: detect objects http://docs.opencv.org/3.1.0/dd/d49/tutorial_py_contour_features.html#gsc.tab=0
#todo: compose voxel map with walls and objects https://pyscience.wordpress.com/2014/11/16/volume-rendering-with-python-and-vtk/
#todo: find path
# Gets the state and possibly to something with it
s = game.get_state()
img = s.image_buffer.copy()
misc = s.game_variables
#img = img.reshape(img.shape[1], img.shape[2], 1)
#if game.get_screen_format() in [ScreenFormat.GRAY8, ScreenFormat.DEPTH_BUFFER8]:
img = img.reshape(img.shape[1], img.shape[2], 1)
# Display the image here!
cv2.imshow('Doom Buffer', img)
#cv2.imwrite("test.png", d)
cv2.waitKey(sleep_time)
# Makes a random action and save the reward.
r = game.make_action([True])
print("State #" + str(s.number))
print("Game Variables:", misc)
print("Last Reward:", r)
print("=====================")
print("Episode finished!")
print("total reward:", game.get_total_reward())
print("************************")
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment