From 08a679e1c9914281d1faeba7d8a01bd2577415dc Mon Sep 17 00:00:00 2001 From: Rojikku98 <be.edvin@gmail.com> Date: Mon, 27 Jul 2020 13:30:49 +0200 Subject: [PATCH] Some smallfixes --- docs/idareplayobserver.rst | 14 +++++++------- docs/index.rst | 3 +++ docs/replays.rst | 16 ++++++++++------ docs/replayunit.rst | 4 ++-- python-api-src/library.cpp | 1 + src/IDAReplayObserver.cpp | 15 +++++++++++++++ src/IDAReplayObserver.h | 1 + 7 files changed, 39 insertions(+), 15 deletions(-) diff --git a/docs/idareplayobserver.rst b/docs/idareplayobserver.rst index c0753c9ac..3c8f696b2 100644 --- a/docs/idareplayobserver.rst +++ b/docs/idareplayobserver.rst @@ -1,15 +1,15 @@ -IDABot -====== +IDAReplayObserver +================= .. class:: library.IDAReplayObserver - This is the basis of a replayObserver. + This is a class for following a replay. Se :ref:`Replays <replays>` for a example. Inherited methods: .. method:: IDAReplayObserver.on_game_start(self) - This method is called when a Starcraft replay has stared, when you inherit it you have to + This method is called when a replay has stared, when you inherit it you have to call the parent's on_game_start method in order to make it work (see :ref:`replays`). @@ -27,13 +27,13 @@ IDABot Methods: - .. method:: IDABot.get_all_units(self) -> List[library.ReplayUnit] + .. method:: IDAReplayObserver.get_all_units(self) -> List[library.ReplayUnit] Retrieves a list of all visible units + .. method:: IDAReplayObserver.get_player_race(self, player_id) -> library.Race - Attributes: + Returns the players race - .. autoattribute:: minerals diff --git a/docs/index.rst b/docs/index.rst index 153c9df49..50fe4ed29 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -28,6 +28,9 @@ Table of contents types coordinates constants + replays + idareplayobserver + replayuinit .. autosummary:: :toctree: _autosummary diff --git a/docs/replays.rst b/docs/replays.rst index cce599d01..e1fe76d8f 100644 --- a/docs/replays.rst +++ b/docs/replays.rst @@ -1,9 +1,11 @@ Replays ======= This page will describe two different techniques for handling replays. The -first technique parses the information saved in the replay file. The secund +first technique parses the information saved in the replay file. The second uses the information in the replay file to actually replay the game. The -different techniques have serten advetedeges and disadvantages. +different techniques have certain advantages and disadvantages. The main +one is that the reader is a lot faster while replaying the game provides +a lot more information. @@ -89,12 +91,14 @@ that no action can be preform just observations. No debug actions can be taken. IDAReplayObserver.on_game_end(self) def main(): - coordinator = Coordinator(r"D:\StarCraft II\Versions\Base69232\SC2_x64.exe") - print(coordinator.load_replay_list("D:\\Replays\\")) - my_observer = MyObserver() - coordinator.add_replay_observer(my_observer) + coordinator = Coordinator(r"D:/StarCraft II/Versions/Base69232/SC2_x64.exe") + if coordinator.load_replay_list("D:/Replays/"): + observer = MyObserver() + coordinator.add_replay_observer(observer) while coordinator.update(): pass + else: + print("No replays found") if __name__ == "__main__": main() diff --git a/docs/replayunit.rst b/docs/replayunit.rst index 472018a9a..c3c8214f8 100644 --- a/docs/replayunit.rst +++ b/docs/replayunit.rst @@ -1,5 +1,5 @@ -Unit -==== +ReplayUnit +========== .. class:: library.ReplayUnit diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index 1ec48212a..29d5c9653 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -99,6 +99,7 @@ PYBIND11_MODULE(library, m) .def("on_step", &IDAReplayObserver::OnStep) .def("on_game_end", &IDAReplayObserver::OnGameEnd) .def("get_all_units", &IDAReplayObserver::GetAllUnits, "Returns a list of all units") + .def("get_player_race", &IDAReplayObserver::GetPlayerRace,"player_id"_a) ; py::class_<sc2::PlayerSetup>(m, "PlayerSetup"); diff --git a/src/IDAReplayObserver.cpp b/src/IDAReplayObserver.cpp index 13728f586..491818b30 100644 --- a/src/IDAReplayObserver.cpp +++ b/src/IDAReplayObserver.cpp @@ -57,4 +57,19 @@ const std::vector<ReplayUnit>& IDAReplayObserver::GetAllUnits() const return m_allUnits; } +CCRace IDAReplayObserver::GetPlayerRace(int player) const +{ + auto playerID = Observation()->GetPlayerID(); + for (auto & playerInfo : Observation()->GetGameInfo().player_info) + { + if (playerInfo.player_id == playerID) + { + return playerInfo.race_actual; + } + } + + BOT_ASSERT(false, "Failed to find the player's race!"); + return sc2::Race::Random; +} + diff --git a/src/IDAReplayObserver.h b/src/IDAReplayObserver.h index b23393a2e..d340fb1af 100644 --- a/src/IDAReplayObserver.h +++ b/src/IDAReplayObserver.h @@ -25,6 +25,7 @@ public: ReplayUnit GetUnit(const CCUnitID tag) const; const std::vector<ReplayUnit> & GetAllUnits() const; + CCRace GetPlayerRace(int player) const; }; -- GitLab