Skip to content

Commit

Permalink
Merged with current master.
Browse files Browse the repository at this point in the history
Former-commit-id: 7e802bc
  • Loading branch information
mihahauke committed Nov 25, 2016
2 parents c661c4b + 00248f9 commit 66aeb0c
Show file tree
Hide file tree
Showing 39 changed files with 460 additions and 236 deletions.
3 changes: 2 additions & 1 deletion doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ recording `filePath` argument added to `newEpisode`, `replayEpisode` added.
#### Others

- ZDoom engine updated to 2.8.1
- **Basic support for multiplayer in PLAYER and SPECTATOR Modes.**
- **Paths in config files are now relative to config file.**
- Improved performance.
- Improved exceptions messages.
- **Paths in config files are now relative to config file.**
- Aliases for `DoomFixedToDouble` - `DoomFixedToNumber` in Lua and `doom_fixed_to_float` in Python added.
- Bugs associated with paths handling fixed.
- Many minor bugs fixed.
Expand Down
3 changes: 1 addition & 2 deletions examples/c++/CIG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ int main(){
// colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
game->addGameArgs("+name AI +colorset 0");


game->setMode(ASYNC_PLAYER); // Multiplayer requires the use of asynchronous modes.
game->setMode(ASYNC_PLAYER);
game->init();

while(!game->isEpisodeFinished()){ // Play until the game (episode) is over.
Expand Down
1 change: 0 additions & 1 deletion examples/c++/CIGBots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ int main(){
// colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
game->addGameArgs("+name AI +colorset 0");

// Multiplayer requires the use of asynchronous modes, but when playing only with bots, synchronous modes can also be used.
game->setMode(ASYNC_PLAYER);
game->init();

Expand Down
2 changes: 1 addition & 1 deletion examples/c++/CIGHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int main(){
game->addGameArgs("+name AI +colorset 0");


game->setMode(ASYNC_PLAYER); // Multiplayer requires the use of asynchronous modes.
game->setMode(ASYNC_PLAYER);
game->init();

while(!game->isEpisodeFinished()){ // Play until the game (episode) is over.
Expand Down
61 changes: 39 additions & 22 deletions examples/java/Basic.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,27 @@ public static void main (String[] args) {
game.setRenderCorpses(false);

// Adds buttons that will be allowed.
game.addAvailableButton(Button.MOVE_LEFT);
game.addAvailableButton(Button.MOVE_RIGHT);
game.addAvailableButton(Button.ATTACK);
Button[] availableButtons = new Button [] {Button.MOVE_LEFT, Button.MOVE_RIGHT, Button.ATTACK};
game.setAvailableButtons(availableButtons);
// game.addAvailableButton(Button.MOVE_LEFT); // Appends to available buttons.
// game.addAvailableButton(Button.MOVE_RIGHT);
// game.addAvailableButton(Button.ATTACK);

// Returns table of available Buttons.
// Button[] availableButtons = game.getAvailableButtons();

// Adds game variables that will be included in state.
game.addAvailableGameVariable(GameVariable.AMMO2);
// game.setAvailableGameVariables is also available.

// Returns table of available GameVariables.
// GameVariable[] availableGameVariables = game.getAvailableGameVariables();

// Causes episodes to finish after 200 tics (actions)
game.setEpisodeTimeout(200);

// Makes episodes start after 10 tics (~after raising the weapon)
//game.setEpisodeStartTime(10);
game.setEpisodeStartTime(10);

// Makes the window appear (turned on by default)
game.setWindowVisible(true);
Expand Down Expand Up @@ -83,32 +92,40 @@ public static void main (String[] args) {

for (int i = 0; i < episodes; ++i) {

System.out.println("Episode #" + (i + 1));
System.out.println("Episode #" + (i + 1));

// Starts a new episode. It is not needed right after init() but it doesn't cost much and the loop is nicer.
game.newEpisode();
// Starts a new episode. It is not needed right after init() but it doesn't cost much and the loop is nicer.
game.newEpisode();

while (!game.isEpisodeFinished()) {
while (!game.isEpisodeFinished()) {

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

// Make random action and get reward
double r = game.makeAction(actions.get(ran.nextInt(3)));
int n = state.number;
double[] vars = state.gameVariables;
byte[] screenBuf = state.screenBuffer;
byte[] depthBuf = state.depthBuffer;
byte[] labelsBuf = state.labelsBuffer;
byte[] automapBuf = state.automapBuffer;
Label[] labels = state.labels;

// You can also get last reward by using this function
// double r = game.getLastReward();
// Make random action and get reward
double r = game.makeAction(actions.get(ran.nextInt(3)));

System.out.println("State #" + s.number);
System.out.println("Game variables: " + s.gameVariables[0]);
System.out.println("Action reward: " + r);
System.out.println("=====================");
// You can also get last reward by using this function
// double r = game.getLastReward();

}
System.out.println("State #" + n);
System.out.println("Game variables: " + Arrays.toString(vars));
System.out.println("Action reward: " + r);
System.out.println("=====================");

}

System.out.println("Episode finished.");
System.out.println("Total reward: " + game.getTotalReward());
System.out.println("************************");
System.out.println("Episode finished.");
System.out.println("Total reward: " + game.getTotalReward());
System.out.println("************************");

}

Expand Down
2 changes: 1 addition & 1 deletion examples/java/CIG.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void main (String[] args) {
// colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
game.addGameArgs("+name AI +colorset 0");

game.setMode(Mode.ASYNC_PLAYER); // Multiplayer requires the use of asynchronous modes.
game.setMode(Mode.ASYNC_PLAYER);
game.init();

while(!game.isEpisodeFinished()){ // Play until the game (episode) is over.
Expand Down
2 changes: 1 addition & 1 deletion examples/java/CIGBots.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void main (String[] args) {
// colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
game.addGameArgs("+name AI +colorset 0");

game.setMode(Mode.ASYNC_PLAYER); // Multiplayer requires the use of asynchronous modes.
game.setMode(Mode.ASYNC_PLAYER);
game.init();


Expand Down
2 changes: 1 addition & 1 deletion examples/java/CIGHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void main (String[] args) {
// colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
game.addGameArgs("+name AI +colorset 0");

game.setMode(Mode.ASYNC_PLAYER); // Multiplayer requires the use of asynchronous modes.
game.setMode(Mode.ASYNC_PLAYER);
game.init();

while(!game.isEpisodeFinished()){ // Play until the game (episode) is over.
Expand Down
8 changes: 0 additions & 8 deletions examples/java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ add_jar(deltabuttons DeltaButtons.java
ENTRY_POINT DeltaButtons
OUTPUT_DIR ${VIZDOOM_JAVA_EXAMPLES_OUTPUT_DIR})

add_jar(multiplayer Multiplayer.java
ENTRY_POINT Multiplayer
OUTPUT_DIR ${VIZDOOM_JAVA_EXAMPLES_OUTPUT_DIR})

add_jar(multiplayerhost MultiplayerHost.java
ENTRY_POINT MultiplayerHost
OUTPUT_DIR ${VIZDOOM_JAVA_EXAMPLES_OUTPUT_DIR})

add_jar(seed Seed.java
ENTRY_POINT Seed
OUTPUT_DIR ${VIZDOOM_JAVA_EXAMPLES_OUTPUT_DIR})
Expand Down
2 changes: 1 addition & 1 deletion examples/java/DeltaButtons.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void main (String[] args) {
while (!game.isEpisodeFinished()) {

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

// Make random action and get reward
game.makeAction(actions.get(ran.nextInt(2)));
Expand Down
62 changes: 0 additions & 62 deletions examples/java/Multiplayer.java

This file was deleted.

41 changes: 0 additions & 41 deletions examples/java/MultiplayerHost.java

This file was deleted.

16 changes: 6 additions & 10 deletions examples/java/Seed.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void main (String[] args) {

game.setScreenResolution(ScreenResolution.RES_640X480);

int seed = 1234;
int seed = 666;
// Sets the seed. It could be after init as well.
game.setSeed(seed);
game.init();
Expand All @@ -44,23 +44,19 @@ public static void main (String[] args) {

int episodes = 10;

for (int i=0;i<episodes;i++){
for(int i = 0; i < episodes; i++){

System.out.println("Episode #" + (i+1));
System.out.println("Episode #" + (i + 1));
game.newEpisode();

while ( !game.isEpisodeFinished()){
while(!game.isEpisodeFinished()){
// Gets the state and possibly to something with it
GameState s = game.getState();
int[] img = s.imageBuffer;
int[] gameVariables = s.gameVariables;

GameState state = game.getState();

// Make random action and get reward
double reward = game.makeAction(actions.get(ran.nextInt(3)));


System.out.println("State #" + s.number);
System.out.println("State #" + state.number);
System.out.println("Action Reward: " + reward);
System.out.println("Seed: " + game.getSeed());
System.out.println("=====================");
Expand Down
15 changes: 7 additions & 8 deletions examples/java/Shaping.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,20 @@ public static void main (String[] args) {
while (!game.isEpisodeFinished()) {

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

// Make random action and get reward
double r = game.makeAction(actions.get(ran.nextInt(3)));

double reward = game.makeAction(actions.get(ran.nextInt(3)));

// Retrieve the shaping reward
int _ssr = game.getGameVariable(GameVariable.USER1); // Get value of scripted variable
double ssr = game.DoomFixedToDouble(_ssr); // If value is in DoomFixed format project it to double
double _ssr = game.getGameVariable(GameVariable.USER1); // Get value of scripted variable
double ssr = game.doomFixedToDouble(_ssr); // If value is in DoomFixed format project it to double
double sr = ssr - lastTotalShapingReward;
lastTotalShapingReward = ssr;

System.out.println("State #" + s.number);
System.out.println("Health: " + s.gameVariables[0]);
System.out.println("Action reward: " + r);
System.out.println("State #" + state.number);
System.out.println("Health: " + Arrays.toString(state.gameVariables));
System.out.println("Action reward: " + reward);
System.out.println("Action shaping reward: " + sr);
System.out.println("=====================");

Expand Down
20 changes: 9 additions & 11 deletions examples/java/Spectator.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,22 @@ public static void main (String[] args) {
game.init();

int episodes = 10;
for (int i=0;i<episodes;i++){
for (int i = 0; i < episodes; i++){

System.out.println("Episode #" +(i+1));
System.out.println("Episode #" + (i + 1));

game.newEpisode();
while (! game.isEpisodeFinished()){
GameState s = game.getState();
int[] img = s.imageBuffer;
int[] misc = s.gameVariables;
GameState state = game.getState();

game.advanceAction();
boolean[] a = game.getLastAction();
double r = game.getLastReward();
int[] action = game.getLastAction();
double reward = game.getLastReward();

System.out.println("State #"+s.number);
System.out.println("Game Variables: "+Arrays.toString(misc));
System.out.println("Action: "+ Arrays.toString(a));
System.out.println("Reward: "+r);
System.out.println("State #" + state.number);
System.out.println("Game Variables: " + Arrays.toString(state.gameVariables));
System.out.println("Action: " + Arrays.toString(action));
System.out.println("Reward: " + reward);
System.out.println("=====================");
}

Expand Down
1 change: 0 additions & 1 deletion examples/lua/cig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ game:addGameArgs("-join 127.0.0.1") -- Connect to a host for a multiplayer game.
-- colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
game:addGameArgs("+name AI +colorset 0")

-- Multiplayer requires the use of asynchronous modes.
game:setMode(Mode.ASYNC_PLAYER);

--game:setWindowVisible(false)
Expand Down
Loading

0 comments on commit 66aeb0c

Please sign in to comment.