-
-
Notifications
You must be signed in to change notification settings - Fork 404
/
Spectator.cpp
83 lines (58 loc) · 2.76 KB
/
Spectator.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
76
77
78
79
80
81
82
83
#include "ViZDoom.h"
#include <iostream>
#include <vector>
using namespace vizdoom;
int main(){
std::cout << "\n\nSPECTATOR EXAMPLE\n\n";
DoomGame *game = new DoomGame();
// Choose scenario config file you wish to be watched by agent.
// Don't load two configs cause the second will overwrite the first one.
// Multiple config files are ok but combining these ones doesn't make much sense.
game->loadConfig("../../scenarios/basic.cfg");
//game->loadConfig("../../scenarios/deadly_corridor.cfg");
//game->loadConfig("../../scenarios/deathmatch.cfg");
//game->loadConfig("../../scenarios/defend_the_center.cfg");
//game->loadConfig("../../scenarios/defend_the_line.cfg");
//game->loadConfig("../../scenarios/health_gathering.cfg");
//game->loadConfig("../../scenarios/my_way_home.cfg");
//game->loadConfig("../../scenarios/predict_position.cfg");
//game->loadConfig("../../scenarios/take_cover.cfg");
game->setDoomGamePath("../../bin/freedoom2.wad");
//game->setDoomGamePath("../../bin/doom2.wad"); // Not provided with environment due to licences.
game->setScreenResolution(RES_640X480);
// Enables spectator mode, so You can play and agent watch your actions.
// You can only use the buttons selected as available.
game->setMode(SPECTATOR);
game->init();
// Run this many episodes
int episodes = 10;
for (int i = 0; i < episodes; ++i) {
std::cout << "Episode #" << i + 1 << "\n";
// 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()) {
// Get the state.
GameStatePtr state = game->getState();
// Advances action - lets You play next game tic.
game->advanceAction();
// You can also advance a few tics at once.
// game->advanceAction(4);
// Get the last action performed by You.
std::vector<double> lastAction = game->getLastAction();
// And reward You get.
double reward = game->getLastReward();
std::cout << "State #" << state->number << "\n";
std::cout << "Action made:";
for(auto a: lastAction) std::cout << " " << a;
std::cout << "\n";
std::cout << "Action reward: " << reward <<"\n";
std::cout << "=====================\n";
}
std::cout << "Episode finished.\n";
std::cout << "Total reward: " << game->getTotalReward() << "\n";
std::cout << "************************\n";
}
// It will be done automatically in destructor but after close You can init it again with different settings.
game->close();
delete game;
}