Skip to content

Commit 9e1f3bf

Browse files
committed
2 parents 916f1b0 + cd744b5 commit 9e1f3bf

12 files changed

+124
-144
lines changed

examples/python/basic.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,32 @@
1010
#
1111
#####################################################################
1212
from __future__ import print_function
13-
from vizdoom import DoomGame
14-
from vizdoom import Mode
13+
1514
from vizdoom import Button
15+
from vizdoom import DoomGame
1616
from vizdoom import GameVariable
17+
from vizdoom import Mode
1718
from vizdoom import ScreenFormat
1819
from vizdoom import ScreenResolution
1920
# Or just use from vizdoom import *
2021

2122
from random import choice
2223
from time import sleep
23-
from time import time
24-
2524

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

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

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

3736
# Sets path to doom2 iwad resource file which contains the actual doom game. Default is "./doom2.wad".
3837
game.set_doom_game_path("../../scenarios/freedoom2.wad")
39-
#game.set_doom_game_path("../../scenarios/doom2.wad") # Not provided with environment due to licences.
38+
# game.set_doom_game_path("../../scenarios/doom2.wad") # Not provided with environment due to licences.
4039

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

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

9694
# Run this many episodes
9795
episodes = 10
@@ -102,7 +100,7 @@
102100
sleep_time = 0.028
103101

104102
for i in range(episodes):
105-
print("Episode #" + str(i+1))
103+
print("Episode #" + str(i + 1))
106104

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

127-
if sleep_time>0:
125+
if sleep_time > 0:
128126
sleep(sleep_time)
129127

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

135-
136133
# It will be done automatically anyway but sometimes you need to do it in the middle of the program...
137134
game.close()

examples/python/cig_bots.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python
22

33
from __future__ import print_function
4-
from vizdoom import *
4+
55
from random import choice
6-
from time import sleep
6+
from vizdoom import *
77

88
game = DoomGame()
99

@@ -14,10 +14,10 @@
1414

1515
# Select game and map you want to use.
1616
game.set_doom_game_path("../../scenarios/freedoom2.wad")
17-
#game.set_doom_game_path("../../scenarios/doom2.wad") # Not provided with environment due to licences
17+
# game.set_doom_game_path("../../scenarios/doom2.wad") # Not provided with environment due to licences
1818

1919
game.set_doom_map("map01") # Limited deathmatch.
20-
#game.set_doom_map("map02") # Full deathmatch.
20+
# game.set_doom_map("map02") # Full deathmatch.
2121

2222
# Start multiplayer game only with your AI (with options that will be used in the competition, details in cig_host example).
2323
game.add_game_args("-host 1 -deathmatch +timelimit 2.0 "
@@ -27,7 +27,6 @@
2727
# colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
2828
game.add_game_args("+name AI +colorset 0")
2929

30-
3130
# Multiplayer requires the use of asynchronous modes, but when playing only with bots, synchronous modes can also be used.
3231
game.set_mode(Mode.ASYNC_PLAYER)
3332

@@ -36,7 +35,7 @@
3635
game.init()
3736

3837
# Three example sample actions
39-
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]]
38+
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]]
4039

4140
# Play with this many bots
4241
bots = 7
@@ -46,7 +45,7 @@
4645

4746
for i in range(episodes):
4847

49-
print("Episode #" + str(i+1))
48+
print("Episode #" + str(i + 1))
5049

5150
# Add specific number of bots
5251
# (file examples/bots.cfg must be placed in the same directory as the Doom executable file,
@@ -63,8 +62,8 @@
6362
game.respawn_player()
6463

6564
# Or observe the game until automatic respawn.
66-
#game.advance_action();
67-
#continue;
65+
# game.advance_action();
66+
# continue;
6867

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

83-
8482
game.close()

examples/python/delta_buttons.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
#!/usr/bin/python
22

33
from __future__ import print_function
4-
from vizdoom import *
54

6-
from random import choice
75
from time import sleep
8-
from time import time
9-
6+
from vizdoom import *
107

118
game = DoomGame()
129

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

1512
game.set_doom_game_path("../../scenarios/freedoom2.wad")
16-
#game.set_doom_game_path("../../scenarios/doom2.wad") # Not provided with environment due to licences.
13+
# game.set_doom_game_path("../../scenarios/doom2.wad") # Not provided with environment due to licences.
1714

1815
game.set_doom_map("map01")
1916

@@ -50,7 +47,7 @@
5047
sleep_time = 0.028
5148

5249
for i in range(episodes):
53-
print("Episode #" + str(i+1))
50+
print("Episode #" + str(i + 1))
5451

5552
game.new_episode()
5653

@@ -70,13 +67,10 @@
7067
print("State #" + str(s.number))
7168
print("=====================")
7269

73-
if sleep_time>0:
70+
if sleep_time > 0:
7471
sleep(sleep_time)
7572

7673
print("Episode finished.")
7774
print("************************")
7875

7976
game.close()
80-
81-
82-

examples/python/format.py

+20-22
Original file line numberDiff line numberDiff line change
@@ -12,75 +12,73 @@
1212
#
1313
#####################################################################
1414
from __future__ import print_function
15-
from vizdoom import *
16-
from time import sleep
17-
from time import time
15+
1816
from random import choice
17+
from vizdoom import *
18+
1919
import cv2
2020

2121
game = DoomGame()
2222

2323
# Use other config file if you wish.
2424
game.load_config("../../examples/config/basic.cfg")
25-
#game.set_window_visible(False)
25+
# game.set_window_visible(False)
2626

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

30-
#game.set_screen_format(ScreenFormat.RGB24)
31-
#game.set_screen_format(ScreenFormat.ARGB32)
32-
#game.set_screen_format(ScreenFormat.GRAY8)
30+
# game.set_screen_format(ScreenFormat.RGB24)
31+
# game.set_screen_format(ScreenFormat.ARGB32)
32+
# game.set_screen_format(ScreenFormat.GRAY8)
3333

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

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

43-
#This one makes no sense in particular
44-
#game.set_screen_format(ScreenFormat.DOOM_256_COLORS)
43+
# This one makes no sense in particular
44+
# game.set_screen_format(ScreenFormat.DOOM_256_COLORS)
4545

4646
game.set_screen_resolution(ScreenResolution.RES_640X480)
4747
game.init()
4848

49-
actions = [[True,False,False],[False,True,False],[False,False,True]]
49+
actions = [[True, False, False], [False, True, False], [False, False, True]]
5050

5151
episodes = 10
5252
# sleep time in ms
5353
sleep_time = 20
5454

5555
for i in range(episodes):
56-
print("Episode #" +str(i+1))
56+
print("Episode #" + str(i + 1))
5757
# Not needed for the first episdoe but the loop is nicer.
5858
game.new_episode()
5959
while not game.is_episode_finished():
6060

61-
6261
# Gets the state and possibly to something with it
6362
s = game.get_state()
6463
img = s.image_buffer
6564
misc = s.game_variables
6665

6766
# Gray8 shape is not cv2 compliant
6867
if game.get_screen_format() in [ScreenFormat.GRAY8, ScreenFormat.DEPTH_BUFFER8]:
69-
img = img.reshape(img.shape[1],img.shape[2],1)
68+
img = img.reshape(img.shape[1], img.shape[2], 1)
7069

7170
# Display the image here!
72-
cv2.imshow('Doom Buffer',img)
71+
cv2.imshow('Doom Buffer', img)
7372
cv2.waitKey(sleep_time)
7473

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

78-
print("State #" +str(s.number))
77+
print("State #" + str(s.number))
7978
print("Game Variables:", misc)
80-
print("Last Reward:",r)
79+
print("Last Reward:", r)
8180
print("=====================")
8281

83-
8482
print("Episode finished!")
8583
print("total reward:", game.get_total_reward())
8684
print("************************")

examples/python/fps.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
# to exclude copying process.
1010
#####################################################################
1111
from __future__ import print_function
12-
from vizdoom import *
12+
1313
from random import choice
14-
from vizdoom import ScreenResolution as res
1514
from time import time
15+
from vizdoom import *
16+
from vizdoom import ScreenResolution as res
1617

1718
# Some options:
18-
resolution =res.RES_320X240
19+
resolution = res.RES_320X240
1920
screen_format = ScreenFormat.DEPTH_BUFFER8
2021
iterations = 10000
2122

@@ -28,11 +29,11 @@
2829

2930
game.init()
3031

31-
actions = [[True,False,False],[False,True,False],[False,False,True]]
32+
actions = [[True, False, False], [False, True, False], [False, False, True]]
3233
left = actions[0]
3334
right = actions[1]
3435
shoot = actions[2]
35-
idle = [False,False,False]
36+
idle = [False, False, False]
3637

3738
iterations = 10000
3839
start = time()
@@ -48,16 +49,12 @@
4849
s = game.get_state()
4950
game.make_action(choice(actions))
5051

51-
end=time()
52-
t = end-start
52+
end = time()
53+
t = end - start
5354
print("Results:")
5455
print("Iterations:", iterations)
5556
print("Resolution:", resolution)
56-
print("time:",round(t,3))
57-
print("fps: ",round(iterations/t,2))
58-
57+
print("time:", round(t, 3))
58+
print("fps: ", round(iterations / t, 2))
5959

6060
game.close()
61-
62-
63-

0 commit comments

Comments
 (0)