Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Former-commit-id: 9e1f3bf
  • Loading branch information
mwydmuch committed Jun 14, 2016
2 parents b50ffe9 + c19129c commit 214065c
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 144 deletions.
19 changes: 8 additions & 11 deletions examples/python/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,32 @@
#
#####################################################################
from __future__ import print_function
from vizdoom import DoomGame
from vizdoom import Mode

from vizdoom import Button
from vizdoom import DoomGame
from vizdoom import GameVariable
from vizdoom import Mode
from vizdoom import ScreenFormat
from vizdoom import ScreenResolution
# Or just use from vizdoom import *

from random import choice
from time import sleep
from time import time


# Create DoomGame instance. It will run the game and communicate with you.
game = DoomGame()

# Now it's time for configuration!
# load_config could be used to load configuration instead of doing it here with code.
# If load_config is used in-code configuration will work. Note that the most recent changes will add to previous ones.
#game.load_config("../../examples/config/basic.cfg")
# game.load_config("../../examples/config/basic.cfg")

# Sets path to vizdoom engine executive which will be spawned as a separate process. Default is "./vizdoom".
game.set_vizdoom_path("../../bin/vizdoom")

# Sets path to doom2 iwad resource file which contains the actual doom game. Default is "./doom2.wad".
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_game_path("../../scenarios/doom2.wad") # Not provided with environment due to licences.

# Sets path to additional resources iwad file which is basically your scenario iwad.
# If not specified default doom2 maps will be used and it's pretty much useles... unless you want to play doom.
Expand Down Expand Up @@ -87,11 +86,10 @@
# Initialize the game. Further configuration won't take any effect from now on.
game.init()


# Define some actions. Each list entry corresponds to declared buttons:
# MOVE_LEFT, MOVE_RIGHT, ATTACK
# 5 more combinations are naturally possible but only 3 are included for transparency when watching.
actions = [[True,False,False],[False,True,False],[False,False,True]]
actions = [[True, False, False], [False, True, False], [False, False, True]]

# Run this many episodes
episodes = 10
Expand All @@ -102,7 +100,7 @@
sleep_time = 0.028

for i in range(episodes):
print("Episode #" + str(i+1))
print("Episode #" + str(i + 1))

# Starts a new episode. It is not needed right after init() but it doesn't cost much. At least the loop is nicer.
game.new_episode()
Expand All @@ -124,14 +122,13 @@
print("Reward:", r)
print("=====================")

if sleep_time>0:
if sleep_time > 0:
sleep(sleep_time)

# Check how the episode went.
print("Episode finished.")
print("total reward:", game.get_total_reward())
print("************************")


# It will be done automatically anyway but sometimes you need to do it in the middle of the program...
game.close()
18 changes: 8 additions & 10 deletions examples/python/cig_bots.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python

from __future__ import print_function
from vizdoom import *

from random import choice
from time import sleep
from vizdoom import *

game = DoomGame()

Expand All @@ -14,10 +14,10 @@

# 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_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.
# 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 "
Expand All @@ -27,7 +27,6 @@
# 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)

Expand All @@ -36,7 +35,7 @@
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]]
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
Expand All @@ -46,7 +45,7 @@

for i in range(episodes):

print("Episode #" + str(i+1))
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,
Expand All @@ -63,8 +62,8 @@
game.respawn_player()

# Or observe the game until automatic respawn.
#game.advance_action();
#continue;
# game.advance_action();
# continue;

s = game.get_state()
# Analyze the state.
Expand All @@ -80,5 +79,4 @@
# Starts a new episode. All players have to call new_episode() in multiplayer mode.
game.new_episode()


game.close()
14 changes: 4 additions & 10 deletions examples/python/delta_buttons.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
#!/usr/bin/python

from __future__ import print_function
from vizdoom import *

from random import choice
from time import sleep
from time import time

from vizdoom import *

game = DoomGame()

game.set_vizdoom_path("../../bin/vizdoom")

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_game_path("../../scenarios/doom2.wad") # Not provided with environment due to licences.

game.set_doom_map("map01")

Expand Down Expand Up @@ -50,7 +47,7 @@
sleep_time = 0.028

for i in range(episodes):
print("Episode #" + str(i+1))
print("Episode #" + str(i + 1))

game.new_episode()

Expand All @@ -70,13 +67,10 @@
print("State #" + str(s.number))
print("=====================")

if sleep_time>0:
if sleep_time > 0:
sleep(sleep_time)

print("Episode finished.")
print("************************")

game.close()



42 changes: 20 additions & 22 deletions examples/python/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,75 +12,73 @@
#
#####################################################################
from __future__ import print_function
from vizdoom import *
from time import sleep
from time import time

from random import choice
from vizdoom import *

import cv2

game = DoomGame()

# Use other config file if you wish.
game.load_config("../../examples/config/basic.cfg")
#game.set_window_visible(False)
# game.set_window_visible(False)

# Just umcomment desired format. The last uncommented will be applied.
# Formats with C were ommited cause they are not cv2 friendly

#game.set_screen_format(ScreenFormat.RGB24)
#game.set_screen_format(ScreenFormat.ARGB32)
#game.set_screen_format(ScreenFormat.GRAY8)
# game.set_screen_format(ScreenFormat.RGB24)
# game.set_screen_format(ScreenFormat.ARGB32)
# game.set_screen_format(ScreenFormat.GRAY8)

# This is most fun. It looks best if you inverse colors.
game.set_screen_format(ScreenFormat.DEPTH_BUFFER8)

#These formats can be use bet they do not make much sense for cv2, you'll just get mixed up colors.
#game.set_screen_format(ScreenFormat.BGR24)
#game.set_screen_format(ScreenFormat.RGBA32)
#game.set_screen_format(ScreenFormat.BGRA32)
#game.set_screen_format(ScreenFormat.ABGR32)
# These formats can be use bet they do not make much sense for cv2, you'll just get mixed up colors.
# game.set_screen_format(ScreenFormat.BGR24)
# game.set_screen_format(ScreenFormat.RGBA32)
# game.set_screen_format(ScreenFormat.BGRA32)
# game.set_screen_format(ScreenFormat.ABGR32)

#This one makes no sense in particular
#game.set_screen_format(ScreenFormat.DOOM_256_COLORS)
# This one makes no sense in particular
# game.set_screen_format(ScreenFormat.DOOM_256_COLORS)

game.set_screen_resolution(ScreenResolution.RES_640X480)
game.init()

actions = [[True,False,False],[False,True,False],[False,False,True]]
actions = [[True, False, False], [False, True, False], [False, False, True]]

episodes = 10
# sleep time in ms
sleep_time = 20

for i in range(episodes):
print("Episode #" +str(i+1))
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():


# Gets the state and possibly to something with it
s = game.get_state()
img = s.image_buffer
misc = s.game_variables

# Gray8 shape is not cv2 compliant
if game.get_screen_format() in [ScreenFormat.GRAY8, ScreenFormat.DEPTH_BUFFER8]:
img = img.reshape(img.shape[1],img.shape[2],1)
img = img.reshape(img.shape[1], img.shape[2], 1)

# Display the image here!
cv2.imshow('Doom Buffer',img)
cv2.imshow('Doom Buffer', img)
cv2.waitKey(sleep_time)

# Makes a random action and save the reward.
r = game.make_action(choice(actions))

print("State #" +str(s.number))
print("State #" + str(s.number))
print("Game Variables:", misc)
print("Last Reward:",r)
print("Last Reward:", r)
print("=====================")


print("Episode finished!")
print("total reward:", game.get_total_reward())
print("************************")
Expand Down
23 changes: 10 additions & 13 deletions examples/python/fps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
# to exclude copying process.
#####################################################################
from __future__ import print_function
from vizdoom import *

from random import choice
from vizdoom import ScreenResolution as res
from time import time
from vizdoom import *
from vizdoom import ScreenResolution as res

# Some options:
resolution =res.RES_320X240
resolution = res.RES_320X240
screen_format = ScreenFormat.DEPTH_BUFFER8
iterations = 10000

Expand All @@ -28,11 +29,11 @@

game.init()

actions = [[True,False,False],[False,True,False],[False,False,True]]
actions = [[True, False, False], [False, True, False], [False, False, True]]
left = actions[0]
right = actions[1]
shoot = actions[2]
idle = [False,False,False]
idle = [False, False, False]

iterations = 10000
start = time()
Expand All @@ -48,16 +49,12 @@
s = game.get_state()
game.make_action(choice(actions))

end=time()
t = end-start
end = time()
t = end - start
print("Results:")
print("Iterations:", iterations)
print("Resolution:", resolution)
print("time:",round(t,3))
print("fps: ",round(iterations/t,2))

print("time:", round(t, 3))
print("fps: ", round(iterations / t, 2))

game.close()



Loading

0 comments on commit 214065c

Please sign in to comment.