diff --git a/README.md b/README.md index 64dd6523ddfbb43d633906e03a854c98bcd2cb2f..0dfcf54ed2fd22b54d3fe02d1d66ac24cd97db09 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Key differences: * Everything is built using cmake, allowing for one Visual studio project to build PyCommandCenter together with all its dependencies -[Download page for Windows](https://gitlab.ida.liu.se/starcraft-api/pycommandcenter/tags) +[Download page for Windows](https://gitlab.ida.liu.se/course-starcraft-ai/pycommandcenter/tags) # Code example for making a bot @@ -68,10 +68,10 @@ First you need to make sure you got all the build dependencies: Now, you are ready to build the python library: -1. Open up a terminal, download the source code using the command: `git clone --recurse-submodules https://gitlab.ida.liu.se/starcraft-api/pycommandcenter.git` +1. Open up a terminal, download the source code using the command: `git clone --recurse-submodules https://gitlab.ida.liu.se/course-starcraft-ai/pycommandcenter.git` 2. Next, open the repository in your file viewer and run the batch script - called `create-visual-studio-solution.bat` in order to use cmake to create a - Visual studio solution + called `create-visual-studio-solution.bat` in order to use cmake to create + a Visual studio solution 3. Open the Visual Studio solution located in the newly created directory `build/` 4. The project called `library` should be selected as the default StartUp @@ -88,7 +88,7 @@ Now, you are ready to build the python library: Same dependencies applies as for Windows, although you don't need Visual Studio. -1. Open up a terminal, download the source code using the command: `git clone --recurse-submodules https://gitlab.ida.liu.se/starcraft-api/pycommandcenter.git` +1. Open up a terminal, download the source code using the command: `git clone --recurse-submodules https://gitlab.ida.liu.se/course-starcraft-ai/pycommandcenter.git` 2. Next, enter the directory and run the command `mkdir build` followed by `cd build` and `cmake ..` in order to create the makefiles needed for building the library. diff --git a/docs/constants.rst b/docs/constants.rst index dfdc992a1d7f16b2ca6c29ddfcb2fcf17eed8839..fd97774e4cc502c0b5c2733e2e587c19d8911069 100644 --- a/docs/constants.rst +++ b/docs/constants.rst @@ -36,6 +36,6 @@ Race .. attribute:: Race.Terran .. attribute:: Race.Zerg - This means a randomly selected race from the three above: + The following attribute means a randomly selected race from the three above: .. attribute:: Race.Random diff --git a/pycharm.md b/pycharm.md index 44c2b360f44029f1d7ae5d58c8102c920eba73d3..5026e1106108e34d8da2db73822b0e1880b07ace 100644 --- a/pycharm.md +++ b/pycharm.md @@ -1,13 +1,13 @@ # Installing PyCommandCenter in PyCharm -Start of by download the library from the [PyCommandCenter repository](https://gitlab.ida.liu.se/starcraft-api/pycommandcenter/tags). +Start by downloading the library from the [PyCommandCenter repository](https://gitlab.ida.liu.se/course-starcraft-ai/pycommandcenter/tags). Place the library in your repository. Add the library to the Python path in Python by: -1. File->Settings->Project: (project name)->Project Interpreter -2. Select the cog in the upper right corner and select "Show All" -3. In the new window that opens select the icon which shows a few folders connected with lines -4. In the new window press the plus icon and select the path of your repository (should be where you placed the library) -5. Restart PyCharm with File->Invalidate Caches/Restart->Invalidate and Restart +1. File->Settings->Project: (project name)->Project Interpreter. +2. Select the cog in the upper right corner and select "Show All". +3. In the new window that opens, select the icon which shows a few folders connected with lines. +4. In the new window, first press the plus icon, and then select the path of your repository (the path to where you placed the library). +5. Restart PyCharm with "File->Invalidate Caches/Restart->Invalidate and Restart". \ No newline at end of file diff --git a/python-api-src/lib_base_location.cpp b/python-api-src/lib_base_location.cpp index 6293a37aaed935eb80fcc79f426b474eb29f09e7..9f18f8af329642f301634390b56f898ff6e4bdd9 100644 --- a/python-api-src/lib_base_location.cpp +++ b/python-api-src/lib_base_location.cpp @@ -9,7 +9,7 @@ void define_base_location(py::module & m) .def_property_readonly("minerals", &BaseLocation::getMinerals, "List of mineral fields at base location (List of unit)") .def_property_readonly("mineral_fields", &BaseLocation::getMinerals, "Alias for minerals in order to differentiate from harvested minerals") .def_property_readonly("is_start_location", &BaseLocation::isStartLocation, "True if the base location is a start location, False otherwise") - .def_property_readonly("depot_position", &BaseLocation::getDepotPosition, "Point2DI position suitable for placing a town hall") + .def_property_readonly("depot_position", &BaseLocation::getDepotPosition, "Point2DI position suitable for placing a town hall (base structure)") .def_property_readonly("position", &BaseLocation::getPosition) .def("get_ground_distance", py::overload_cast<const CCPosition &>(&BaseLocation::getGroundDistance, py::const_)) .def("get_ground_distance", py::overload_cast<const CCTilePosition &>(&BaseLocation::getGroundDistance, py::const_)) diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index 50ec422acb00f0f77d3aa241b671a3fdd45b89fa..e8d5ff9975a194a93587c6384bd545b61eadc30f 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -63,7 +63,7 @@ PYBIND11_MODULE(library, m) .def(py::init()); // IDABot is a specialization of Agent - py::class_<IDABot, PyIDABot, sc2::Agent>(m, "IDABot") + py::class_<IDABot, PyIDABot, sc2::Agent>(m, "IDABot") .def(py::init()) .def("on_game_start", &IDABot::OnGameStart) .def("on_step", &IDABot::OnStep) @@ -78,7 +78,10 @@ PYBIND11_MODULE(library, m) .def_property_readonly("minerals", &IDABot::GetMinerals, "How much minerals we currently have") .def_property_readonly("current_supply", &IDABot::GetCurrentSupply, "How much supply we are currently using") .def_property_readonly("max_supply", &IDABot::GetMaxSupply, "How much supply we can currently use") - .def_property_readonly("gas", &IDABot::GetGas, "How much gas we currently have"); + .def_property_readonly("gas", &IDABot::GetGas, "How much gas we currently have") + .def("use_ability", &IDABot::UseAbility, "Use an ability with the given unit") + .def("use_ability", &IDABot::UseAbilityWithPoint, "Use ability at point with the given unit") + .def("use_ability", &IDABot::UseAbilityWithTarget, "Use ability at target with the given unit"); py::class_<sc2::PlayerSetup>(m, "PlayerSetup"); diff --git a/src/IDABot.cpp b/src/IDABot.cpp index f61dc8329e06685f6078df8c859dd01619207af1..5705dffe94268775333d0223686a1952417ef31d 100644 --- a/src/IDABot.cpp +++ b/src/IDABot.cpp @@ -219,3 +219,17 @@ const TypeData & IDABot::Data(const MetaType & type) const return m_techTree.getData(type); } +void IDABot::UseAbility(const Unit& unit, sc2::AbilityID ability) +{ + Actions()->UnitCommand(unit.getUnitPtr(), ability, false); +} + +void IDABot::UseAbilityWithPoint(const Unit& unit, sc2::AbilityID ability, const sc2::Point2D& point) +{ + Actions()->UnitCommand(unit.getUnitPtr(), ability, point, false); +} + +void IDABot::UseAbilityWithTarget(const Unit& unit, sc2::AbilityID ability, const Unit* target) +{ + Actions()->UnitCommand(unit.getUnitPtr(), ability, target->getUnitPtr(), false); +} diff --git a/src/IDABot.h b/src/IDABot.h index eca954f01a1857bf31747ae128a239b86dc19e88..100b581a5ba449b8c50df19e31b9b037b281e3af 100644 --- a/src/IDABot.h +++ b/src/IDABot.h @@ -62,4 +62,9 @@ public: const TypeData & Data(const CCUpgrade & type) const; const TypeData & Data(const MetaType & type) const; const TypeData & Data(const Unit & unit) const; + + // Used for giving "raw" commands to units + void UseAbility(const Unit& unit, sc2::AbilityID ability); + void UseAbilityWithPoint(const Unit& unit, sc2::AbilityID ability, const sc2::Point2D& point); + void UseAbilityWithTarget(const Unit& unit, sc2::AbilityID ability, const Unit* target); };