Skip to content

Commit ce8334d

Browse files
committed
newEpisode for multiplayer fix
1 parent 15c7044 commit ce8334d

12 files changed

+204
-110
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ src/vizdoom/wadsrc_wad
7777
src/vizdoom/zdoom_docs
7878
src/vizdoom/zlib/x64/
7979

80-
# Game wads, scenarios backups, demos and personal configurations
80+
# Game wads, scenarios backups, logs, demos and personal configurations
8181
**.bak
8282
**/doom2.wad
8383
**/doom.wad
@@ -86,6 +86,7 @@ src/vizdoom/zlib/x64/
8686
**/freedm.wad
8787
**.bcp
8888
**.lmp
89+
**.log
8990

9091
# CLion & PyCharm
9192
**.idea

examples/c++/CIG.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ int main(){
2424
// Join existing game.
2525
game->addGameArgs("-join 127.0.0.1"); // Connect to a host for a multiplayer game.
2626

27-
// Name Your AI.
28-
game->addGameArgs("+name AI");
27+
// Name your agent and select color
28+
// colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
29+
game->addGameArgs("+name AI +colorset 0");
30+
2931

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

examples/c++/CIGBots.cpp

+35-18
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,54 @@ int main(){
2525
game->addGameArgs("-host 1 -deathmatch +timelimit 10.0 "
2626
"+sv_forcerespawn 1 +sv_noautoaim 1 +sv_respawnprotect 1 +sv_spawnfarthest 1");
2727

28-
// Name Your AI.
29-
game->addGameArgs("+name AI");
28+
// Name your agent and select color
29+
// colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
30+
game->addGameArgs("+name AI +colorset 0");
3031

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

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

40-
while(!game->isEpisodeFinished()){ // Play until the game (episode) is over.
37+
int bots = 7; // Play with this many bots
38+
int episodes = 10; // Run this many episodes
39+
40+
for(int i = 0; i < episodes; ++i) {
4141

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

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

50-
GameState state = game->getState();
51-
// Analyze the state.
52+
while (!game->isEpisodeFinished()) { // Play until the game (episode) is over.
53+
54+
if (game->isPlayerDead()) { // Check if player is dead
55+
game->respawnPlayer(); // Use this to respawn immediately after death, new state will be available.
56+
57+
// Or observe the game until automatic respawn.
58+
//game->advanceAction();
59+
//continue;
60+
}
5261

53-
std::vector<int> action(game->getAvailableButtonsSize());
54-
// Set your action.
62+
GameState state = game->getState();
63+
// Analyze the state.
5564

56-
game->makeAction(action);
65+
std::vector<int> action(game->getAvailableButtonsSize());
66+
// Set your action.
67+
68+
game->makeAction(action);
69+
70+
std::cout << game->getEpisodeTime() << " Frags: " << game->getGameVariable(FRAGCOUNT) << std::endl;
71+
}
5772

58-
std::cout << game->getEpisodeTime() << " Frags: " << game->getGameVariable(FRAGCOUNT) << std::endl;
73+
std::cout << "Episode finished.\n";
74+
std::cout << "Total reward: " << game->getTotalReward() << "\n";
75+
std::cout << "************************\n";
5976
}
6077

6178
game->close();

examples/c++/CIGHost.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ int main(){
3131
"+sv_spawnfarthest 1 " // Players will be spawned as far as possible from any other players.
3232
"+vizdoom_nocheat 1"); // Disables depth buffer and the ability to use commands that could interfere with multiplayer game.
3333

34-
// Name Your AI.
35-
game->addGameArgs("+name AI");
34+
// Name your agent and select color
35+
// colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
36+
game->addGameArgs("+name AI +colorset 0");
37+
3638

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

examples/java/CIG.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ public static void main (String[] args) {
2525
// Join existing game.
2626
game.addGameArgs("-join 127.0.0.1"); // Connect to a host for a multiplayer game.
2727

28-
// Name Your AI.
29-
game.addGameArgs("+name AI");
28+
// Name your agent and select color
29+
// colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
30+
game.addGameArgs("+name AI +colorset 0");
3031

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

examples/java/CIGBots.java

+35-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public static void main (String[] args) {
1111

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

14-
1514
// Use CIG example config or Your own.
1615
game.loadConfig("../../examples/config/cig.cfg");
1716

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

28-
// Name Your AI.
29-
game.addGameArgs("+name AI");
27+
// Name your agent and select color
28+
// colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
29+
game.addGameArgs("+name AI +colorset 0");
3030

31-
game.setMode(Mode.ASYNC_PLAYER); // Multiplayer requires the use of asynchronous modes.
31+
game.setMode(Mode.ASYNC_PLAYER); // Multiplayer requires the use of asynchronous modes.
3232
game.init();
3333

34-
for(int i=0; i < 7; ++i) {
35-
game.sendGameCommand("addbot");
36-
}
3734

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

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

43-
// Or observe the game until automatic respawn.
44-
//game.advanceAction();
45-
//continue;
40+
System.out.println("Episode #" + (i + 1));
41+
42+
// Add specific number of bots
43+
// (file examples/bots.cfg must be placed in the same directory as the Doom executable file,
44+
// edit this file to adjust bots).
45+
game.sendGameCommand("removebots");
46+
for(int b = 0; b < bots; ++b) {
47+
game.sendGameCommand("addbot");
4648
}
4749

48-
GameState state = game.getState();
49-
// Analyze the state.
50+
while(!game.isEpisodeFinished()){ // Play until the game (episode) is over.
51+
52+
if(game.isPlayerDead()){ // Check if player is dead
53+
game.respawnPlayer(); // Use this to respawn immediately after death, new state will be available.
5054

51-
int[] action= new int[game.getAvailableButtonsSize()];
52-
// Set your action.
55+
// Or observe the game until automatic respawn.
56+
//game.advanceAction();
57+
//continue;
58+
}
5359

54-
game.makeAction(action);
60+
GameState state = game.getState();
61+
// Analyze the state.
62+
63+
int[] action= new int[game.getAvailableButtonsSize()];
64+
// Set your action.
65+
66+
game.makeAction(action);
67+
68+
System.out.println(game.getEpisodeTime() + " Frags: " + game.getGameVariable(GameVariable.FRAGCOUNT));
69+
}
5570

56-
System.out.println(game.getEpisodeTime() + " Frags: " + game.getGameVariable(GameVariable.FRAGCOUNT));
71+
System.out.println("Episode finished.");
72+
System.out.println("************************");
5773
}
5874

5975
game.close();

examples/java/CIGHost.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,17 @@ public static void main (String[] args) {
3232
+"+sv_spawnfarthest 1 " // Players will be spawned as far as possible from any other players.
3333
+"+vizdoom_nocheat 1"); // Disables depth buffer and the ability to use commands that could interfere with multiplayer game.
3434

35-
// Name Your AI.
36-
game.addGameArgs("+name AI");
35+
// Name your agent and select color
36+
// colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
37+
game.addGameArgs("+name AI +colorset 0");
3738

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

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

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

4647
// Or observe the game until automatic respawn.
4748
//game.advanceAction();

examples/python/cig.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22

33
from __future__ import print_function
44
from vizdoom import *
55
from random import choice
66

77
game = DoomGame()
88

9-
# Use CIG example config or Your own.
9+
# Use CIG example config or your own.
1010
game.load_config("../../examples/config/cig.cfg")
1111

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

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

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

2526
# Multiplayer requires the use of asynchronous modes.
26-
game.set_mode(Mode.ASYNC_PLAYER)
27+
game.set_mode(Mode.ASYNC_SPECTATOR)
2728

28-
# game.set_window_visible(false)
29+
#game.set_window_visible(false)
2930

3031
game.init()
3132

examples/python/cig_bots.py

+48-26
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,84 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22

33
from __future__ import print_function
44
from vizdoom import *
55
from random import choice
6+
from time import sleep
67

78
game = DoomGame()
89

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

11-
# Use CIG example config or Your own.
12+
# Use CIG example config or your own.
1213
game.load_config("../../examples/config/cig.cfg")
1314

14-
# Select game and map You want to use.
15+
# Select game and map you want to use.
1516
game.set_doom_game_path("../../scenarios/freedoom2.wad")
1617
#game.set_doom_game_path("../../scenarios/doom2.wad") # Not provided with environment due to licences
1718

1819
game.set_doom_map("map01") # Limited deathmatch.
1920
#game.set_doom_map("map02") # Full deathmatch.
2021

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

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

2831
# Multiplayer requires the use of asynchronous modes, but when playing only with bots, synchronous modes can also be used.
29-
game.set_mode(Mode.PLAYER)
32+
game.set_mode(Mode.ASYNC_PLAYER)
3033

31-
# game.set_window_visible(false)
34+
# game.set_window_visible(False)
3235

3336
game.init()
3437

3538
# Three example sample actions
3639
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]]
3740

38-
# Add bots (file examples/bots.cfg must be placed in the same directory as the Doom executable file).
39-
bots_number = 7
40-
for i in range(bots_number):
41-
game.send_game_command("addbot")
41+
# Play with this many bots
42+
bots = 7
43+
44+
# Run this many episodes
45+
episodes = 10
46+
47+
for i in range(episodes):
48+
49+
print("Episode #" + str(i+1))
50+
51+
# Add specific number of bots
52+
# (file examples/bots.cfg must be placed in the same directory as the Doom executable file,
53+
# edit this file to adjust bots).
54+
game.send_game_command("removebots")
55+
for i in range(bots):
56+
game.send_game_command("addbot")
57+
58+
# Play until the game (episode) is over.
59+
while not game.is_episode_finished():
60+
61+
if game.is_player_dead():
62+
# Use this to respawn immediately after death, new state will be available.
63+
game.respawn_player()
64+
65+
# Or observe the game until automatic respawn.
66+
#game.advance_action();
67+
#continue;
4268

43-
# Play until the game (episode) is over.
44-
while not game.is_episode_finished():
69+
s = game.get_state()
70+
# Analyze the state.
4571

46-
if game.is_player_dead():
47-
# Use this to respawn immediately after death, new state will be available.
48-
game.respawn_player()
72+
game.make_action(choice(actions))
73+
# Make your action.
4974

50-
# Or observe the game until automatic respawn.
51-
#game.advance_action();
52-
#continue;
75+
print("Frags:", game.get_game_variable(GameVariable.FRAGCOUNT))
5376

54-
s = game.get_state()
55-
# Analyze the state.
77+
print("Episode finished.")
78+
print("************************")
5679

57-
game.make_action(choice(actions))
58-
# Make your action.
80+
# Starts a new episode. All players have to call new_episode() in multiplayer mode.
81+
game.new_episode()
5982

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

6284
game.close()

0 commit comments

Comments
 (0)