/
bot_simple.cc
70 lines (55 loc) · 1.8 KB
/
bot_simple.cc
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
#include "sc2api/sc2_api.h"
#include "sc2lib/sc2_lib.h"
#include "sc2utils/sc2_manage_process.h"
#include <iostream>
class FooBot : public sc2::Agent {
public:
uint32_t restarts_;
FooBot() :
restarts_(0) {
}
virtual void OnGameStart() final {
std::cout << "Starting a new game (" << restarts_ << " restarts)" << std::endl;
};
virtual void OnStep() final {
uint32_t game_loop = Observation()->GetGameLoop();
if (game_loop % 100 == 0) {
sc2::Units units = Observation()->GetUnits(sc2::Unit::Alliance::Self);
for (auto& it_unit : units) {
sc2::Point2D target = sc2::FindRandomLocation(Observation()->GetGameInfo());
Actions()->UnitCommand(it_unit, sc2::ABILITY_ID::SMART, target);
}
}
};
virtual void OnGameEnd() final {
++restarts_;
std::cout << "Game ended after: " << Observation()->GetGameLoop() << " loops " << std::endl;
};
private:
};
//*************************************************************************************************
int main(int argc, char* argv[]) {
sc2::Coordinator coordinator;
if (!coordinator.LoadSettings(argc, argv)) {
return 1;
}
// Add the custom bot, it will control the players.
FooBot bot;
coordinator.SetParticipants({
CreateParticipant(sc2::Race::Terran, &bot),
CreateComputer(sc2::Race::Terran)
});
// Start the game.
coordinator.LaunchStarcraft();
// Step forward the game simulation.
bool do_break = false;
while (!do_break) {
coordinator.StartGame(sc2::kMapBelShirVestigeLE);
while (coordinator.Update() && !do_break) {
if (sc2::PollKeyPress()) {
do_break = true;
}
}
}
return 0;
}