|
1 |
| -#!/usr/bin/python |
| 1 | +#!/usr/bin/env python |
2 | 2 |
|
3 | 3 | from __future__ import print_function
|
4 | 4 | from vizdoom import *
|
5 | 5 | from random import choice
|
| 6 | +from time import sleep |
6 | 7 |
|
7 | 8 | game = DoomGame()
|
8 | 9 |
|
9 | 10 | game.set_vizdoom_path("../../bin/vizdoom")
|
10 | 11 |
|
11 |
| -# Use CIG example config or Your own. |
| 12 | +# Use CIG example config or your own. |
12 | 13 | game.load_config("../../examples/config/cig.cfg")
|
13 | 14 |
|
14 |
| -# Select game and map You want to use. |
| 15 | +# Select game and map you want to use. |
15 | 16 | game.set_doom_game_path("../../scenarios/freedoom2.wad")
|
16 | 17 | #game.set_doom_game_path("../../scenarios/doom2.wad") # Not provided with environment due to licences
|
17 | 18 |
|
18 | 19 | game.set_doom_map("map01") # Limited deathmatch.
|
19 | 20 | #game.set_doom_map("map02") # Full deathmatch.
|
20 | 21 |
|
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 " |
23 | 24 | "+sv_forcerespawn 1 +sv_noautoaim 1 +sv_respawnprotect 1 +sv_spawnfarthest 1")
|
24 | 25 |
|
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 | + |
27 | 30 |
|
28 | 31 | # 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) |
30 | 33 |
|
31 |
| -# game.set_window_visible(false) |
| 34 | +# game.set_window_visible(False) |
32 | 35 |
|
33 | 36 | game.init()
|
34 | 37 |
|
35 | 38 | # Three example sample actions
|
36 | 39 | 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]]
|
37 | 40 |
|
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; |
42 | 68 |
|
43 |
| -# Play until the game (episode) is over. |
44 |
| -while not game.is_episode_finished(): |
| 69 | + s = game.get_state() |
| 70 | + # Analyze the state. |
45 | 71 |
|
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. |
49 | 74 |
|
50 |
| - # Or observe the game until automatic respawn. |
51 |
| - #game.advance_action(); |
52 |
| - #continue; |
| 75 | + print("Frags:", game.get_game_variable(GameVariable.FRAGCOUNT)) |
53 | 76 |
|
54 |
| - s = game.get_state() |
55 |
| - # Analyze the state. |
| 77 | + print("Episode finished.") |
| 78 | + print("************************") |
56 | 79 |
|
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() |
59 | 82 |
|
60 |
| - print("Frags:", game.get_game_variable(GameVariable.FRAGCOUNT)) |
61 | 83 |
|
62 | 84 | game.close()
|
0 commit comments