How to get the position of the target.

73 views
Skip to first unread message

Yutaro Kikuchi

unread,
Oct 27, 2017, 7:24:53 AM10/27/17
to Visual Doom AI Users
Hello

I am trying to get the position of target in the basical model(https://github.com/mwydmuch/ViZDoom/blob/master/examples/python/basic.py).
I fixed Action Code Script in WAD and make the python script accesible position of the target through GameVariable.USER1~3.
However, the value returned from GameVariable.USER1~3 is 0.0 always.
As a trial, I runned the shaping.py (https://github.com/YutaroKikuchi/VizDoom/blob/develop/examples/python/shaping.py). Curiously it worked correctly.
What is the missing in this implementation?

Here is ASC

#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);
   
}


And then, Here is the python script named "test_game_variables.py" based basic.py

#!/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()

Other codes is located https://github.com/YutaroKikuchi/VizDoom/tree/test_gamevariable/working/test_game_vriable.

Does anyone have idea?

Thanks

Yutaro Kikuchi

unread,
Oct 30, 2017, 1:28:28 AM10/30/17
to Visual Doom AI Users
I solved it by myself.
Reason is that I forgot compile ACS previously.
I use SLADE3 as editor, and configured the directory of Action Code Compiler in SLADE3.
Finaly I compiled ACS by Right-Click.

Thanks

2017年10月27日金曜日 20時24分53秒 UTC+9 Yutaro Kikuchi:
Reply all
Reply to author
Forward
0 new messages