From 8cf95a6930e7c02b702ef5a20d8f4fe330133e16 Mon Sep 17 00:00:00 2001 From: Daniel de Leng <daniel.de.leng@liu.se> Date: Thu, 4 Jul 2024 11:48:30 +0200 Subject: [PATCH] Add missing implementation for virtual method on_game_end; update documentation --- docs/idabot.rst | 7 ++++--- python-api-src/library.cpp | 5 +++-- src/IDABot.cpp | 4 ++++ src/IDABot.h | 1 + 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/idabot.rst b/docs/idabot.rst index 61b678b61..c0d54e119 100644 --- a/docs/idabot.rst +++ b/docs/idabot.rst @@ -17,7 +17,8 @@ IDABot .. method:: IDABot.on_game_start(self) - (see :ref:`gettingstarted` for example). + This method is run when the game starts. See :ref:`gettingstarted` + for an example. .. method:: IDABot.on_step(self) @@ -27,7 +28,7 @@ IDABot .. method:: IDABot.on_game_end(self) - This method is run whenever the match ends. + This method is run whenever the match ends. Methods: @@ -99,4 +100,4 @@ Debug .. automethod:: debug_set_shields -.. toctree:: \ No newline at end of file +.. toctree:: diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index 9ac8f65eb..8ee7a7322 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -130,7 +130,8 @@ PYBIND11_MODULE(commandcenter, m) .def("on_step", &IDABot::OnStep, R"(The on_step function in the IDABot class is a method that is called every game step (or frame) during a Starcraft II match. This function is crucial for implementing the bot's logic that needs to be executed continuously throughout the game. It's where the bot evaluates the current game state, makes decisions, and issues commands to units.)") - .def("on_game_end", &IDABot::OnGameEnd) + .def("on_game_end", &IDABot::OnGameEnd, R"(The on_game_end function is a method defined in the IDABot class. It is called when a game ends in Starcraft II. + This function can for example be used to save a replay and log performance information.)") .def("send_chat", &IDABot::SendChat, "Sends the string 'message' to the game chat.", "message"_a) .def("get_all_units", &IDABot::GetAllUnits, "Returns a list of all visible units, including minerals and geysers.") .def("get_my_units", &IDABot::GetMyUnits, "Returns a list of all your units.") @@ -161,7 +162,7 @@ PYBIND11_MODULE(commandcenter, m) .def("upgrade_gas_cost", &IDABot::UpgradeGasCost, "Vespene/gas cost of researching the upgrade.", "upgrade"_a) .def("upgrade_research_time", &IDABot::UpgradeResearchTime, "Time in GameLoops to research this upgrade.", "upgrade"_a) .def("effect_radius", &IDABot::RadiusEffect, "Size of the circle the effect impacts.", "effect"_a) - .def("save_replay", &IDABot::SaveReplay, "Saves the game as a replay", "path"_a) + .def("save_replay", &IDABot::SaveReplay, "Saves the game as an SC2Replay. Returns whether successful.", "path"_a) .def_property_readonly("base_location_manager", &IDABot::Bases, "An instance of the class :class:`commandcenter.BaseLocationManager`. ") .def_property_readonly("tech_tree", &IDABot::GetTechTree, "An instance of the class :class:`commandcenter.TechTree`.") .def_property_readonly("map_tools", &IDABot::Map, "An instance of the class :class:`commandcenter.MapTools`.") diff --git a/src/IDABot.cpp b/src/IDABot.cpp index 4547b39f4..efe6acded 100644 --- a/src/IDABot.cpp +++ b/src/IDABot.cpp @@ -87,6 +87,10 @@ void IDABot::OnStep() m_buildingPlacer.drawReservedTiles(); } +void IDABot::OnGameEnd() +{ +} + void IDABot::setUnits() { m_allUnits.clear(); diff --git a/src/IDABot.h b/src/IDABot.h index 22f5736ea..40a7b9f80 100644 --- a/src/IDABot.h +++ b/src/IDABot.h @@ -38,6 +38,7 @@ public: void OnGameStart() override; void OnStep() override; + void OnGameEnd() override; /* API for students -- GitLab