#include "zcommon.acs"
int target_id = 10;
global int 0:reward;global int 1:target_x;global int 2:target_y;global int 3:target_z;global int 4:test;
script 1 OPEN{ test = 100; SpawnTarget(); reward = 0; print(s:"Hello");}int c =0;script 2 ENTER{ test = 100; TakeInventory("Fist",1); ACS_Execute(3, 1, 0, 0, 0);
}
script 3 (void){ int bullets = CheckInventory("Clip"); while(true) { int t_bullets = CheckInventory("Clip"); if(t_bullets < bullets) { reward = reward - 5.0; } bullets = t_bullets; delay(1); }}
script 4 (void){ reward = reward + 106.0; Exit_Normal(0);
}
function void SpawnTarget(void){
int y = Random(-161.0,224.0); target_x = 100; target_y = y; target_z = 100; Spawn("Cacodemon", 0.0, y,0.0,target_id,128); //disables movement SetActorProperty(target_id, APROP_Speed, 0); //makes it die on one hit SetActorProperty(target_id, APROP_Health, 1); //makes it ignore the player and attack actor with tid 100 Thing_Hate (target_id, 100, 6); SetThingSpecial(target_id, ACS_ExecuteAlways, 4); }
#!/usr/bin/env python
from __future__ import print_function
from vizdoom import *
from random import choice
from time import sleep
def initialize_game():
game = DoomGame()
game.load_config("./config/basic.cfg")
game.set_doom_map("map01")
game.init()
return game
actions = [[True, False, False], [False, True, False], [False, False, True]]
game = initialize_game()
episodes = 1
# Sets time that will pause the engine after each action (in seconds)
# Without this everything would go too fast for you to keep track of what's happening.
sleep_time = 1.0 / DEFAULT_TICRATE # = 0.028
for i in range(episodes):
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()
while not game.is_episode_finished():
# Gets the state
state = game.get_state()
# Get Position from GameVariable
pos_x = game.get_game_variable(GameVariable.USER1)
pos_y = game.get_game_variable(GameVariable.USER2)
pos_z = game.get_game_variable(GameVariable.USER3)
test = game.get_game_variable(GameVariable.USER4)
pos_x = doom_fixed_to_double(pos_x)
pos_y = doom_fixed_to_double(pos_y)
pos_z = doom_fixed_to_double(pos_z)
# Which consists of:
n = state.number
vars = state.game_variables
screen_buf = state.screen_buffer
depth_buf = state.depth_buffer
labels_buf = state.labels_buffer
automap_buf = state.automap_buffer
labels = state.labels
# Makes a random action and get remember reward.
r = game.make_action(choice(actions))
# Prints state's game variables and reward.
print("State #" + str(n))
print("test:",test)
print("Game variables:", vars)
print("X{0}, Y:{0}, X:{0}".format(pos_x, pos_y, pos_z))
print(type(pos_x))
print("Reward:", r)
print("=====================")
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()