Skip to content

Commit

Permalink
newEpisode for multiplayer fix
Browse files Browse the repository at this point in the history
Former-commit-id: ce8334d
  • Loading branch information
mwydmuch committed Jun 14, 2016
1 parent 71fe88c commit ddf2370
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 110 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ src/vizdoom/wadsrc_wad
src/vizdoom/zdoom_docs
src/vizdoom/zlib/x64/

# Game wads, scenarios backups, demos and personal configurations
# Game wads, scenarios backups, logs, demos and personal configurations
**.bak
**/doom2.wad
**/doom.wad
Expand All @@ -86,6 +86,7 @@ src/vizdoom/zlib/x64/
**/freedm.wad
**.bcp
**.lmp
**.log

# CLion & PyCharm
**.idea
Expand Down
6 changes: 4 additions & 2 deletions examples/c++/CIG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ int main(){
// Join existing game.
game->addGameArgs("-join 127.0.0.1"); // Connect to a host for a multiplayer game.

// Name Your AI.
game->addGameArgs("+name AI");
// Name your agent and select color
// 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->init();
Expand Down
53 changes: 35 additions & 18 deletions examples/c++/CIGBots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,54 @@ int main(){
game->addGameArgs("-host 1 -deathmatch +timelimit 10.0 "
"+sv_forcerespawn 1 +sv_noautoaim 1 +sv_respawnprotect 1 +sv_spawnfarthest 1");

// Name Your AI.
game->addGameArgs("+name AI");
// Name your agent and select color
// 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();

// Add bots (file examples/bots.cfg must be placed in the same directory as the Doom executable file).
for(int i=0; i < 7; ++i) {
game->sendGameCommand("addbot");
}

while(!game->isEpisodeFinished()){ // Play until the game (episode) is over.
int bots = 7; // Play with this many bots
int episodes = 10; // Run this many episodes

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

if(game->isPlayerDead()){
game->respawnPlayer(); // Use this to respawn immediately after death, new state will be available.
std::cout << "Episode #" << i + 1 << "\n";

// Or observe the game until automatic respawn.
//game->advanceAction();
//continue;
// Add specific number of bots
// (file examples/bots.cfg must be placed in the same directory as the Doom executable file,
// edit this file to adjust bots).
game->sendGameCommand("removebots");
for (int b = 0; b < bots; ++b) {
game->sendGameCommand("addbot");
}

GameState state = game->getState();
// Analyze the state.
while (!game->isEpisodeFinished()) { // Play until the game (episode) is over.

if (game->isPlayerDead()) { // Check if player is dead
game->respawnPlayer(); // Use this to respawn immediately after death, new state will be available.

// Or observe the game until automatic respawn.
//game->advanceAction();
//continue;
}

std::vector<int> action(game->getAvailableButtonsSize());
// Set your action.
GameState state = game->getState();
// Analyze the state.

game->makeAction(action);
std::vector<int> action(game->getAvailableButtonsSize());
// Set your action.

game->makeAction(action);

std::cout << game->getEpisodeTime() << " Frags: " << game->getGameVariable(FRAGCOUNT) << std::endl;
}

std::cout << game->getEpisodeTime() << " Frags: " << game->getGameVariable(FRAGCOUNT) << std::endl;
std::cout << "Episode finished.\n";
std::cout << "Total reward: " << game->getTotalReward() << "\n";
std::cout << "************************\n";
}

game->close();
Expand Down
6 changes: 4 additions & 2 deletions examples/c++/CIGHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ int main(){
"+sv_spawnfarthest 1 " // Players will be spawned as far as possible from any other players.
"+vizdoom_nocheat 1"); // Disables depth buffer and the ability to use commands that could interfere with multiplayer game.

// Name Your AI.
game->addGameArgs("+name AI");
// Name your agent and select color
// 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->init();
Expand Down
5 changes: 3 additions & 2 deletions examples/java/CIG.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public static void main (String[] args) {
// Join existing game.
game.addGameArgs("-join 127.0.0.1"); // Connect to a host for a multiplayer game.

// Name Your AI.
game.addGameArgs("+name AI");
// Name your agent and select color
// 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.init();
Expand Down
54 changes: 35 additions & 19 deletions examples/java/CIGBots.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public static void main (String[] args) {

System.out.println("\n\nCIG BOTS EXAMPLE\n");


// Use CIG example config or Your own.
game.loadConfig("../../examples/config/cig.cfg");

Expand All @@ -25,35 +24,52 @@ public static void main (String[] args) {
// Start multiplayer game only with Your AI (with options that will be used in the competition, details in CIGHost example).
game.addGameArgs("-host 1 -deathmatch +timelimit 10.0 +sv_forcerespawn 1 +sv_noautoaim 1 +sv_respawnprotect 1 +sv_spawnfarthest 1");

// Name Your AI.
game.addGameArgs("+name AI");
// Name your agent and select color
// 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); // Multiplayer requires the use of asynchronous modes.
game.init();

for(int i=0; i < 7; ++i) {
game.sendGameCommand("addbot");
}

while(!game.isEpisodeFinished()){ // Play until the game (episode) is over.
int bots = 7; // Play with this many bots
int episodes = 10; // Run this many episodes

if(game.isPlayerDead()){ // Check if player is dead
game.respawnPlayer(); // Use this to respawn immediately after death, new state will be available.
for(int i = 0; i < episodes; ++i){

// Or observe the game until automatic respawn.
//game.advanceAction();
//continue;
System.out.println("Episode #" + (i + 1));

// Add specific number of bots
// (file examples/bots.cfg must be placed in the same directory as the Doom executable file,
// edit this file to adjust bots).
game.sendGameCommand("removebots");
for(int b = 0; b < bots; ++b) {
game.sendGameCommand("addbot");
}

GameState state = game.getState();
// Analyze the state.
while(!game.isEpisodeFinished()){ // Play until the game (episode) is over.

if(game.isPlayerDead()){ // Check if player is dead
game.respawnPlayer(); // Use this to respawn immediately after death, new state will be available.

int[] action= new int[game.getAvailableButtonsSize()];
// Set your action.
// Or observe the game until automatic respawn.
//game.advanceAction();
//continue;
}

game.makeAction(action);
GameState state = game.getState();
// Analyze the state.

int[] action= new int[game.getAvailableButtonsSize()];
// Set your action.

game.makeAction(action);

System.out.println(game.getEpisodeTime() + " Frags: " + game.getGameVariable(GameVariable.FRAGCOUNT));
}

System.out.println(game.getEpisodeTime() + " Frags: " + game.getGameVariable(GameVariable.FRAGCOUNT));
System.out.println("Episode finished.");
System.out.println("************************");
}

game.close();
Expand Down
9 changes: 5 additions & 4 deletions examples/java/CIGHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ public static void main (String[] args) {
+"+sv_spawnfarthest 1 " // Players will be spawned as far as possible from any other players.
+"+vizdoom_nocheat 1"); // Disables depth buffer and the ability to use commands that could interfere with multiplayer game.

// Name Your AI.
game.addGameArgs("+name AI");
// Name your agent and select color
// 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.init();

while(!game.isEpisodeFinished()){ // Play until the game (episode) is over.

if(game.isPlayerDead()){ // Check if player is dead
game.respawnPlayer(); // Use this to respawn immediately after death, new state will be available.
if(game.isPlayerDead()){ // Check if player is dead
game.respawnPlayer(); // Use this to respawn immediately after death, new state will be available.

// Or observe the game until automatic respawn.
//game.advanceAction();
Expand Down
15 changes: 8 additions & 7 deletions examples/python/cig.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/python
#!/usr/bin/env python

from __future__ import print_function
from vizdoom import *
from random import choice

game = DoomGame()

# Use CIG example config or Your own.
# Use CIG example config or your own.
game.load_config("../../examples/config/cig.cfg")

# Select game and map You want to use.
# Select game and map you want to use.
game.set_doom_game_path("../../scenarios/freedoom2.wad")
#game.set_doom_game_path("../../scenarios/doom2.wad") # Not provided with environment due to licences

Expand All @@ -19,13 +19,14 @@
# Join existing game.
game.add_game_args("-join 127.0.0.1") # Connect to a host for a multiplayer game.

# Name Your AI.
game.add_game_args("+name AI")
# Name your agent and select color
# colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
game.add_game_args("+name AI +colorset 0")

# Multiplayer requires the use of asynchronous modes.
game.set_mode(Mode.ASYNC_PLAYER)
game.set_mode(Mode.ASYNC_SPECTATOR)

# game.set_window_visible(false)
#game.set_window_visible(false)

game.init()

Expand Down
74 changes: 48 additions & 26 deletions examples/python/cig_bots.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,84 @@
#!/usr/bin/python
#!/usr/bin/env python

from __future__ import print_function
from vizdoom import *
from random import choice
from time import sleep

game = DoomGame()

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

# Use CIG example config or Your own.
# Use CIG example config or your own.
game.load_config("../../examples/config/cig.cfg")

# Select game and map You want to use.
# Select game and map you want to use.
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") # Limited deathmatch.
#game.set_doom_map("map02") # Full deathmatch.

# Start multiplayer game only with Your AI (with options that will be used in the competition, details in cig_host example).
game.add_game_args("-host 1 -deathmatch +timelimit 10.0 "
# Start multiplayer game only with your AI (with options that will be used in the competition, details in cig_host example).
game.add_game_args("-host 1 -deathmatch +timelimit 1.0 "
"+sv_forcerespawn 1 +sv_noautoaim 1 +sv_respawnprotect 1 +sv_spawnfarthest 1")

# Name Your AI.
game.add_game_args("+name AI")
# Name your agent and select color
# colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
game.add_game_args("+name AI +colorset 0")


# 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_mode(Mode.ASYNC_PLAYER)

# game.set_window_visible(false)
# game.set_window_visible(False)

game.init()

# Three example sample actions
actions = [[1,0,0,0,0,0,0,0,0],[0,1,0,0,0,0,0,0,0],[0,0,1,0,0,0,0,0,0]]

# Add bots (file examples/bots.cfg must be placed in the same directory as the Doom executable file).
bots_number = 7
for i in range(bots_number):
game.send_game_command("addbot")
# Play with this many bots
bots = 7

# Run this many episodes
episodes = 10

for i in range(episodes):

print("Episode #" + str(i+1))

# Add specific number of bots
# (file examples/bots.cfg must be placed in the same directory as the Doom executable file,
# edit this file to adjust bots).
game.send_game_command("removebots")
for i in range(bots):
game.send_game_command("addbot")

# Play until the game (episode) is over.
while not game.is_episode_finished():

if game.is_player_dead():
# Use this to respawn immediately after death, new state will be available.
game.respawn_player()

# Or observe the game until automatic respawn.
#game.advance_action();
#continue;

# Play until the game (episode) is over.
while not game.is_episode_finished():
s = game.get_state()
# Analyze the state.

if game.is_player_dead():
# Use this to respawn immediately after death, new state will be available.
game.respawn_player()
game.make_action(choice(actions))
# Make your action.

# Or observe the game until automatic respawn.
#game.advance_action();
#continue;
print("Frags:", game.get_game_variable(GameVariable.FRAGCOUNT))

s = game.get_state()
# Analyze the state.
print("Episode finished.")
print("************************")

game.make_action(choice(actions))
# Make your action.
# Starts a new episode. All players have to call new_episode() in multiplayer mode.
game.new_episode()

print("Frags:", game.get_game_variable(GameVariable.FRAGCOUNT))

game.close()
Loading

0 comments on commit ddf2370

Please sign in to comment.