Before diving in, let us familiarize ourselves with a vizdoom environment by seeing a basic example:
- Let's load the necessary libraries:
from vizdoom import *
import random
import time
- Create an instance to the DoomGame:
game = DoomGame()
- As we know ViZDoom provides a lot of Doom scenarios, let us load the basic scenario:
game.load_config("basic.cfg")
- The init() method initializes the game with the scenario:
game.init()
- Now, let's define the one with hot encoded actions:
shoot = [0, 0, 1]
left = [1, 0, 0]
right = [0, 1, 0]
actions = [shoot, left, right]
- Now, let us start playing the game:
no_of_episodes = 10
for i in range(no_of_episodes):
# for each episode start the game
game.new_episode()
# loop until the episode is over
while not game.is_episode_finished():
# get the game state
state = game.get_state()
img = state.screen_buffer
# get the game variables
misc = state.game_variables
# perform some action randomly and receive reward
reward = game.make_action(random.choice(actions))
print(reward)
# we will set some time before starting the next episode
time.sleep(2)
Once you run the program, you can see the output as follows: