BWAPI
|
00001 /* 00002 * BasicAIModule.cpp 00003 */ 00004 #include "BasicAIModule.h" 00005 #include "Strategizer.h" 00006 00007 00008 #include <BWAPI.h> 00009 #include <BWTA.h> 00010 00011 #include <string> 00012 #include <vector> 00013 00014 using namespace BWAPI; 00015 using std::string; 00016 using std::vector; 00017 00018 /* 00019 * onStart() 00020 * 00021 * Called by the game when a new match using this AI module begins 00022 */ 00023 void BasicAIModule::onStart() 00024 { 00025 /* set up BWTA */ 00026 BWTA::readMap(); 00027 BWTA::analyze(); 00028 // BWSAL::resetLog(); 00029 00030 /* requires BTWA::analyze(); */ 00031 enhancedUI = new EnhancedUI(); 00032 00033 Broodwar->enableFlag(Flag::UserInput); 00034 00035 Broodwar->sendText("UW-Madison : CS638 Software Engineering - Brood War AI"); 00036 00037 Strategizer::instance().onMatchStart(); 00038 } 00039 00040 /* 00041 * onEnd() 00042 * 00043 * Called by the game when a match using this AI module ends 00044 */ 00045 void BasicAIModule::onEnd(bool isWinner) 00046 { 00047 Strategizer::instance().onMatchEnd(isWinner); 00048 } 00049 00050 /* 00051 * onFrame() 00052 * 00053 * Called by the game on each frames 00054 */ 00055 void BasicAIModule::onFrame() 00056 { 00057 /* draw for all terrain */ 00058 enhancedUI->update(); 00059 00060 TacticalBuildingPlacer::instance().draw(); 00061 00062 /* update the Strategizer */ 00063 Strategizer::instance().update(); 00064 } 00065 00066 /* 00067 * onUnitDiscover() 00068 * 00069 */ 00070 void BasicAIModule::onUnitDiscover(Unit* unit) 00071 { 00072 const string& name = unit->getType().getName(); 00073 00074 // This conditional is temporary to filter out all the 00075 // resource and building units that BWTA finds. 00076 if( name == "Terran SCV" ) 00077 Broodwar->sendText("Unit discovered: %s", name.c_str()); 00078 } 00079 00080 /* 00081 * onUnitEvade() 00082 * 00083 */ 00084 void BasicAIModule::onUnitEvade(Unit* unit) 00085 { 00086 00087 } 00088 00089 /* 00090 * onUnitMorph() 00091 * 00092 */ 00093 void BasicAIModule::onUnitMorph(Unit* unit) 00094 { 00095 00096 } 00097 00098 /* 00099 * onUnitRenegade() 00100 * 00101 */ 00102 void BasicAIModule::onUnitRenegade(Unit* unit) 00103 { 00104 00105 } 00106 00107 /* 00108 * onUnitDestroy() 00109 * 00110 */ 00111 void BasicAIModule::onUnitDestroy(Unit* unit) 00112 { 00113 Broodwar->sendText("Unit destroyed: %s", unit->getType().getName().c_str()); 00114 } 00115 00116 /* 00117 * onSendText() 00118 * 00119 */ 00120 void BasicAIModule::onSendText(string text) 00121 { 00122 00123 } 00124 00125 /* 00126 * showPlayers() 00127 * 00128 */ 00129 void BasicAIModule::showPlayers() 00130 { 00131 00132 } 00133 00134 /* 00135 * showForces() 00136 * 00137 */ 00138 void BasicAIModule::showForces() 00139 { 00140 00141 } 00142