From d0e4864373fe31400c5d1754690a97ccd321cca3 Mon Sep 17 00:00:00 2001 From: sigureling <1678348940@qq.com> Date: Sat, 11 May 2024 23:15:57 +0800 Subject: [PATCH 1/8] fix: :sparkles: Add RepairHome and RepairWormhole --- CAPI/cpp/API/include/API.h | 8 ++++++ CAPI/cpp/API/include/Communication.h | 2 ++ CAPI/cpp/API/include/logic.h | 2 ++ CAPI/cpp/API/src/API.cpp | 12 +++++++++ CAPI/cpp/API/src/Communication.cpp | 38 ++++++++++++++++++++++++++++ CAPI/cpp/API/src/DebugAPI.cpp | 21 +++++++++++++++ CAPI/cpp/API/src/logic.cpp | 12 +++++++++ CAPI/python/PyAPI/API.py | 6 +++++ CAPI/python/PyAPI/Communication.py | 28 ++++++++++++++++++++ CAPI/python/PyAPI/DebugAPI.py | 38 ++++++++++++++++++++++++++-- CAPI/python/PyAPI/Interface.py | 30 +++++++++++++++++++++- CAPI/python/PyAPI/logic.py | 8 ++++++ dependency/proto/Services.proto | 3 +++ logic/Server/RpcServices.cs | 32 +++++++++++++++++++++++ 14 files changed, 237 insertions(+), 3 deletions(-) diff --git a/CAPI/cpp/API/include/API.h b/CAPI/cpp/API/include/API.h index 5c6c463a..10cc295d 100755 --- a/CAPI/cpp/API/include/API.h +++ b/CAPI/cpp/API/include/API.h @@ -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; @@ -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; @@ -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; 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..a64c8446 100755 --- a/CAPI/cpp/API/include/logic.h +++ b/CAPI/cpp/API/include/logic.h @@ -117,6 +117,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/src/API.cpp b/CAPI/cpp/API/src/API.cpp index 0059658d..8ede7fd6 100755 --- a/CAPI/cpp/API/src/API.cpp +++ b/CAPI/cpp/API/src/API.cpp @@ -275,6 +275,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..bb9eccf1 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)); diff --git a/CAPI/cpp/API/src/logic.cpp b/CAPI/cpp/API/src/logic.cpp index 050b0325..1c73ca58 100755 --- a/CAPI/cpp/API/src/logic.cpp +++ b/CAPI/cpp/API/src/logic.cpp @@ -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..176954e9 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) 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..536714c9 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}" @@ -300,7 +328,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) diff --git a/CAPI/python/PyAPI/Interface.py b/CAPI/python/PyAPI/Interface.py index ca381a70..3cac021a 100644 --- a/CAPI/python/PyAPI/Interface.py +++ b/CAPI/python/PyAPI/Interface.py @@ -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 @@ -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..d0260440 100644 --- a/CAPI/python/PyAPI/logic.py +++ b/CAPI/python/PyAPI/logic.py @@ -235,6 +235,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/dependency/proto/Services.proto b/dependency/proto/Services.proto index dbc18505..544fecf2 100755 --- a/dependency/proto/Services.proto +++ b/dependency/proto/Services.proto @@ -19,6 +19,9 @@ service AvailableService rpc Construct(ConstructMsg) returns (BoolRes); // 修建建筑 rpc Attack(AttackMsg) returns (BoolRes); // 攻击 rpc Send(SendMsg) returns (BoolRes); // 传递信息 + rpc RepairHome(IDMsg) returns (BoolRes); // 修理大本营 + rpc RepairWormhole(IDMsg) returns (BoolRes); // 修理虫洞 + // 大本营 rpc InstallModule(InstallMsg) returns (BoolRes); rpc Recycle(IDMsg) returns (BoolRes); diff --git a/logic/Server/RpcServices.cs b/logic/Server/RpcServices.cs index 2b8d21d8..fcc01047 100755 --- a/logic/Server/RpcServices.cs +++ b/logic/Server/RpcServices.cs @@ -298,6 +298,38 @@ public override Task Produce(IDMsg request, ServerCallContext context) return Task.FromResult(boolRes); } + public override Task RepairHome(IDMsg request, ServerCallContext context) + { + GameServerLogging.logger.ConsoleLogDebug( + $"TRY RepairHome: Player {request.PlayerId} from Team {request.TeamId}"); + BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } + // var gameID = communicationToGameID[request.TeamId][request.PlayerId]; + boolRes.ActSuccess = game.RepairHome(request.TeamId, request.PlayerId); + GameServerLogging.logger.ConsoleLogDebug("END RepairHome"); + return Task.FromResult(boolRes); + } + + public override Task RepairWormhole(IDMsg request, ServerCallContext context) + { + GameServerLogging.logger.ConsoleLogDebug( + $"TRY RepairWormhole: Player {request.PlayerId} from Team {request.TeamId}"); + BoolRes boolRes = new(); + if (request.PlayerId >= spectatorMinPlayerID) + { + boolRes.ActSuccess = false; + return Task.FromResult(boolRes); + } + // var gameID = communicationToGameID[request.TeamId][request.PlayerId]; + boolRes.ActSuccess = game.RepairWormhole(request.TeamId, request.PlayerId); + GameServerLogging.logger.ConsoleLogDebug("END RepairWormhole"); + return Task.FromResult(boolRes); + } + public override Task Rebuild(ConstructMsg request, ServerCallContext context) { GameServerLogging.logger.ConsoleLogDebug( From 994522a65673f7c40320c62ac7cf818d79e368c5 Mon Sep 17 00:00:00 2001 From: sigureling <1678348940@qq.com> Date: Thu, 16 May 2024 00:43:01 +0800 Subject: [PATCH 2/8] feat: :zap: Wrap GetConstructionState --- CAPI/cpp/API/include/API.h | 12 ++++++------ CAPI/cpp/API/include/logic.h | 3 ++- CAPI/cpp/API/include/structures.h | 11 +++++++++++ CAPI/cpp/API/src/API.cpp | 9 ++++----- CAPI/cpp/API/src/DebugAPI.cpp | 12 ++++++------ CAPI/cpp/API/src/logic.cpp | 10 +++++----- CAPI/python/PyAPI/API.py | 4 ++-- CAPI/python/PyAPI/DebugAPI.py | 26 +++++++++----------------- CAPI/python/PyAPI/Interface.py | 6 +++--- CAPI/python/PyAPI/logic.py | 19 +++++++++++-------- CAPI/python/PyAPI/structures.py | 5 +++++ 11 files changed, 64 insertions(+), 53 deletions(-) diff --git a/CAPI/cpp/API/include/API.h b/CAPI/cpp/API/include/API.h index 10cc295d..0a82f1ff 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; @@ -99,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; @@ -209,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; @@ -265,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; @@ -328,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; @@ -374,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/logic.h b/CAPI/cpp/API/include/logic.h index a64c8446..93c36f99 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; diff --git a/CAPI/cpp/API/include/structures.h b/CAPI/cpp/API/include/structures.h index 35bd5b4f..780fb99f 100755 --- a/CAPI/cpp/API/include/structures.h +++ b/CAPI/cpp/API/include/structures.h @@ -243,6 +243,17 @@ namespace THUAI7 int32_t speed; // 子弹速度 }; + struct Construction + { + int32_t teamID; + int32_t hp; + ConstructionType constructionType; + static Construction newConstruction(std::pair teamHP, ConstructionType type) + { + return Construction{teamHP.first, teamHP.second, type}; + } + }; + // struct BombedBullet // { // BulletType bulletType, diff --git a/CAPI/cpp/API/src/API.cpp b/CAPI/cpp/API/src/API.cpp index 8ede7fd6..41196e57 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,14 +139,14 @@ 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); + return std::move(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); + return std::move(logic.GetConstructionState(cellX, cellY)); } int32_t ShipAPI::GetWormholeHp(int32_t cellX, int32_t cellY) const diff --git a/CAPI/cpp/API/src/DebugAPI.cpp b/CAPI/cpp/API/src/DebugAPI.cpp index bb9eccf1..4295cf26 100755 --- a/CAPI/cpp/API/src/DebugAPI.cpp +++ b/CAPI/cpp/API/src/DebugAPI.cpp @@ -222,9 +222,9 @@ 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); + return std::move(logic.GetConstructionState(cellX, cellY)); } int32_t ShipDebugAPI::GetWormholeHp(int32_t cellX, int32_t cellY) const @@ -416,9 +416,9 @@ 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); + return std::move(logic.GetConstructionState(cellX, cellY)); } int32_t TeamDebugAPI::GetWormholeHp(int32_t cellX, int32_t cellY) const @@ -467,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; }); } @@ -495,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 1c73ca58..bc2a522d 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(THUAI7::Construction::newConstruction(currentState->mapInfo->factoryState[pos], THUAI7::ConstructionType::Factory)); } else if (it2 != currentState->mapInfo->communityState.end()) - return currentState->mapInfo->communityState[pos]; + return std::make_optional(THUAI7::Construction::newConstruction(currentState->mapInfo->communityState[pos], THUAI7::ConstructionType::Community)); else if (it3 != currentState->mapInfo->fortState.end()) - return currentState->mapInfo->fortState[pos]; + return std::make_optional(THUAI7::Construction::newConstruction(currentState->mapInfo->fortState[pos], THUAI7::ConstructionType::Fort)); else { logger->warn("Construction not found"); - return std::make_pair(-1, -1); + return std::nullopt; } } diff --git a/CAPI/python/PyAPI/API.py b/CAPI/python/PyAPI/API.py index 176954e9..5b950c5d 100644 --- a/CAPI/python/PyAPI/API.py +++ b/CAPI/python/PyAPI/API.py @@ -82,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.Construction: return self.__logic.GetConstructionState(cellX, cellY) def GetWormholeHp(self, cellX: int, cellY: int) -> int: @@ -190,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.Construction: return self.__logic.GetConstructionState(cellX, cellY) def GetWormholeHp(self, cellX: int, cellY: int) -> int: diff --git a/CAPI/python/PyAPI/DebugAPI.py b/CAPI/python/PyAPI/DebugAPI.py index 536714c9..8a02d3df 100644 --- a/CAPI/python/PyAPI/DebugAPI.py +++ b/CAPI/python/PyAPI/DebugAPI.py @@ -227,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.Construction: return self.__logic.GetConstructionState(cellX, cellY) def GetWormholeHp(self, cellX: int, cellY: int) -> int: @@ -291,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( @@ -474,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.Construction: return self.__logic.GetConstructionState(cellX, cellY) def GetWormholeHp(self, cellX: int, cellY: int) -> int: @@ -530,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 3cac021a..b41c2dbd 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.Construction: pass @abstractmethod @@ -247,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.Construction: """获取当前建筑状态 :param cellX: X坐标, 单位Cell :param cellY: Y坐标, 单位Cell - :return: 该建筑当前的所属队伍编号与血量 + :return: 该建筑信息 """ pass diff --git a/CAPI/python/PyAPI/logic.py b/CAPI/python/PyAPI/logic.py index d0260440..36934ae7 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.Construction: 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.Construction( + 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.Construction( + 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.Construction( + 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: diff --git a/CAPI/python/PyAPI/structures.py b/CAPI/python/PyAPI/structures.py index 7e261c05..54612465 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 Construction: + def __init__(self,teamID,HP,type:ConstructionType): + self.teamID=teamID + self.hp=HP + self.constructionType=type class Bullet: """ From 112d3b5d4e03f73b3b8307622ca8becd422c8b11 Mon Sep 17 00:00:00 2001 From: sigureling <1678348940@qq.com> Date: Thu, 16 May 2024 00:48:42 +0800 Subject: [PATCH 3/8] fix: :fire: remove useless code --- dependency/proto/Services.proto | 2 -- 1 file changed, 2 deletions(-) diff --git a/dependency/proto/Services.proto b/dependency/proto/Services.proto index 66a1ee26..794af9f4 100755 --- a/dependency/proto/Services.proto +++ b/dependency/proto/Services.proto @@ -21,8 +21,6 @@ service AvailableService rpc RepairWormhole(IDMsg) returns (BoolRes); // 修理虫洞 rpc Attack(AttackMsg) returns (BoolRes); // 攻击 rpc Send(SendMsg) returns (BoolRes); // 传递信息 - rpc RepairHome(IDMsg) returns (BoolRes); // 修理大本营 - rpc RepairWormhole(IDMsg) returns (BoolRes); // 修理虫洞 // 大本营 rpc InstallModule(InstallMsg) returns (BoolRes); From 2381af5e14bf8763d036eadfb5de284c24e03380 Mon Sep 17 00:00:00 2001 From: sigureling <1678348940@qq.com> Date: Thu, 16 May 2024 00:59:10 +0800 Subject: [PATCH 4/8] style: :art: Rename ConstructionState --- CAPI/cpp/API/include/API.h | 12 ++++++------ CAPI/cpp/API/include/logic.h | 2 +- CAPI/cpp/API/include/structures.h | 8 +++++--- CAPI/cpp/API/src/API.cpp | 4 ++-- CAPI/cpp/API/src/DebugAPI.cpp | 4 ++-- CAPI/cpp/API/src/logic.cpp | 8 ++++---- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/CAPI/cpp/API/include/API.h b/CAPI/cpp/API/include/API.h index 0a82f1ff..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::optional 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; @@ -99,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::optional 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; @@ -209,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::optional 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; @@ -265,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::optional 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; @@ -328,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::optional 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; @@ -374,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::optional 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/logic.h b/CAPI/cpp/API/include/logic.h index 93c36f99..e03bad4e 100755 --- a/CAPI/cpp/API/include/logic.h +++ b/CAPI/cpp/API/include/logic.h @@ -99,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::optional 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; diff --git a/CAPI/cpp/API/include/structures.h b/CAPI/cpp/API/include/structures.h index 780fb99f..375c57e1 100755 --- a/CAPI/cpp/API/include/structures.h +++ b/CAPI/cpp/API/include/structures.h @@ -243,14 +243,16 @@ namespace THUAI7 int32_t speed; // 子弹速度 }; - struct Construction + struct ConstructionState { int32_t teamID; int32_t hp; ConstructionType constructionType; - static Construction newConstruction(std::pair teamHP, ConstructionType type) + ConstructionState(std::pair teamHP, ConstructionType type) : + teamID(teamHP.first), + hp(teamHP.second), + constructionType(type) { - return Construction{teamHP.first, teamHP.second, type}; } }; diff --git a/CAPI/cpp/API/src/API.cpp b/CAPI/cpp/API/src/API.cpp index 41196e57..6b9fbc2a 100755 --- a/CAPI/cpp/API/src/API.cpp +++ b/CAPI/cpp/API/src/API.cpp @@ -139,12 +139,12 @@ THUAI7::PlaceType TeamAPI::GetPlaceType(int32_t cellX, int32_t cellY) const return logic.GetPlaceType(cellX, cellY); } -std::optional ShipAPI::GetConstructionState(int32_t cellX, int32_t cellY) const +std::optional ShipAPI::GetConstructionState(int32_t cellX, int32_t cellY) const { return std::move(logic.GetConstructionState(cellX, cellY)); } -std::optional TeamAPI::GetConstructionState(int32_t cellX, int32_t cellY) const +std::optional TeamAPI::GetConstructionState(int32_t cellX, int32_t cellY) const { return std::move(logic.GetConstructionState(cellX, cellY)); } diff --git a/CAPI/cpp/API/src/DebugAPI.cpp b/CAPI/cpp/API/src/DebugAPI.cpp index 4295cf26..6b308761 100755 --- a/CAPI/cpp/API/src/DebugAPI.cpp +++ b/CAPI/cpp/API/src/DebugAPI.cpp @@ -222,7 +222,7 @@ THUAI7::PlaceType ShipDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const return logic.GetPlaceType(cellX, cellY); } -std::optional ShipDebugAPI::GetConstructionState(int32_t cellX, int32_t cellY) const +std::optional ShipDebugAPI::GetConstructionState(int32_t cellX, int32_t cellY) const { return std::move(logic.GetConstructionState(cellX, cellY)); } @@ -416,7 +416,7 @@ THUAI7::PlaceType TeamDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const return logic.GetPlaceType(cellX, cellY); } -std::optional TeamDebugAPI::GetConstructionState(int32_t cellX, int32_t cellY) const +std::optional TeamDebugAPI::GetConstructionState(int32_t cellX, int32_t cellY) const { return std::move(logic.GetConstructionState(cellX, cellY)); } diff --git a/CAPI/cpp/API/src/logic.cpp b/CAPI/cpp/API/src/logic.cpp index bc2a522d..f7f0faeb 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::optional 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,12 +101,12 @@ std::optional Logic::GetConstructionState(int32_t cellX, i auto it3 = currentState->mapInfo->fortState.find(pos); if (it != currentState->mapInfo->factoryState.end()) { - return std::make_optional(THUAI7::Construction::newConstruction(currentState->mapInfo->factoryState[pos], THUAI7::ConstructionType::Factory)); + return std::make_optional(THUAI7::ConstructionState(currentState->mapInfo->factoryState[pos], THUAI7::ConstructionType::Factory)); } else if (it2 != currentState->mapInfo->communityState.end()) - return std::make_optional(THUAI7::Construction::newConstruction(currentState->mapInfo->communityState[pos], THUAI7::ConstructionType::Community)); + return std::make_optional(THUAI7::ConstructionState(currentState->mapInfo->communityState[pos], THUAI7::ConstructionType::Community)); else if (it3 != currentState->mapInfo->fortState.end()) - return std::make_optional(THUAI7::Construction::newConstruction(currentState->mapInfo->fortState[pos], THUAI7::ConstructionType::Fort)); + return std::make_optional(THUAI7::ConstructionState(currentState->mapInfo->fortState[pos], THUAI7::ConstructionType::Fort)); else { logger->warn("Construction not found"); From 281a465ba7bac6f3897bc62d311fcb774ae5eafc Mon Sep 17 00:00:00 2001 From: sigureling <1678348940@qq.com> Date: Thu, 16 May 2024 01:05:18 +0800 Subject: [PATCH 5/8] fix: :fire: remove useless code --- logic/Server/RpcServices.cs | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/logic/Server/RpcServices.cs b/logic/Server/RpcServices.cs index d9892c7a..7a7c0863 100755 --- a/logic/Server/RpcServices.cs +++ b/logic/Server/RpcServices.cs @@ -306,38 +306,6 @@ public override Task Produce(IDMsg request, ServerCallContext context) return Task.FromResult(boolRes); } - public override Task RepairHome(IDMsg request, ServerCallContext context) - { - GameServerLogging.logger.ConsoleLogDebug( - $"TRY RepairHome: Player {request.PlayerId} from Team {request.TeamId}"); - BoolRes boolRes = new(); - if (request.PlayerId >= spectatorMinPlayerID) - { - boolRes.ActSuccess = false; - return Task.FromResult(boolRes); - } - // var gameID = communicationToGameID[request.TeamId][request.PlayerId]; - boolRes.ActSuccess = game.RepairHome(request.TeamId, request.PlayerId); - GameServerLogging.logger.ConsoleLogDebug("END RepairHome"); - return Task.FromResult(boolRes); - } - - public override Task RepairWormhole(IDMsg request, ServerCallContext context) - { - GameServerLogging.logger.ConsoleLogDebug( - $"TRY RepairWormhole: Player {request.PlayerId} from Team {request.TeamId}"); - BoolRes boolRes = new(); - if (request.PlayerId >= spectatorMinPlayerID) - { - boolRes.ActSuccess = false; - return Task.FromResult(boolRes); - } - // var gameID = communicationToGameID[request.TeamId][request.PlayerId]; - boolRes.ActSuccess = game.RepairWormhole(request.TeamId, request.PlayerId); - GameServerLogging.logger.ConsoleLogDebug("END RepairWormhole"); - return Task.FromResult(boolRes); - } - public override Task Rebuild(ConstructMsg request, ServerCallContext context) { GameServerLogging.logger.ConsoleLogDebug( From ae341bf56bdfd7368a09c5a7c5ebd5739453cd25 Mon Sep 17 00:00:00 2001 From: sigureling <1678348940@qq.com> Date: Thu, 16 May 2024 17:06:15 +0800 Subject: [PATCH 6/8] perf: :fire: remove std::move --- CAPI/cpp/API/src/API.cpp | 4 ++-- CAPI/cpp/API/src/DebugAPI.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CAPI/cpp/API/src/API.cpp b/CAPI/cpp/API/src/API.cpp index 6b9fbc2a..9656d2ec 100755 --- a/CAPI/cpp/API/src/API.cpp +++ b/CAPI/cpp/API/src/API.cpp @@ -141,12 +141,12 @@ THUAI7::PlaceType TeamAPI::GetPlaceType(int32_t cellX, int32_t cellY) const std::optional ShipAPI::GetConstructionState(int32_t cellX, int32_t cellY) const { - return std::move(logic.GetConstructionState(cellX, cellY)); + return logic.GetConstructionState(cellX, cellY); } std::optional TeamAPI::GetConstructionState(int32_t cellX, int32_t cellY) const { - return std::move(logic.GetConstructionState(cellX, cellY)); + return logic.GetConstructionState(cellX, cellY); } int32_t ShipAPI::GetWormholeHp(int32_t cellX, int32_t cellY) const diff --git a/CAPI/cpp/API/src/DebugAPI.cpp b/CAPI/cpp/API/src/DebugAPI.cpp index 6b308761..4e24fd50 100755 --- a/CAPI/cpp/API/src/DebugAPI.cpp +++ b/CAPI/cpp/API/src/DebugAPI.cpp @@ -224,7 +224,7 @@ THUAI7::PlaceType ShipDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const std::optional ShipDebugAPI::GetConstructionState(int32_t cellX, int32_t cellY) const { - return std::move(logic.GetConstructionState(cellX, cellY)); + return logic.GetConstructionState(cellX, cellY); } int32_t ShipDebugAPI::GetWormholeHp(int32_t cellX, int32_t cellY) const @@ -418,7 +418,7 @@ THUAI7::PlaceType TeamDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const std::optional TeamDebugAPI::GetConstructionState(int32_t cellX, int32_t cellY) const { - return std::move(logic.GetConstructionState(cellX, cellY)); + return logic.GetConstructionState(cellX, cellY); } int32_t TeamDebugAPI::GetWormholeHp(int32_t cellX, int32_t cellY) const From d2c5e5557713b7336f6b3815cfd9e170325d5f0e Mon Sep 17 00:00:00 2001 From: sigureling <1678348940@qq.com> Date: Thu, 16 May 2024 17:07:11 +0800 Subject: [PATCH 7/8] perf: :fire: remove spare construct function --- CAPI/cpp/API/src/logic.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CAPI/cpp/API/src/logic.cpp b/CAPI/cpp/API/src/logic.cpp index f7f0faeb..9710b355 100755 --- a/CAPI/cpp/API/src/logic.cpp +++ b/CAPI/cpp/API/src/logic.cpp @@ -101,12 +101,12 @@ std::optional Logic::GetConstructionState(int32_t cel auto it3 = currentState->mapInfo->fortState.find(pos); if (it != currentState->mapInfo->factoryState.end()) { - return std::make_optional(THUAI7::ConstructionState(currentState->mapInfo->factoryState[pos], THUAI7::ConstructionType::Factory)); + return std::make_optional(currentState->mapInfo->factoryState[pos], THUAI7::ConstructionType::Factory); } else if (it2 != currentState->mapInfo->communityState.end()) - return std::make_optional(THUAI7::ConstructionState(currentState->mapInfo->communityState[pos], THUAI7::ConstructionType::Community)); + return std::make_optional(currentState->mapInfo->communityState[pos], THUAI7::ConstructionType::Community); else if (it3 != currentState->mapInfo->fortState.end()) - return std::make_optional(THUAI7::ConstructionState(currentState->mapInfo->fortState[pos], THUAI7::ConstructionType::Fort)); + return std::make_optional(currentState->mapInfo->fortState[pos], THUAI7::ConstructionType::Fort); else { logger->warn("Construction not found"); From b73242a375447273f97511f47de0c5dc5989c0a1 Mon Sep 17 00:00:00 2001 From: sigureling <1678348940@qq.com> Date: Thu, 16 May 2024 17:10:53 +0800 Subject: [PATCH 8/8] style: :art: change to THUAI7.ConstructionState | None --- CAPI/python/PyAPI/API.py | 4 ++-- CAPI/python/PyAPI/DebugAPI.py | 4 ++-- CAPI/python/PyAPI/Interface.py | 6 +++--- CAPI/python/PyAPI/logic.py | 8 ++++---- CAPI/python/PyAPI/structures.py | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CAPI/python/PyAPI/API.py b/CAPI/python/PyAPI/API.py index 5b950c5d..70eb0950 100644 --- a/CAPI/python/PyAPI/API.py +++ b/CAPI/python/PyAPI/API.py @@ -82,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) -> THUAI7.Construction: + def GetConstructionState(self, cellX: int, cellY: int) -> THUAI7.ConstructionState | None: return self.__logic.GetConstructionState(cellX, cellY) def GetWormholeHp(self, cellX: int, cellY: int) -> int: @@ -190,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) -> THUAI7.Construction: + 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/DebugAPI.py b/CAPI/python/PyAPI/DebugAPI.py index 8a02d3df..25f6f66c 100644 --- a/CAPI/python/PyAPI/DebugAPI.py +++ b/CAPI/python/PyAPI/DebugAPI.py @@ -227,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) -> THUAI7.Construction: + def GetConstructionState(self, cellX: int, cellY: int) -> THUAI7.ConstructionState | None: return self.__logic.GetConstructionState(cellX, cellY) def GetWormholeHp(self, cellX: int, cellY: int) -> int: @@ -465,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) -> THUAI7.Construction: + 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/Interface.py b/CAPI/python/PyAPI/Interface.py index b41c2dbd..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) -> THUAI7.Construction: + def GetConstructionState(self, cellX: int, cellY: int) -> THUAI7.ConstructionState | None: pass @abstractmethod @@ -247,7 +247,7 @@ def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType: pass @abstractmethod - def GetConstructionState(self, cellX: int, cellY: int) -> THUAI7.Construction: + def GetConstructionState(self, cellX: int, cellY: int) -> THUAI7.ConstructionState | None: """获取当前建筑状态 :param cellX: X坐标, 单位Cell @@ -415,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` diff --git a/CAPI/python/PyAPI/logic.py b/CAPI/python/PyAPI/logic.py index 36934ae7..bb4e1dae 100644 --- a/CAPI/python/PyAPI/logic.py +++ b/CAPI/python/PyAPI/logic.py @@ -138,21 +138,21 @@ def GetPlayerGUIDs(self) -> List[int]: with self.__mtxState: return copy.deepcopy(self.__currentState.guids) - def GetConstructionState(self, cellX: int, cellY: int) -> THUAI7.Construction: + 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 THUAI7.Construction( + return THUAI7.ConstructionState( self.__currentState.mapInfo.factoryState[(cellX, cellY)], THUAI7.ConstructionType.Factory, ) elif (cellX, cellY) in self.__currentState.mapInfo.communityState: - return THUAI7.Construction( + return THUAI7.ConstructionState( self.__currentState.mapInfo.communityState[(cellX, cellY)], THUAI7.ConstructionType.Community, ) elif (cellX, cellY) in self.__currentState.mapInfo.fortState: - return THUAI7.Construction( + return THUAI7.ConstructionState( self.__currentState.mapInfo.fortState[(cellX, cellY)], THUAI7.ConstructionType.Fort, ) diff --git a/CAPI/python/PyAPI/structures.py b/CAPI/python/PyAPI/structures.py index 54612465..59b02fd8 100644 --- a/CAPI/python/PyAPI/structures.py +++ b/CAPI/python/PyAPI/structures.py @@ -227,7 +227,7 @@ def __init__(self): self.teamID: int = 0 self.guid: int = 0 -class Construction: +class ConstructionState: def __init__(self,teamID,HP,type:ConstructionType): self.teamID=teamID self.hp=HP