Basic Doom game

Before diving in, let us familiarize ourselves with a vizdoom environment by seeing a basic example:

  1. Let's load the necessary libraries:
from vizdoom import *
import random
import time
  1.  Create an instance to the DoomGame:
game = DoomGame() 
  1. As we know ViZDoom provides a lot of Doom scenarios, let us load the basic scenario:
game.load_config("basic.cfg")
  1. The init() method initializes the game with the scenario:
game.init()
  1. 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]
  1. 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:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.229.44