Skip to content

Commit

Permalink
Move forward/backward and left/right delta buttons work again, delta_…
Browse files Browse the repository at this point in the history
…buttons.py example, vizdoom_nocheat flag
  • Loading branch information
mwydmuch committed Apr 18, 2016
1 parent 27ca774 commit f7f2b35
Show file tree
Hide file tree
Showing 20 changed files with 313 additions and 50 deletions.
16 changes: 16 additions & 0 deletions examples/bin/vizdoom.so.dir/DependInfo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The set of languages for which implicit dependencies are needed:
set(CMAKE_DEPENDS_LANGUAGES
)
# The set of files for implicit dependencies of each language:

# Targets to which this target links.
set(CMAKE_TARGET_LINKED_INFO_FILES
)

# The include file search paths:
set(CMAKE_C_TARGET_INCLUDE_PATH
"../../vizdoom_api_src"
)
set(CMAKE_CXX_TARGET_INCLUDE_PATH ${CMAKE_C_TARGET_INCLUDE_PATH})
set(CMAKE_Fortran_TARGET_INCLUDE_PATH ${CMAKE_C_TARGET_INCLUDE_PATH})
set(CMAKE_ASM_TARGET_INCLUDE_PATH ${CMAKE_C_TARGET_INCLUDE_PATH})
62 changes: 62 additions & 0 deletions examples/bin/vizdoom.so.dir/build.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.2

#=============================================================================
# Special targets provided by cmake.

# Disable implicit rules so canonical targets will work.
.SUFFIXES:

# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =

.SUFFIXES: .hpux_make_needs_suffix_list

# Suppress display of executed commands.
$(VERBOSE).SILENT:

# A target that is always out of date.
cmake_force:
.PHONY : cmake_force

#=============================================================================
# Set environment variables for the build.

# The shell in which to execute make rules.
SHELL = /bin/sh

# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake

# The command to remove a file.
RM = /usr/bin/cmake -E remove -f

# Escaping for special characters.
EQUALS = =

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/marek/Workspace/ViZDoom/examples/c++

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/marek/Workspace/ViZDoom/examples/c++

# Include any dependencies generated for this target.
include CMakeFiles/../../bin/vizdoom.so.dir/depend.make

# Include the progress variables for this target.
include CMakeFiles/../../bin/vizdoom.so.dir/progress.make

# Include the compile flags for this target's objects.
include CMakeFiles/../../bin/vizdoom.so.dir/flags.make

CMakeFiles/../../bin/vizdoom.so.dir/requires:
.PHONY : CMakeFiles/../../bin/vizdoom.so.dir/requires

CMakeFiles/../../bin/vizdoom.so.dir/clean:
$(CMAKE_COMMAND) -P CMakeFiles/../../bin/vizdoom.so.dir/cmake_clean.cmake
.PHONY : CMakeFiles/../../bin/vizdoom.so.dir/clean

CMakeFiles/../../bin/vizdoom.so.dir/depend:
cd /home/marek/Workspace/ViZDoom/examples/c++ && $(CMAKE_COMMAND) -E cmake_depends "Unix Makefiles" /home/marek/Workspace/ViZDoom/examples/c++ /home/marek/Workspace/ViZDoom/examples/c++ /home/marek/Workspace/ViZDoom/examples/c++ /home/marek/Workspace/ViZDoom/examples/c++ /home/marek/Workspace/ViZDoom/examples/bin/vizdoom.so.dir/DependInfo.cmake --color=$(COLOR)
.PHONY : CMakeFiles/../../bin/vizdoom.so.dir/depend

5 changes: 5 additions & 0 deletions examples/bin/vizdoom.so.dir/cmake_clean.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

# Per-language clean rules from dependency scanning.
foreach(lang)
include(CMakeFiles/../../bin/vizdoom.so.dir/cmake_clean_${lang}.cmake OPTIONAL)
endforeach()
2 changes: 2 additions & 0 deletions examples/bin/vizdoom.so.dir/depend.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Empty dependencies file for ../../bin/vizdoom.so.
# This may be replaced when dependencies are built.
3 changes: 3 additions & 0 deletions examples/bin/vizdoom.so.dir/flags.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.2

1 change: 1 addition & 0 deletions examples/bin/vizdoom.so.dir/progress.make
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions examples/c++/Basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ int main() {
// Create DoomGame instance. It will run the game and communicate with you.
DoomGame *game = new DoomGame();

// Sets path to vizdoom engine executive which will be spawned as a separate process. Default is "./vizdoom".
game->setViZDoomPath("../../bin/vizdoom");

// Sets path to doom2 iwad resource file which contains the actual doom game-> Default is "./doom2.wad".
Expand Down
12 changes: 7 additions & 5 deletions examples/c++/DeltaButtons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ int main(){
game->setScreenResolution(RES_640X480);

// Adds delta buttons that will be allowed and set the maximum allowed value (optional).
game->addAvailableButton(MOVE_FORWARD_BACKWARD_DELTA, 50);
game->addAvailableButton(MOVE_LEFT_RIGHT_DELTA, 20);
game->addAvailableButton(MOVE_FORWARD_BACKWARD_DELTA, 5);
game->addAvailableButton(MOVE_LEFT_RIGHT_DELTA, 2);
game->addAvailableButton(TURN_LEFT_RIGHT_DELTA);
game->addAvailableButton(LOOK_UP_DOWN_DELTA);

Expand All @@ -37,10 +37,10 @@ int main(){
// For MOVE_FORWARD_BACKWARD_DELTA, MOVE_LEFT_RIGHT_DELTA, MOVE_UP_DOWN_DELTA (rarely used)
// value is the speed of movement in a given direction (100 is close to the maximum speed).
std::vector<int> actions[2];
int action0[] = {100, 10, 10, 10};
int action0[] = {10, 1, 1, 1};
actions[0] = std::vector<int>(action0, action0 + sizeof(action0) / sizeof(int));

int action1[] = {20, -30, -20, -15};
int action1[] = {2, -3, -2, 0};
actions[1] = std::vector<int>(action1, action1 + sizeof(action1) / sizeof(int));

// If button's absolute value > max button's value then value = max value with original value sign.
Expand All @@ -66,13 +66,15 @@ int main(){
std::cout << "Episode #" << i + 1 << "\n";
game->newEpisode();

game->getEpisodeTime();

while (!game->isEpisodeFinished()) {

// Get the state
GameState s = game->getState();

// Make random action and get reward
game->makeAction(actions[std::rand() % 3]);
game->makeAction(actions[std::rand() % 2]);

}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/c++/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Demonstrates how to configure and play multiplayer game for CIG 2016 competition
Demonstrates how to play with bots to simulate multiplayer game. Helpful for developing AI agent for CIG 2016 competition.

###[DeltaButtons.cpp](https://github.com/Marqt/ViZDoom/blob/master/examples/c++/DeltaButtons.cpp)
Shows how delta buttons (they may take values other than 0 and 1 and used for precise movement) works.
Shows how delta buttons (they may take values other than 0 and 1 and be used for precise movement) works.

###[Multiplayer.cpp](https://github.com/Marqt/ViZDoom/blob/master/examples/c++/Multiplayer.cpp), [MultiplayerHost.cpp](https://github.com/Marqt/ViZDoom/blob/master/examples/c++/MultiplayerHost.cpp)
Demonstrates how to configure and play multiplayer game.
Expand Down
7 changes: 4 additions & 3 deletions examples/java/Basic.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ public static void main (String[] args) {

// Create DoomGame instance. It will run the game and communicate with you.
DoomGame game = new DoomGame();

game.setViZDoomPath("../../bin/vizdoom");

// Sets path to vizdoom engine executive which will be spawned as a separate process. Default is "./vizdoom".
game.setViZDoomPath("../../bin/vizdood");

// Sets path to doom2 iwad resource file which contains the actual doom game-> Default is "./doom2.wad".
game.setDoomGamePath("../../scenarios/freedoom2.wad");
Expand All @@ -31,7 +32,7 @@ public static void main (String[] args) {
game.setDoomMap("map01");

// Sets resolution. Default is 320X240
game.setScreenResolution(ScreenResolution.RES_320X240);
game.setScreenResolution(ScreenResolution.RES_640X480);

// Sets the screen buffer format. Not used here but now you can change it. Defalut is CRCGCB.
game.setScreenFormat(ScreenFormat.RGB24);
Expand Down
8 changes: 4 additions & 4 deletions examples/java/DeltaButtons.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public static void main (String[] args) {
game.setScreenResolution(ScreenResolution.RES_640X480);

// Adds delta buttons that will be allowed and set the maximum allowed value (optional).
game.addAvailableButton(Button.MOVE_FORWARD_BACKWARD_DELTA, 50);
game.addAvailableButton(Button.MOVE_LEFT_RIGHT_DELTA, 20);
game.addAvailableButton(Button.MOVE_FORWARD_BACKWARD_DELTA, 5);
game.addAvailableButton(Button.MOVE_LEFT_RIGHT_DELTA, 2);
game.addAvailableButton(Button.TURN_LEFT_RIGHT_DELTA);
game.addAvailableButton(Button.LOOK_UP_DOWN_DELTA);

Expand All @@ -40,8 +40,8 @@ public static void main (String[] args) {
// For MOVE_FORWARD_BACKWARD_DELTA, MOVE_LEFT_RIGHT_DELTA, MOVE_UP_DOWN_DELTA (rarely used)
// value is the speed of movement in a given direction (100 is close to the maximum speed).
List<int[]> actions = new ArrayList<int[]>();
actions.add(new int[] {100, 10, 10, 10});
actions.add(new int[] {20, -30, -20, -15});
actions.add(new int[] {10, 1, 1, 1});
actions.add(new int[] {2, -3, -2, -1});


// If button's absolute value > max button's value then value = max value with original value sign.
Expand Down
2 changes: 1 addition & 1 deletion examples/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Demonstrates how to configure and play multiplayer game for CIG 2016 competition
Demonstrates how to play with bots to simulate multiplayer game. Helpful for developing AI agent for CIG 2016 competition.

###[DeltaButtons.java](https://github.com/Marqt/ViZDoom/blob/master/examples/java/DeltaButtons.java)
Shows how delta buttons (they may take values other than 0 and 1 and used for precise movement) works.
Shows how delta buttons (they may take values other than 0 and 1 and be used for precise movement) works.

###[Multiplayer.java](https://github.com/Marqt/ViZDoom/blob/master/examples/java/Multiplayer.java), [MultiplayerHost.java](https://github.com/Marqt/ViZDoom/blob/master/examples/java/MultiplayerHost.java)
Demonstrates how to configure and play multiplayer game.
Expand Down
21 changes: 15 additions & 6 deletions examples/python/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
To run the examples, [freedoom2.wad]( https://freedoom.github.io/download.html) should be placed in the ``../scenarios`` subdirectory.
Furthermore, you need to have ``vizdoom.so`` present (or symlinked) in the ``examples/python`` directory. These steps should be done automatically by the building process.
To run the examples, [freedoom2.wad]( https://freedoom.github.io/download.html) should be placed in the ``scenarios`` subdirectory.
Furthermore, you need to have ``vizdoom.so`` present (or symlinked) in the ``examples/python`` directory (on Linux it should be done automatically by the building process).

---
##Examples

###[basic.py](https://github.com/Marqt/ViZDoom/blob/master/examples/python/basic.py)
Demonstrates how to use the most basic features of the environment. It configures the engine, and makes the agent perform random actions. It also prints the current state and the reward earned with every action.

###[scenarios.py](https://github.com/Marqt/ViZDoom/blob/master/examples/python/scenarios.py)
Presents different scenarios that come with ViZDoom environment.
###[cig.py](https://github.com/Marqt/ViZDoom/blob/master/examples/python/cig.py), [cig_host.py](https://github.com/Marqt/ViZDoom/blob/master/examples/python/cig_host.py)
Demonstrates how to configure and play multiplayer game for CIG 2016 competition.

###[spectator.py](https://github.com/Marqt/ViZDoom/blob/master/examples/python/spectator.py)
Shows how to use the *SPECTATOR* mode in which YOU play Doom and AI is the spectator (intended for apprenticeship learning).
###[cig_bots.py](https://github.com/Marqt/ViZDoom/blob/master/examples/python/cig_bots.py)
Demonstrates how to play with bots to simulate multiplayer game. Helpful for developing AI agent for CIG 2016 competition.

###[delta_buttons.cpp](https://github.com/Marqt/ViZDoom/blob/master/examples/python/delta_buttons.cpp)
Shows how delta buttons (they may take values other than 0 and 1 and be used for precise movement) works.

###[format.py](https://github.com/Marqt/ViZDoom/blob/master/examples/python/format.py)
Presents different formats of the screen buffer. [OpenCV](http://opencv.org/) is used to display the images.
Expand All @@ -22,5 +25,11 @@ Tests the performance of the environment in frames per second. It should give yo
###[shaping.py](https://github.com/Marqt/ViZDoom/blob/master/examples/python/shaping.py)
Demonstrates how to make use of the game variables to implement [shaping](https://en.wikipedia.org/wiki/Shaping_(psychology)) using health_guided.wad scenario.

###[scenarios.py](https://github.com/Marqt/ViZDoom/blob/master/examples/python/scenarios.py)
Presents different scenarios that come with ViZDoom environment.

###[seed.py](https://github.com/Marqt/ViZDoom/blob/master/examples/python/seed.py)
Shows how to run deterministic episodes by setting the seed. After setting the seed every episode will look the same (if the agent behaves deterministically).

###[spectator.py](https://github.com/Marqt/ViZDoom/blob/master/examples/python/spectator.py)
Shows how to use the *SPECTATOR* mode in which YOU play Doom and AI is the spectator (intended for apprenticeship learning).
4 changes: 2 additions & 2 deletions examples/python/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# If load_config is used in-code configuration will work. Note that the most recent changes will add to previous ones.
#game.load_config("../../examples/config/basic.cfg")

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

# Sets path to doom2 iwad resource file which contains the actual doom game. Default is "./doom2.wad".
Expand Down Expand Up @@ -95,7 +95,7 @@
for i in range(episodes):
print("Episode #" + str(i+1))

# Starts a new episode. It is not neaded right after init() but it doesn't cost much. At least the loop is nicer.
# 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():
Expand Down
2 changes: 1 addition & 1 deletion examples/python/cig_bots.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Name Your AI.
game.add_game_args("+name AI");

# Multiplayer requires the use of asynchronous modes but
# Multiplayer requires the use of asynchronous modes, but when playing only with bots, synchronous modes can also be used.
game.set_mode(Mode.PLAYER)

# game.set_window_visible(false)
Expand Down
83 changes: 83 additions & 0 deletions examples/python/delta_buttons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/python

from __future__ import print_function
from vizdoom import *

from random import choice
from time import sleep
from time import time


game = DoomGame()

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

game.set_doom_game_path("../../scenarios/freedoom2.wad")
game.set_doom_game_path("../../scenarios/doom2.wad") # Not provided with environment due to licences.

game.set_doom_map("map01")

game.set_screen_resolution(ScreenResolution.RES_640X480)


# Adds delta buttons that will be allowed and set the maximum allowed value (optional).
game.add_available_button(Button.MOVE_FORWARD_BACKWARD_DELTA, 10)
game.add_available_button(Button.MOVE_LEFT_RIGHT_DELTA, 5)
game.add_available_button(Button.TURN_LEFT_RIGHT_DELTA, 5)
game.add_available_button(Button.LOOK_UP_DOWN_DELTA)

# For normal buttons (binary) all values other than 0 are interpreted as pushed.
# For delta buttons values determine a precision/speed.
#
# For TURN_LEFT_RIGHT_DELTA and LOOK_UP_DOWN_DELTA value is the angle (in degrees)
# of which the viewing angle will change.
#
# For MOVE_FORWARD_BACKWARD_DELTA, MOVE_LEFT_RIGHT_DELTA, MOVE_UP_DOWN_DELTA (rarely used)
# value is the speed of movement in a given direction (100 is close to the maximum speed).
action = [100, 10, 10, 1]

# If button's absolute value > max button's value then value = max value with original value sign.

# Delta buttons in spectator modes correspond to mouse movements.
# Maximum allowed values also apply to spectator modes.
# game.add_game_args("+freelook 1") # Use this to enable looking around with the mouse.
# game.set_mode(Mode.SPECTATOR)

game.set_window_visible(True)

game.init()

episodes = 10
sleep_time = 0.028

for i in range(episodes):
print("Episode #" + str(i+1))

game.new_episode()

while not game.is_episode_finished():

s = game.get_state()
r = game.make_action(action)

t = game.get_episode_time()

action[0] = t % 100 - 50
action[1] = t % 100 - 50
action[2] = t % 100 - 50
if not t % 25:
action[3] = -action[3]

print("State #" + str(s.number))
print("=====================")

if sleep_time>0:
sleep(sleep_time)

print("Episode finished.")
print("************************")

game.close()



7 changes: 1 addition & 6 deletions vizdoom_api_bindings/python/ViZDoomGamePython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ namespace vizdoom {
int x = this->getScreenWidth();
int y = this->getScreenHeight();

switch(this->getScreenFormat())
{
switch(this->getScreenFormat()) {
case CRCGCB:
case CRCGCBDB:
case CBCGCR:
Expand All @@ -62,8 +61,6 @@ namespace vizdoom {
this->imageShape[1] = x;
this->imageShape[2] = channels;
}


}
return initSuccess;
}
Expand Down Expand Up @@ -112,7 +109,6 @@ namespace vizdoom {
return GameStatePython(state.number, numpyImage.copy());
}


}

boost::python::list DoomGamePython::getLastAction() {
Expand All @@ -125,7 +121,6 @@ namespace vizdoom {
}

object DoomGamePython::getGameScreen(){
//TODO check if it works
PyObject *img = PyArray_SimpleNewFromData(3, imageShape, NPY_UBYTE, this->doomController->getScreen());
boost::python::handle<> numpyImageHandle = boost::python::handle<>(img);
boost::python::numeric::array numpyImage = array(numpyImageHandle);
Expand Down
Loading

0 comments on commit f7f2b35

Please sign in to comment.