diff --git a/docs/constants.rst b/docs/constants.rst index fd97774e4cc502c0b5c2733e2e587c19d8911069..f75b8535ddfbc859aa49b75c7110fb012100ea6d 100644 --- a/docs/constants.rst +++ b/docs/constants.rst @@ -25,6 +25,13 @@ Difficulty :members: :undoc-members: +AIBuild +------- + +.. autoclass:: library.AIBuild + :members: + :undoc-members: + Race ---- diff --git a/docs/gettingstarted.rst b/docs/gettingstarted.rst index 4d8997451b8d86f1eff424f2f96741d21f56d756..037793e338f9110230000d487491afb6ac174866 100644 --- a/docs/gettingstarted.rst +++ b/docs/gettingstarted.rst @@ -127,6 +127,14 @@ However, your bot might will probably be able to play the game faster. If you remove or comment out this line the game will run as fast as possible, only waiting for your bot to return from `on_step`. +If you want to train your agent on certain type of bots. For example, If we +want the opponent to focus on air strategy. You can add the +following line to the bot. + +.. code-block:: python + + participant_2 = create_computer(Race.Random, Difficulty.Easy, AIBuild.Air) + We can also play two bots against each other by changing the row: .. code-block:: python diff --git a/docs/idabot.rst b/docs/idabot.rst index f5f9004d66608c797e6938b94dbc56f209c43b11..a2c4d935a844bea19b70185e00ba7afeeac574a8 100644 --- a/docs/idabot.rst +++ b/docs/idabot.rst @@ -59,9 +59,13 @@ IDABot Sends the string 'message' to the game chat - .. method:: IDABot.carry_vespene(self, unit) -> Boolean - - "Returns true if unit carries a vespene" + .. method:: IDABot.has_creep(self, Point2D) -> Boolean + + Returns if the position has a creep. + + .. method:: IDABot.move_camera(self, Point2DI) + + Move the camera to the position. Attributes: @@ -74,3 +78,88 @@ IDABot .. autoattribute:: max_supply .. autoattribute:: current_frame + +Debug +----- + +When developing AI-methods or when simply having a problem. +The debug-methods are a great tool for speeding up the process. + + .. method:: IDABot.debug_create_unit(self, UnitTypeID, Point2D, Player Constant, Int) + + This method creates the nr (INT) of units on the position of the Point2D, the unit + belongs to the Player Constant. + + .. method:: IDABot.debug_kill_unit(self, Unit) + + Kills the unit. + + .. method:: IDABot.debug_show_map(self) + + Make the entire map visible. + + .. method:: IDABot.debug_fast_build(self) + + Set the build time in game to 1. + + .. method:: IDABot.debug_enemy_control(self) + + Gives the player full control over the enemy. + + .. method:: IDABot.debug_fast_build(self) + + Set the build time in game to 1. + + .. method:: IDABot.debug_ignore_food(self) + + Ignore food in game. + + .. method:: IDABot.debug_ignore_resource_cost(self) + + Ignore the resource cost in game. Everything cost 0 resources. + + .. method:: IDABot.debug_give_all_resources(self) + + Set the mineral and vespene gas to 5000. + + .. method:: IDABot.debug_god_mode(self) + + Give yourself god mode in the game. + + .. method:: IDABot.debug_ignore_mineral(self) + + Ignore the mineral cost in the game. + + .. method:: IDABot.debug_no_cooldowns(self) + + Deactivate cooldowns (Basically setting them to 0). + + .. method:: IDABot.debug_give_all_tech(self) + + Give yourself all tech. + + .. method:: IDABot.debug_give_all_upgrades(self) + + Give yourself all upgrades. + + .. method:: IDABot.debug_set_score(self, Float) + + Set the player score in game. + + .. method:: IDABot.debug_end_game(self, Boolean) + + End the game, if the Boolean is True then victory. + If False, defeat. + + .. method:: IDABot.debug_set_energy(self, Float, Unit) + + Set the amount (Float) of energy to the unit. + + .. method:: IDABot.debug_set_life(self, Float, Unit) + + Set the amount (Float) of life to the unit. + + .. method:: IDABot.debug_set_shields(self, Float, Unit) + + Set the amount (Float) of shield to the unit. + diff --git a/docs/unit.rst b/docs/unit.rst index 84c9b02aeac5a1ffad5fb0cc99a7e193b5fb8d69..28fd1a45ac0a54a12afde46ab2e0c82a87787734 100644 --- a/docs/unit.rst +++ b/docs/unit.rst @@ -77,7 +77,7 @@ Unit Returns if this unit is currently holding minerals - .. autoattribute:: is_carrying_minerals + .. autoattribute:: is_carrying_gas Returns if this unit is currently holding gas @@ -85,6 +85,19 @@ Unit Returns target if unit has one, otherwise will fail the assertion (make sure not to call this unless certain that the unit has a target!). + .. autoattribute:: gas_left_in_refinery + + This is used on the geyser. + Returns the amount of gas left in refinery. + + .. autoattribute:: minerals_left_in_mineralfield + + Returns the amount of minerals left in mineralfield. + + .. autoattribute:: owner + + Returns the Player ID, the owner of the unit. + Methods: .. automethod:: ability diff --git a/python-api-src/lib_map_tools.cpp b/python-api-src/lib_map_tools.cpp index 65c421d80f8d6ccbf520bb05a2771f1d74fdce84..2f76c2b6091c536f60f70653de1d6af21862c8a9 100644 --- a/python-api-src/lib_map_tools.cpp +++ b/python-api-src/lib_map_tools.cpp @@ -20,6 +20,7 @@ void define_map_tools(py::module & m) .def("draw_line", py::overload_cast<const CCPosition &, const CCPosition &, const CCColor &>(&MapTools::drawLine, py::const_), py::arg("start"), py::arg("stop"), py::arg("color") = sc2::Colors::White) .def("draw_box", py::overload_cast<const CCPosition &, const CCPosition &, const CCColor &>(&MapTools::drawBox, py::const_), py::arg("top_left"), py::arg("bottom_right"), py::arg("color") = sc2::Colors::White) .def("draw_circle", py::overload_cast<const CCPosition &, CCPositionType, const CCColor &>(&MapTools::drawCircle, py::const_), py::arg("center"), py::arg("radius"), py::arg("color") = sc2::Colors::White) + .def("draw_resource_circle", &MapTools::drawResourceCircle, py::arg("center"), py::arg("radius"), py::arg("color") = sc2::Colors::White) .def("draw_text", &MapTools::drawText, "position"_a, "text"_a, "color"_a = sc2::Colors::White) .def("draw_text_screen", &MapTools::drawTextScreen, "percentage_x"_a, "percentage_y"_a, "text"_a, "color"_a = sc2::Colors::White) .def("is_valid_tile", py::overload_cast<int, int>(&MapTools::isValidTile, py::const_), "x"_a, "y"_a) diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index e183d8d498b49251a4c20176fb932651459487f2..7278c8a6bd573454873609082421ef98eed3ed7e 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -95,7 +95,7 @@ PYBIND11_MODULE(library, m) .def("debug_end_game", &IDABot::DebugEndGame, "End the game through debug mode") .def("debug_set_energy", &IDABot::DebugSetEnergy, "Set the energy on a unit through debug mode") .def("debug_set_life", &IDABot::DebugSetLife, "Set the life on a unit through debug mode") - .def("debug_set_shield", &IDABot::DebugSetShields, "Set the shields on a unit through debug mode") + .def("debug_set_shields", &IDABot::DebugSetShields, "Set the shields on a unit through debug mode") .def("get_enemy_base_location", &IDABot::GetEnemyBaseLocations, "Return the CCpostion of the enemy base") .def("move_camera", &IDABot::CameraMove, "Move the camera to p postion", "p"_a) .def("has_creep", &IDABot::HasCreep, "Returns true if there is creep at position p", "p"_a) @@ -132,7 +132,8 @@ PYBIND11_MODULE(library, m) .value("Rush", sc2::AIBuild::Rush) .value("Timing", sc2::AIBuild::Timing) .value("Power", sc2::AIBuild::Power) - .value("Macro", sc2::AIBuild::Air); + .value("Macro", sc2::AIBuild::Macro) + .value("Air", sc2::AIBuild::Air); m.def("create_participants", &sc2::CreateParticipant, "Create participant from bot", "race"_a, "bot"_a, "player_name"_a = ""); diff --git a/src/BaseLocation.cpp b/src/BaseLocation.cpp index d5f89e36834216d2a396286eb852fc1522f0e19c..f601e4ee42d8a43eb6357522fbba026191266981 100644 --- a/src/BaseLocation.cpp +++ b/src/BaseLocation.cpp @@ -202,7 +202,9 @@ void BaseLocation::draw() { CCPositionType radius = Util::TileToPosition(1.0f); - m_bot.Map().drawCircle(m_centerOfResources, radius, CCColor(255, 255, 0)); + // Take first mineral for the Z-pos. + sc2::Point3D center_pos = sc2::Point3D(m_centerOfResources.x, m_centerOfResources.y, m_minerals[0].getUnitPtr()->pos.z); + m_bot.Map().drawResourceCircle(center_pos, radius, CCColor(255, 255, 0)); std::stringstream ss; ss << "BaseLocation: " << m_baseID << "\n"; @@ -237,14 +239,14 @@ void BaseLocation::draw() //m_bot.Map().drawLine(m_left, y, m_right, y, CCColor(160, 160, 160)); } - for (auto & mineralPos : m_mineralPositions) + for (auto & mineral : m_minerals) { - m_bot.Map().drawCircle(mineralPos, radius, CCColor(0, 128, 128)); + m_bot.Map().drawResourceCircle(mineral.getUnitPtr()->pos, radius, CCColor(0, 128, 128)); } - for (auto & geyserPos : m_geyserPositions) + for (auto & geyser : m_geysers) { - m_bot.Map().drawCircle(geyserPos, radius, CCColor(0, 255, 0)); + m_bot.Map().drawResourceCircle(geyser.getUnitPtr()->pos, radius, CCColor(0, 255, 0)); } if (m_isStartLocation) diff --git a/src/BaseLocationManager.cpp b/src/BaseLocationManager.cpp index 0e44fc4448b348c2cbb53c9319e56418dc068f0b..512f233c6af0b0e4e5a7227d86bd18b0486c37ad 100644 --- a/src/BaseLocationManager.cpp +++ b/src/BaseLocationManager.cpp @@ -269,7 +269,7 @@ void BaseLocationManager::drawBaseLocations() const BaseLocation * next_expansion = getNextExpansion(Players::Self); CCTilePosition nextExpansionPosition = next_expansion->getDepotPosition(); - m_bot.Map().drawCircle(Util::GetPosition(nextExpansionPosition), 1, CCColor(255, 0, 255)); + m_bot.Map().drawResourceCircle(sc2::Point3D(Util::GetPosition(nextExpansionPosition).x, Util::GetPosition(nextExpansionPosition).y, next_expansion->getMinerals()[0].getUnitPtr()->pos.z), 1, CCColor(255, 0, 255)); m_bot.Map().drawText(Util::GetPosition(nextExpansionPosition), "Next Expansion Location", CCColor(255, 0, 255)); } diff --git a/src/IDABot.cpp b/src/IDABot.cpp index dc70bd380867149a14aaaa83399a3f52ed4f11a1..dc0cb3601e037ac495a32e29381ed98ae202d5a9 100644 --- a/src/IDABot.cpp +++ b/src/IDABot.cpp @@ -322,6 +322,8 @@ void IDABot::DebugSetShields(float value, const Unit unit) // There is a bug in the latest SC2 // This a function to get the enemy base instead of using build location manager +// Switched over to other API where this is solved +// Leaving function incase of it breaking const std::vector<Point2D> IDABot::GetEnemyBaseLocations() { return Observation()->GetGameInfo().enemy_start_locations; diff --git a/src/MapTools.cpp b/src/MapTools.cpp index 9714266742e38929b60d91ce67a85fda34ef1b36..652968cbfd98ba2181444b87e2657eb54f4367ff 100644 --- a/src/MapTools.cpp +++ b/src/MapTools.cpp @@ -401,6 +401,15 @@ void MapTools::drawCircle(const CCPosition & pos, CCPositionType radius, const C #endif } +void MapTools::drawResourceCircle(const sc2::Point3D & pos, CCPositionType radius, const CCColor & color) const +{ +#ifdef SC2API + m_bot.Debug()->DebugSphereOut(pos, radius, color); +#else + BWAPI::Broodwar->drawCircleMap(pos, radius, color); +#endif +} + void MapTools::drawCircle(CCPositionType x, CCPositionType y, CCPositionType radius, const CCColor & color) const { #ifdef SC2API diff --git a/src/MapTools.h b/src/MapTools.h index 8453345e01667597071510cd7095f5b6805367d4..025083a3cde21f213f2e10d7c76eb389dd428e25 100644 --- a/src/MapTools.h +++ b/src/MapTools.h @@ -54,6 +54,7 @@ public: void drawBox(const CCPosition & tl, const CCPosition & br, const CCColor & color = CCColor(255, 255, 255)) const; void drawCircle(CCPositionType x1, CCPositionType x2, CCPositionType radius, const CCColor & color = CCColor(255, 255, 255)) const; void drawCircle(const CCPosition & pos, CCPositionType radius, const CCColor & color = CCColor(255, 255, 255)) const; + void drawResourceCircle(const sc2::Point3D & pos, CCPositionType radius, const CCColor & color = CCColor(255, 255, 255)) const; void drawText(const CCPosition & pos, const std::string & str, const CCColor & color = CCColor(255, 255, 255)) const; void drawTextScreen(float xPerc, float yPerc, const std::string & str, const CCColor & color = CCColor(255, 255, 255)) const;