forked from Farama-Foundation/ViZDoom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CIGBots.cpp
75 lines (51 loc) · 2.58 KB
/
CIGBots.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "ViZDoom.h"
#include <iostream>
#include <vector>
using namespace vizdoom;
int main(){
std::cout << "\n\nCIG BOTS EXAMPLE\n\n";
DoomGame* game = new DoomGame();
// Use CIG example config or Your own.
game->loadConfig("../../scenarios/cig.cfg");
// Select game and map You want to use.
game->setDoomGamePath("../../bin/freedoom2.wad");
//game->setDoomGamePath("../../bin/doom2.wad"); // Not provided with environment due to licences.
game->setDoomMap("map01"); // Limited deathmatch.
//game->setDoomMap("map02"); // Full deathmatch.
// 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 1.0 "
"+sv_forcerespawn 1 +sv_noautoaim 1 +sv_respawnprotect 1 +sv_spawnfarthest 1 +sv_nocrouch 1 "
"+viz_respawn_delay 10 +viz_nocheat 1");
// 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);
game->init();
int bots = 7; // Play with this many bots
int episodes = 10; // Run this many episodes
for(int i = 0; i < episodes; ++i) {
std::cout << "Episode #" << i + 1 << "\n";
// 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");
}
while (!game->isEpisodeFinished()) { // Play until the game (episode) is over.
GameStatePtr state = game->getState();
// Analyze the state.
std::vector<double> action(game->getAvailableButtonsSize());
// Set your action.
game->makeAction(action);
if(game->isPlayerDead()){ // Check if player is dead
game->respawnPlayer(); // Use this to respawn immediately after death, new state will be available.
}
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();
}