diff --git a/CAPI/cpp/API/include/API.h b/CAPI/cpp/API/include/API.h index 5c6c463a..9b2a41e9 100755 --- a/CAPI/cpp/API/include/API.h +++ b/CAPI/cpp/API/include/API.h @@ -45,7 +45,7 @@ class ILogic [[nodiscard]] virtual std::shared_ptr GetGameInfo() const = 0; [[nodiscard]] virtual std::vector GetPlayerGUIDs() const = 0; [[nodiscard]] virtual THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const = 0; - [[nodiscard]] virtual std::pair GetConstructionState(int32_t cellX, int32_t cellY) const = 0; + [[nodiscard]] virtual std::optional GetConstructionState(int32_t cellX, int32_t cellY) const = 0; [[nodiscard]] virtual int32_t GetWormholeHp(int32_t cellX, int32_t cellY) const = 0; [[nodiscard]] virtual int32_t GetResourceState(int32_t cellX, int32_t cellY) const = 0; [[nodiscard]] virtual int32_t GetHomeHp() const = 0; @@ -64,6 +64,8 @@ class ILogic virtual bool Move(int64_t time, double angle) = 0; virtual bool Recover(int64_t recover) = 0; virtual bool Produce() = 0; + virtual bool RepairWormhole() = 0; + virtual bool RepairHome() = 0; virtual bool Rebuild(THUAI7::ConstructionType constructionType) = 0; virtual bool Construct(THUAI7::ConstructionType constructionType) = 0; virtual bool Attack(double angle) = 0; @@ -97,7 +99,7 @@ class IAPI [[nodiscard]] virtual std::vector> GetFullMap() const = 0; [[nodiscard]] virtual std::shared_ptr GetGameInfo() const = 0; [[nodiscard]] virtual THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const = 0; - [[nodiscard]] virtual std::pair GetConstructionState(int32_t cellX, int32_t cellY) const = 0; + [[nodiscard]] virtual std::optional GetConstructionState(int32_t cellX, int32_t cellY) const = 0; [[nodiscard]] virtual int32_t GetWormholeHp(int32_t cellX, int32_t cellY) const = 0; [[nodiscard]] virtual int32_t GetResourceState(int32_t cellX, int32_t cellY) const = 0; [[nodiscard]] virtual int32_t GetHomeHp() const = 0; @@ -139,6 +141,8 @@ class IShipAPI : public IAPI virtual std::future Attack(double angleInRadian) = 0; virtual std::future Recover(int64_t recover) = 0; virtual std::future Produce() = 0; + virtual std::future RepairWormhole() = 0; + virtual std::future RepairHome() = 0; virtual std::future Rebuild(THUAI7::ConstructionType constructionType) = 0; virtual std::future Construct(THUAI7::ConstructionType constructionType) = 0; virtual std::shared_ptr GetSelfInfo() const = 0; @@ -195,6 +199,8 @@ class ShipAPI : public IShipAPI, public IGameTimer std::future Attack(double angleInRadian) override; std::future Recover(int64_t recover) override; std::future Produce() override; + std::future RepairWormhole() override; + std::future RepairHome() override; std::future Rebuild(THUAI7::ConstructionType constructionType) override; std::future Construct(THUAI7::ConstructionType constructionType) override; @@ -203,7 +209,7 @@ class ShipAPI : public IShipAPI, public IGameTimer [[nodiscard]] std::vector> GetBullets() const override; [[nodiscard]] std::vector> GetFullMap() const override; [[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override; - [[nodiscard]] std::pair GetConstructionState(int32_t cellX, int32_t cellY) const override; + [[nodiscard]] std::optional GetConstructionState(int32_t cellX, int32_t cellY) const override; [[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override; [[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override; [[nodiscard]] std::shared_ptr GetGameInfo() const override; @@ -259,7 +265,7 @@ class TeamAPI : public ITeamAPI, public IGameTimer [[nodiscard]] std::vector> GetBullets() const override; [[nodiscard]] std::vector> GetFullMap() const override; [[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override; - [[nodiscard]] std::pair GetConstructionState(int32_t cellX, int32_t cellY) const override; + [[nodiscard]] std::optional GetConstructionState(int32_t cellX, int32_t cellY) const override; [[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override; [[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override; [[nodiscard]] int32_t GetHomeHp() const override; @@ -312,6 +318,8 @@ class ShipDebugAPI : public IShipAPI, public IGameTimer std::future Attack(double angleInRadian) override; std::future Recover(int64_t recover) override; std::future Produce() override; + std::future RepairWormhole() override; + std::future RepairHome() override; std::future Rebuild(THUAI7::ConstructionType constructionType) override; std::future Construct(THUAI7::ConstructionType constructionType) override; @@ -320,7 +328,7 @@ class ShipDebugAPI : public IShipAPI, public IGameTimer [[nodiscard]] std::vector> GetBullets() const override; [[nodiscard]] std::vector> GetFullMap() const override; [[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override; - [[nodiscard]] std::pair GetConstructionState(int32_t cellX, int32_t cellY) const override; + [[nodiscard]] std::optional GetConstructionState(int32_t cellX, int32_t cellY) const override; [[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override; [[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override; [[nodiscard]] int32_t GetHomeHp() const override; @@ -366,7 +374,7 @@ class TeamDebugAPI : public ITeamAPI, public IGameTimer [[nodiscard]] std::vector> GetBullets() const override; [[nodiscard]] std::vector> GetFullMap() const override; [[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override; - [[nodiscard]] std::pair GetConstructionState(int32_t cellX, int32_t cellY) const override; + [[nodiscard]] std::optional GetConstructionState(int32_t cellX, int32_t cellY) const override; [[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override; [[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override; [[nodiscard]] int32_t GetHomeHp() const override; diff --git a/CAPI/cpp/API/include/Communication.h b/CAPI/cpp/API/include/Communication.h index 96a846b7..8ab441f8 100755 --- a/CAPI/cpp/API/include/Communication.h +++ b/CAPI/cpp/API/include/Communication.h @@ -35,6 +35,8 @@ class Communication bool Move(int32_t playerID, int32_t teamID, int64_t time, double angle); bool Recover(int32_t playerID, int64_t recover, int32_t teamID); bool Produce(int32_t playerID, int32_t teamID); + bool RepairWormhole(int32_t playerID, int32_t teamID); + bool RepairHome(int32_t playerID, int32_t teamID); bool Rebuild(int32_t playerID, int32_t teamID, THUAI7::ConstructionType constructionType); bool Construct(int32_t playerID, int32_t teamID, THUAI7::ConstructionType constructionType); bool Attack(int32_t playerID, int32_t teamID, double angle); diff --git a/CAPI/cpp/API/include/logic.h b/CAPI/cpp/API/include/logic.h index cd1df973..e03bad4e 100755 --- a/CAPI/cpp/API/include/logic.h +++ b/CAPI/cpp/API/include/logic.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -98,7 +99,7 @@ class Logic : public ILogic [[nodiscard]] std::shared_ptr GetGameInfo() const; [[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const; [[nodiscard]] std::vector GetPlayerGUIDs() const; - [[nodiscard]] std::pair GetConstructionState(int32_t cellX, int32_t cellY) const; + [[nodiscard]] std::optional GetConstructionState(int32_t cellX, int32_t cellY) const; [[nodiscard]] int32_t GetWormholeHp(int32_t cellX, int32_t cellY) const; [[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const; [[nodiscard]] int32_t GetHomeHp() const; @@ -117,6 +118,8 @@ class Logic : public ILogic bool Move(int64_t time, double angle); bool Recover(int64_t recover); bool Produce(); + bool RepairWormhole(); + bool RepairHome(); bool Rebuild(THUAI7::ConstructionType constructionType); bool Construct(THUAI7::ConstructionType constructionType); bool Attack(double angle); diff --git a/CAPI/cpp/API/include/structures.h b/CAPI/cpp/API/include/structures.h index 35bd5b4f..375c57e1 100755 --- a/CAPI/cpp/API/include/structures.h +++ b/CAPI/cpp/API/include/structures.h @@ -243,6 +243,19 @@ namespace THUAI7 int32_t speed; // 子弹速度 }; + struct ConstructionState + { + int32_t teamID; + int32_t hp; + ConstructionType constructionType; + ConstructionState(std::pair teamHP, ConstructionType type) : + teamID(teamHP.first), + hp(teamHP.second), + constructionType(type) + { + } + }; + // struct BombedBullet // { // BulletType bulletType, diff --git a/CAPI/cpp/API/src/API.cpp b/CAPI/cpp/API/src/API.cpp index 0059658d..9656d2ec 100755 --- a/CAPI/cpp/API/src/API.cpp +++ b/CAPI/cpp/API/src/API.cpp @@ -1,4 +1,3 @@ -#include #include "AI.h" #include "API.h" @@ -140,12 +139,12 @@ THUAI7::PlaceType TeamAPI::GetPlaceType(int32_t cellX, int32_t cellY) const return logic.GetPlaceType(cellX, cellY); } -std::pair ShipAPI::GetConstructionState(int32_t cellX, int32_t cellY) const +std::optional ShipAPI::GetConstructionState(int32_t cellX, int32_t cellY) const { return logic.GetConstructionState(cellX, cellY); } -std::pair TeamAPI::GetConstructionState(int32_t cellX, int32_t cellY) const +std::optional TeamAPI::GetConstructionState(int32_t cellX, int32_t cellY) const { return logic.GetConstructionState(cellX, cellY); } @@ -275,6 +274,18 @@ std::future ShipAPI::Produce() { return logic.Produce(); }); } +std::future ShipAPI::RepairWormhole() +{ + return std::async(std::launch::async, [=]() + { return logic.RepairWormhole(); }); +} + +std::future ShipAPI::RepairHome() +{ + return std::async(std::launch::async, [=]() + { return logic.RepairHome(); }); +} + std::future ShipAPI::Rebuild(THUAI7::ConstructionType constructionType) { return std::async(std::launch::async, [=]() diff --git a/CAPI/cpp/API/src/Communication.cpp b/CAPI/cpp/API/src/Communication.cpp index 6c86b7eb..1c68e8da 100755 --- a/CAPI/cpp/API/src/Communication.cpp +++ b/CAPI/cpp/API/src/Communication.cpp @@ -114,6 +114,44 @@ bool Communication::Produce(int32_t playerID, int32_t teamID) return false; } +bool Communication::RepairWormhole(int32_t playerID, int32_t teamID) +{ + { + std::lock_guard lock(mtxLimit); + if (counter >= limit || counterMove >= moveLimit) + return false; + counter++; + counterMove++; + } + protobuf::BoolRes repairWormholeResult; + ClientContext context; + auto request = THUAI72Proto::THUAI72ProtobufIDMsg(playerID, teamID); + auto status = THUAI7Stub->RepairWormhole(&context, request, &repairWormholeResult); + if (status.ok()) + return repairWormholeResult.act_success(); + else + return false; +} + +bool Communication::RepairHome(int32_t playerID, int32_t teamID) +{ + { + std::lock_guard lock(mtxLimit); + if (counter >= limit || counterMove >= moveLimit) + return false; + counter++; + counterMove++; + } + protobuf::BoolRes repairHomeResult; + ClientContext context; + auto request = THUAI72Proto::THUAI72ProtobufIDMsg(playerID, teamID); + auto status = THUAI7Stub->RepairHome(&context, request, &repairHomeResult); + if (status.ok()) + return repairHomeResult.act_success(); + else + return false; +} + bool Communication::Rebuild(int32_t playerID, int32_t teamID, THUAI7::ConstructionType constructionType) { { diff --git a/CAPI/cpp/API/src/DebugAPI.cpp b/CAPI/cpp/API/src/DebugAPI.cpp index c2641e32..4e24fd50 100755 --- a/CAPI/cpp/API/src/DebugAPI.cpp +++ b/CAPI/cpp/API/src/DebugAPI.cpp @@ -156,6 +156,27 @@ std::future ShipDebugAPI::Produce() logger->warn("Produce: failed at {}ms",Time::TimeSinceStart(startPoint)); return result; }); } + +std::future ShipDebugAPI::RepairWormhole() +{ + logger->info("RepairWormhole: called at {}ms", Time::TimeSinceStart(startPoint)); + return std::async(std::launch::async, [=]() + { auto result= logic.RepairWormhole(); + if(!result) + logger->warn("RepairWormhole: failed at {}ms",Time::TimeSinceStart(startPoint)); + return result; }); +} + +std::future ShipDebugAPI::RepairHome() +{ + logger->info("RepairHome: called at {}ms", Time::TimeSinceStart(startPoint)); + return std::async(std::launch::async, [=]() + { auto result= logic.RepairHome(); + if(!result) + logger->warn("RepairHome: failed at {}ms",Time::TimeSinceStart(startPoint)); + return result; }); +} + std::future ShipDebugAPI::Rebuild(THUAI7::ConstructionType constructionType) { logger->info("Rebuild: rebuilding {}, called at {}ms", THUAI7::constructionDict[constructionType], Time::TimeSinceStart(startPoint)); @@ -201,7 +222,7 @@ THUAI7::PlaceType ShipDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const return logic.GetPlaceType(cellX, cellY); } -std::pair ShipDebugAPI::GetConstructionState(int32_t cellX, int32_t cellY) const +std::optional ShipDebugAPI::GetConstructionState(int32_t cellX, int32_t cellY) const { return logic.GetConstructionState(cellX, cellY); } @@ -395,7 +416,7 @@ THUAI7::PlaceType TeamDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const return logic.GetPlaceType(cellX, cellY); } -std::pair TeamDebugAPI::GetConstructionState(int32_t cellX, int32_t cellY) const +std::optional TeamDebugAPI::GetConstructionState(int32_t cellX, int32_t cellY) const { return logic.GetConstructionState(cellX, cellY); } @@ -446,7 +467,7 @@ std::future TeamDebugAPI::InstallModule(int32_t playerID, THUAI7::ModuleTy return std::async(std::launch::async, [=]() { auto result= logic.InstallModule(playerID, moduleType); if(!result) - logger->info("InstallModule: failed at {}ms",Time::TimeSinceStart(startPoint)); + logger->warn("InstallModule: failed at {}ms",Time::TimeSinceStart(startPoint)); return result; }); } @@ -474,7 +495,7 @@ void TeamDebugAPI::PrintSelfInfo() const { auto Team = logic.TeamGetSelfInfo(); logger->info("******Self Info******"); - logger->info("playerID={}, teamID={}, score={}, energy={}", Team->playerID, Team->teamID, Team->score, Team->energy); + logger->info("teamID={}, playerID={}, score={}, energy={}", Team->teamID, Team->playerID, Team->score, Team->energy); logger->info("*********************\n"); } diff --git a/CAPI/cpp/API/src/logic.cpp b/CAPI/cpp/API/src/logic.cpp index 050b0325..9710b355 100755 --- a/CAPI/cpp/API/src/logic.cpp +++ b/CAPI/cpp/API/src/logic.cpp @@ -91,7 +91,7 @@ THUAI7::PlaceType Logic::GetPlaceType(int32_t cellX, int32_t cellY) const return currentState->gameMap[cellX][cellY]; } -std::pair Logic::GetConstructionState(int32_t cellX, int32_t cellY) const +std::optional Logic::GetConstructionState(int32_t cellX, int32_t cellY) const { std::unique_lock lock(mtxState); logger->debug("Called GetConstructionState"); @@ -101,16 +101,16 @@ std::pair Logic::GetConstructionState(int32_t cellX, int32_t c auto it3 = currentState->mapInfo->fortState.find(pos); if (it != currentState->mapInfo->factoryState.end()) { - return currentState->mapInfo->factoryState[pos]; + return std::make_optional(currentState->mapInfo->factoryState[pos], THUAI7::ConstructionType::Factory); } else if (it2 != currentState->mapInfo->communityState.end()) - return currentState->mapInfo->communityState[pos]; + return std::make_optional(currentState->mapInfo->communityState[pos], THUAI7::ConstructionType::Community); else if (it3 != currentState->mapInfo->fortState.end()) - return currentState->mapInfo->fortState[pos]; + return std::make_optional(currentState->mapInfo->fortState[pos], THUAI7::ConstructionType::Fort); else { logger->warn("Construction not found"); - return std::make_pair(-1, -1); + return std::nullopt; } } @@ -261,6 +261,18 @@ bool Logic::Produce() return pComm->Produce(playerID, teamID); } +bool Logic::RepairWormhole() +{ + logger->debug("Called RepairWormhole"); + return pComm->RepairWormhole(playerID, teamID); +} + +bool Logic::RepairHome() +{ + logger->debug("Called RepairHome"); + return pComm->RepairHome(playerID, teamID); +} + bool Logic::Rebuild(THUAI7::ConstructionType constructionType) { logger->debug("Called Rebuild"); diff --git a/CAPI/python/PyAPI/API.py b/CAPI/python/PyAPI/API.py index 2a2a2375..70eb0950 100644 --- a/CAPI/python/PyAPI/API.py +++ b/CAPI/python/PyAPI/API.py @@ -34,6 +34,12 @@ def Recover(self, recover: int) -> Future[bool]: def Produce(self) -> Future[bool]: return self.__pool.submit(self.__logic.Produce) + def RepairWormhole(self) -> Future[bool]: + return self.__pool.submit(self.__logic.RepairWormhole) + + def RepairHome(self) -> Future[bool]: + return self.__pool.submit(self.__logic.RepairHome) + def Rebuild(self, constructionType: THUAI7.ConstructionType) -> Future[bool]: return self.__pool.submit(self.__logic.Rebuild, constructionType) @@ -76,7 +82,7 @@ def GetFullMap(self) -> List[List[THUAI7.PlaceType]]: def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType: return self.__logic.GetPlaceType(cellX, cellY) - def GetConstructionState(self, cellX: int, cellY: int) -> Tuple[int, int]: + def GetConstructionState(self, cellX: int, cellY: int) -> THUAI7.ConstructionState | None: return self.__logic.GetConstructionState(cellX, cellY) def GetWormholeHp(self, cellX: int, cellY: int) -> int: @@ -184,7 +190,7 @@ def GetFullMap(self) -> List[List[THUAI7.PlaceType]]: def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType: return self.__logic.GetPlaceType(cellX, cellY) - def GetConstructionState(self, cellX: int, cellY: int) -> Tuple[int, int]: + def GetConstructionState(self, cellX: int, cellY: int) -> THUAI7.ConstructionState | None: return self.__logic.GetConstructionState(cellX, cellY) def GetWormholeHp(self, cellX: int, cellY: int) -> int: diff --git a/CAPI/python/PyAPI/Communication.py b/CAPI/python/PyAPI/Communication.py index 8f49aa39..13311490 100644 --- a/CAPI/python/PyAPI/Communication.py +++ b/CAPI/python/PyAPI/Communication.py @@ -112,6 +112,34 @@ def Produce(self, playerID: int, teamID: int) -> bool: else: return produceResult.act_success + def RepairWormhole(self, playerID: int, teamID: int) -> bool: + try: + with self.__mtxLimit: + if self.__counter >= self.__limit: + return False + self.__counter += 1 + produceResult: Message2Clients.BoolRes = self.__THUAI7Stub.RepairWormhole( + THUAI72Proto.THUAI72ProtobufIDMsg(playerID, teamID) + ) + except grpc.RpcError: + return False + else: + return produceResult.act_success + + def RepairHome(self, playerID: int, teamID: int) -> bool: + try: + with self.__mtxLimit: + if self.__counter >= self.__limit: + return False + self.__counter += 1 + produceResult: Message2Clients.BoolRes = self.__THUAI7Stub.RepairHome( + THUAI72Proto.THUAI72ProtobufIDMsg(playerID, teamID) + ) + except grpc.RpcError: + return False + else: + return produceResult.act_success + def Rebuild( self, constructionType: THUAI7.ConstructionType, playerID: int, teamID: int ) -> bool: diff --git a/CAPI/python/PyAPI/DebugAPI.py b/CAPI/python/PyAPI/DebugAPI.py index 820f0daf..25f6f66c 100644 --- a/CAPI/python/PyAPI/DebugAPI.py +++ b/CAPI/python/PyAPI/DebugAPI.py @@ -10,7 +10,13 @@ class ShipDebugAPI(IShipAPI, IGameTimer): def __init__( - self, logic: ILogic, file: bool, screen: bool, warnOnly: bool, playerID: int, teamID: int + self, + logic: ILogic, + file: bool, + screen: bool, + warnOnly: bool, + playerID: int, + teamID: int, ) -> None: self.__logic = logic self.__pool = ThreadPoolExecutor(20) @@ -106,6 +112,28 @@ def logProduce() -> bool: return self.__pool.submit(logProduce) + def RepairWormhole(self) -> Future[bool]: + self.__logger.info(f"RepairWormhole: called at {self.__GetTime()}ms") + + def logRepairWormhole() -> bool: + result = self.__logic.RepairWormhole() + if not result: + self.__logger.warning(f"RepairWormhole failed at {self.__GetTime()}ms") + return result + + return self.__pool.submit(logRepairWormhole) + + def RepairHome(self) -> Future[bool]: + self.__logger.info(f"RepairHome: called at {self.__GetTime()}ms") + + def logRepairHome() -> bool: + result = self.__logic.RepairHome() + if not result: + self.__logger.warning(f"RepairHome failed at {self.__GetTime()}ms") + return result + + return self.__pool.submit(logRepairHome) + def Rebuild(self, constructionType: THUAI7.ConstructionType) -> Future[bool]: self.__logger.info( f"Rebuild: called at {self.__GetTime()}ms construction type {constructionType}" @@ -199,7 +227,7 @@ def GetFullMap(self) -> List[List[THUAI7.PlaceType]]: def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType: return self.__logic.GetPlaceType(cellX, cellY) - def GetConstructionState(self, cellX: int, cellY: int) -> Tuple[int, int]: + def GetConstructionState(self, cellX: int, cellY: int) -> THUAI7.ConstructionState | None: return self.__logic.GetConstructionState(cellX, cellY) def GetWormholeHp(self, cellX: int, cellY: int) -> int: @@ -263,23 +291,14 @@ def PrintTeam(self) -> None: def PrintSelfInfo(self) -> None: ship = self.__logic.GetSelfInfo() - self.__logger.info("******ship Info******") + self.__logger.info("******Self Info******") self.__logger.info( - f"teamID={ship.teamID} playerID={ship.playerID}, GUID={ship.guid} shipType:{ship.shipType}" + f"type={THUAI7.shipTypeDict[ship.shipType]}, playerID={ship.playerID}, GUID={ship.guid}, x={ship.x}, y={ship.y}" ) self.__logger.info( - f"x={ship.x}, y={ship.y} hp={ship.hp} armor={ship.armor} shield={ship.shield} state:{ship.shipState}" + f"state={THUAI7.shipStateDict[ship.shipState]}, speed={ship.speed}, view range={ship.viewRange}, facing direction={ship.facingDirection}" ) - self.__logger.info( - f"speed={ship.speed}, view range={ship.viewRange}, facingDirection={ship.facingDirection}" - ) - self.__logger.info( - f"producerType:{ship.producerType} constructorType:{ship.constructorType}" - ) - self.__logger.info( - f"armorType:{ship.armorType} shieldType:{ship.shieldType} weaponType:{ship.weaponType}" - ) - self.__logger.info("************************\n") + self.__logger.info("*********************\n") def __GetTime(self) -> float: return (datetime.datetime.now() - self.__startPoint) / datetime.timedelta( @@ -300,7 +319,13 @@ def Play(self, ai: IAI) -> None: class TeamDebugAPI(ITeamAPI, IGameTimer): def __init__( - self, logic: ILogic, file: bool, screen: bool, warnOnly: bool, playerID: int, teamID: int + self, + logic: ILogic, + file: bool, + screen: bool, + warnOnly: bool, + playerID: int, + teamID: int, ) -> None: self.__logic = logic self.__pool = ThreadPoolExecutor(20) @@ -440,7 +465,7 @@ def GetFullMap(self) -> List[List[THUAI7.PlaceType]]: def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType: return self.__logic.GetPlaceType(cellX, cellY) - def GetConstructionState(self, cellX: int, cellY: int) -> Tuple[int, int]: + def GetConstructionState(self, cellX: int, cellY: int) -> THUAI7.ConstructionState | None: return self.__logic.GetConstructionState(cellX, cellY) def GetWormholeHp(self, cellX: int, cellY: int) -> int: @@ -496,8 +521,9 @@ def PrintTeam(self) -> None: def PrintSelfInfo(self) -> None: selfInfo = self.__logic.GetSelfInfo() self.__logger.info("******self team info******") - self.__logger.info(f"teamID:{selfInfo.teamID} playerID:{selfInfo.playerID}") - self.__logger.info(f"score:{selfInfo.score} energy:{selfInfo.energy}") + self.__logger.info( + f"teamID:{selfInfo.teamID} playerID:{selfInfo.playerID} score:{selfInfo.score} energy:{selfInfo.energy}" + ) self.__logger.info("************************\n") def __GetTime(self) -> float: diff --git a/CAPI/python/PyAPI/Interface.py b/CAPI/python/PyAPI/Interface.py index ca381a70..6e374797 100644 --- a/CAPI/python/PyAPI/Interface.py +++ b/CAPI/python/PyAPI/Interface.py @@ -43,7 +43,7 @@ def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType: pass @abstractmethod - def GetConstructionState(self, cellX: int, cellY: int) -> tuple: + def GetConstructionState(self, cellX: int, cellY: int) -> THUAI7.ConstructionState | None: pass @abstractmethod @@ -110,6 +110,14 @@ def Rebuild(self, constructionType: THUAI7.ConstructionType) -> bool: def Construct(self, constructionType: THUAI7.ConstructionType) -> bool: pass + @abstractmethod + def RepairHome(self) -> bool: + pass + + @abstractmethod + def RepairWormhole(self) -> bool: + pass + @abstractmethod def Attack(self, angle: float) -> bool: pass @@ -239,12 +247,12 @@ def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType: pass @abstractmethod - def GetConstructionState(self, cellX: int, cellY: int) -> Tuple[int, int]: + def GetConstructionState(self, cellX: int, cellY: int) -> THUAI7.ConstructionState | None: """获取当前建筑状态 :param cellX: X坐标, 单位Cell :param cellY: Y坐标, 单位Cell - :return: 该建筑当前的所属队伍编号与血量 + :return: 该建筑信息 """ pass @@ -407,7 +415,7 @@ def Produce(self) -> Future[bool]: pass @abstractmethod - def Rebuild(self, constructionType: THUAI7.ConstructionType) -> Future[bool]: + def Rebuild(self, constructionType: THUAI7.ConstructionStateType) -> Future[bool]: """发出重建指令 - 需要接近待重建 `Construction` @@ -416,6 +424,24 @@ def Rebuild(self, constructionType: THUAI7.ConstructionType) -> Future[bool]: """ pass + @abstractmethod + def RepairWormhole(self) -> Future[bool]: + """发出修复虫洞指令 + - 需要接近待建造的 `Wormhole` + + :return: 是否成功进入修复虫洞状态,通过`.result()`方法等待获取`bool` + """ + pass + + @abstractmethod + def RepairHome(self) -> Future[bool]: + """发出修复大本营指令 + - 需要接近待建造的 `Home` + + :return: 是否成功进入修复大本营状态,通过`.result()`方法等待获取`bool` + """ + pass + @abstractmethod def Construct(self, constructionType: THUAI7.ConstructionType) -> Future[bool]: """发出建造指令 @@ -455,7 +481,9 @@ def GetSelfInfo(self) -> THUAI7.Team: pass @abstractmethod - def InstallModule(self, playerID: int, moduleType: THUAI7.ModuleType) -> Future[bool]: + def InstallModule( + self, playerID: int, moduleType: THUAI7.ModuleType + ) -> Future[bool]: """安装模块 :param playerID: 待安装模块的舰船编号 diff --git a/CAPI/python/PyAPI/logic.py b/CAPI/python/PyAPI/logic.py index 4fbb56ad..bb4e1dae 100644 --- a/CAPI/python/PyAPI/logic.py +++ b/CAPI/python/PyAPI/logic.py @@ -138,24 +138,27 @@ def GetPlayerGUIDs(self) -> List[int]: with self.__mtxState: return copy.deepcopy(self.__currentState.guids) - def GetConstructionState(self, cellX: int, cellY: int) -> tuple: + def GetConstructionState(self, cellX: int, cellY: int) -> THUAI7.ConstructionState | None: with self.__mtxState: self.__logger.debug("Called GetConstructionState") if (cellX, cellY) in self.__currentState.mapInfo.factoryState: - return copy.deepcopy( - self.__currentState.mapInfo.factoryState[(cellX, cellY)] + return THUAI7.ConstructionState( + self.__currentState.mapInfo.factoryState[(cellX, cellY)], + THUAI7.ConstructionType.Factory, ) elif (cellX, cellY) in self.__currentState.mapInfo.communityState: - return copy.deepcopy( - self.__currentState.mapInfo.communityState[(cellX, cellY)] + return THUAI7.ConstructionState( + self.__currentState.mapInfo.communityState[(cellX, cellY)], + THUAI7.ConstructionType.Community, ) elif (cellX, cellY) in self.__currentState.mapInfo.fortState: - return copy.deepcopy( - self.__currentState.mapInfo.fortState[(cellX, cellY)] + return THUAI7.ConstructionState( + self.__currentState.mapInfo.fortState[(cellX, cellY)], + THUAI7.ConstructionType.Fort, ) else: self.__logger.warning("GetConstructionState: Out of range") - return (-1, -1) + return None def GetWormholeHp(self, cellX: int, cellY: int) -> int: with self.__mtxState: @@ -235,6 +238,14 @@ def Produce(self) -> bool: self.__logger.debug("Called Produce") return self.__comm.Produce(self.__playerID, self.__teamID) + def RepairWormhole(self) -> bool: + self.__logger.debug("Called RepairWormhole") + return self.__comm.RepairWormhole(self.__playerID, self.__teamID) + + def RepairHome(self) -> bool: + self.__logger.debug("Called RepairHome") + return self.__comm.RepairHome(self.__playerID, self.__teamID) + def Rebuild(self, constructionType: THUAI7.ConstructionType) -> bool: self.__logger.debug("Called Rebuild") return self.__comm.Rebuild(constructionType, self.__playerID, self.__teamID) diff --git a/CAPI/python/PyAPI/structures.py b/CAPI/python/PyAPI/structures.py index 7e261c05..59b02fd8 100644 --- a/CAPI/python/PyAPI/structures.py +++ b/CAPI/python/PyAPI/structures.py @@ -227,6 +227,11 @@ def __init__(self): self.teamID: int = 0 self.guid: int = 0 +class ConstructionState: + def __init__(self,teamID,HP,type:ConstructionType): + self.teamID=teamID + self.hp=HP + self.constructionType=type class Bullet: """ diff --git a/dependency/proto/Services.proto b/dependency/proto/Services.proto index 21c2becb..794af9f4 100755 --- a/dependency/proto/Services.proto +++ b/dependency/proto/Services.proto @@ -21,6 +21,7 @@ service AvailableService rpc RepairWormhole(IDMsg) returns (BoolRes); // 修理虫洞 rpc Attack(AttackMsg) returns (BoolRes); // 攻击 rpc Send(SendMsg) returns (BoolRes); // 传递信息 + // 大本营 rpc InstallModule(InstallMsg) returns (BoolRes); rpc Recycle(IDMsg) returns (BoolRes);