MCPcopy Create free account
hub / github.com/bwapi/bwapi / main

Function main

bwapi/ExampleAIClient/Source/ExampleAIClient.cpp:27–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27int main(int argc, const char* argv[])
28{
29 std::cout << "Connecting..." << std::endl;;
30 reconnect();
31 while(true)
32 {
33 std::cout << "waiting to enter match" << std::endl;
34 while ( !Broodwar->isInGame() )
35 {
36 BWAPI::BWAPIClient.update();
37 if (!BWAPI::BWAPIClient.isConnected())
38 {
39 std::cout << "Reconnecting..." << std::endl;;
40 reconnect();
41 }
42 }
43 std::cout << "starting match!" << std::endl;
44 Broodwar->sendText("Hello world!");
45 Broodwar << "The map is " << Broodwar->mapName() << ", a " << Broodwar->getStartLocations().size() << " player map" << std::endl;
46 // Enable some cheat flags
47 Broodwar->enableFlag(Flag::UserInput);
48 // Uncomment to enable complete map information
49 //Broodwar->enableFlag(Flag::CompleteMapInformation);
50
51 show_bullets=false;
52 show_visibility_data=false;
53
54 if (Broodwar->isReplay())
55 {
56 Broodwar << "The following players are in this replay:" << std::endl;;
57 Playerset players = Broodwar->getPlayers();
58 for(auto p : players)
59 {
60 if ( !p->getUnits().empty() && !p->isNeutral() )
61 Broodwar << p->getName() << ", playing as " << p->getRace() << std::endl;
62 }
63 }
64 else
65 {
66 if (Broodwar->enemy())
67 Broodwar << "The match up is " << Broodwar->self()->getRace() << " vs " << Broodwar->enemy()->getRace() << std::endl;
68
69 //send each worker to the mineral field that is closest to it
70 Unitset units = Broodwar->self()->getUnits();
71 Unitset minerals = Broodwar->getMinerals();
72 for ( auto &u : units )
73 {
74 if ( u->getType().isWorker() )
75 {
76 Unit closestMineral = nullptr;
77
78 for (auto &m : minerals)
79 {
80 if ( !closestMineral || u->getDistance(m) < u->getDistance(closestMineral))
81 closestMineral = m;
82 }
83 if ( closestMineral )
84 u->rightClick(closestMineral);

Callers

nothing calls this directly

Calls 15

showPlayersFunction · 0.85
showForcesFunction · 0.85
drawBulletsFunction · 0.85
drawVisibilityDataFunction · 0.85
drawStatsFunction · 0.85
sendTextMethod · 0.80
isWorkerMethod · 0.80
isResourceDepotMethod · 0.80
getWorkerMethod · 0.80
isWinnerMethod · 0.80
getTextMethod · 0.80
drawCircleMapMethod · 0.80

Tested by

no test coverage detected