| @@ -69,8 +69,8 @@ public: | |||||
| virtual bool Graduate() = 0; | virtual bool Graduate() = 0; | ||||
| virtual bool StartLearning() = 0; | virtual bool StartLearning() = 0; | ||||
| virtual bool StartTreatMate(int64_t mateID) = 0; | |||||
| virtual bool StartRescueMate(int64_t mateID) = 0; | |||||
| virtual bool StartEncourageMate(int64_t mateID) = 0; | |||||
| virtual bool StartRouseMate(int64_t mateID) = 0; | |||||
| virtual bool OpenDoor() = 0; | virtual bool OpenDoor() = 0; | ||||
| virtual bool CloseDoor() = 0; | virtual bool CloseDoor() = 0; | ||||
| @@ -177,8 +177,8 @@ public: | |||||
| /*****学生阵营的特定函数*****/ | /*****学生阵营的特定函数*****/ | ||||
| virtual std::future<bool> StartLearning() = 0; | virtual std::future<bool> StartLearning() = 0; | ||||
| virtual std::future<bool> StartTreatMate(int64_t mateID) = 0; | |||||
| virtual std::future<bool> StartRescueMate(int64_t mateID) = 0; | |||||
| virtual std::future<bool> StartEncourageMate(int64_t mateID) = 0; | |||||
| virtual std::future<bool> StartRouseMate(int64_t mateID) = 0; | |||||
| virtual std::future<bool> Graduate() = 0; | virtual std::future<bool> Graduate() = 0; | ||||
| [[nodiscard]] virtual std::shared_ptr<const THUAI6::Student> GetSelfInfo() const = 0; | [[nodiscard]] virtual std::shared_ptr<const THUAI6::Student> GetSelfInfo() const = 0; | ||||
| }; | }; | ||||
| @@ -266,8 +266,8 @@ public: | |||||
| [[nodiscard]] std::vector<int64_t> GetPlayerGUIDs() const override; | [[nodiscard]] std::vector<int64_t> GetPlayerGUIDs() const override; | ||||
| std::future<bool> StartLearning() override; | std::future<bool> StartLearning() override; | ||||
| std::future<bool> StartTreatMate(int64_t mateID) override; | |||||
| std::future<bool> StartRescueMate(int64_t mateID) override; | |||||
| std::future<bool> StartEncourageMate(int64_t mateID) override; | |||||
| std::future<bool> StartRouseMate(int64_t mateID) override; | |||||
| std::future<bool> Graduate() override; | std::future<bool> Graduate() override; | ||||
| [[nodiscard]] std::shared_ptr<const THUAI6::Student> GetSelfInfo() const override; | [[nodiscard]] std::shared_ptr<const THUAI6::Student> GetSelfInfo() const override; | ||||
| @@ -434,8 +434,8 @@ public: | |||||
| [[nodiscard]] std::vector<int64_t> GetPlayerGUIDs() const override; | [[nodiscard]] std::vector<int64_t> GetPlayerGUIDs() const override; | ||||
| std::future<bool> StartLearning() override; | std::future<bool> StartLearning() override; | ||||
| std::future<bool> StartTreatMate(int64_t mateID) override; | |||||
| std::future<bool> StartRescueMate(int64_t mateID) override; | |||||
| std::future<bool> StartEncourageMate(int64_t mateID) override; | |||||
| std::future<bool> StartRouseMate(int64_t mateID) override; | |||||
| std::future<bool> Graduate() override; | std::future<bool> Graduate() override; | ||||
| [[nodiscard]] virtual std::shared_ptr<const THUAI6::Student> GetSelfInfo() const override; | [[nodiscard]] virtual std::shared_ptr<const THUAI6::Student> GetSelfInfo() const override; | ||||
| @@ -39,8 +39,8 @@ public: | |||||
| bool Graduate(int64_t playerID); | bool Graduate(int64_t playerID); | ||||
| bool StartLearning(int64_t playerID); | bool StartLearning(int64_t playerID); | ||||
| bool StartTreatMate(int64_t playerID, int64_t mateID); | |||||
| bool StartRescueMate(int64_t playerID, int64_t mateID); | |||||
| bool StartEncourageMate(int64_t playerID, int64_t mateID); | |||||
| bool StartRouseMate(int64_t playerID, int64_t mateID); | |||||
| bool Attack(double angle, int64_t playerID); | bool Attack(double angle, int64_t playerID); | ||||
| @@ -125,8 +125,8 @@ private: | |||||
| bool StartLearning() override; | bool StartLearning() override; | ||||
| bool StartTreatMate(int64_t mateID) override; | |||||
| bool StartRescueMate(int64_t mateID) override; | |||||
| bool StartEncourageMate(int64_t mateID) override; | |||||
| bool StartRouseMate(int64_t mateID) override; | |||||
| bool Attack(double angle) override; | bool Attack(double angle) override; | ||||
| @@ -1,6 +1,7 @@ | |||||
| #include <vector> | #include <vector> | ||||
| #include <thread> | #include <thread> | ||||
| #include "AI.h" | #include "AI.h" | ||||
| #include "constants.h" | |||||
| // 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新 | // 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新 | ||||
| extern const bool asynchronous = false; | extern const bool asynchronous = false; | ||||
| @@ -383,16 +383,16 @@ std::future<bool> StudentAPI::StartLearning() | |||||
| { return logic.StartLearning(); }); | { return logic.StartLearning(); }); | ||||
| } | } | ||||
| std::future<bool> StudentAPI::StartTreatMate(int64_t mateID) | |||||
| std::future<bool> StudentAPI::StartEncourageMate(int64_t mateID) | |||||
| { | { | ||||
| return std::async(std::launch::async, [=]() | return std::async(std::launch::async, [=]() | ||||
| { return logic.StartTreatMate(mateID); }); | |||||
| { return logic.StartEncourageMate(mateID); }); | |||||
| } | } | ||||
| std::future<bool> StudentAPI::StartRescueMate(int64_t mateID) | |||||
| std::future<bool> StudentAPI::StartRouseMate(int64_t mateID) | |||||
| { | { | ||||
| return std::async(std::launch::async, [=]() | return std::async(std::launch::async, [=]() | ||||
| { return logic.StartRescueMate(mateID); }); | |||||
| { return logic.StartRouseMate(mateID); }); | |||||
| } | } | ||||
| std::future<bool> StudentAPI::Graduate() | std::future<bool> StudentAPI::Graduate() | ||||
| @@ -183,7 +183,7 @@ bool Communication::StartLearning(int64_t playerID) | |||||
| return false; | return false; | ||||
| } | } | ||||
| bool Communication::StartRescueMate(int64_t playerID, int64_t mateID) | |||||
| bool Communication::StartRouseMate(int64_t playerID, int64_t mateID) | |||||
| { | { | ||||
| protobuf::BoolRes saveStudentResult; | protobuf::BoolRes saveStudentResult; | ||||
| ClientContext context; | ClientContext context; | ||||
| @@ -195,7 +195,7 @@ bool Communication::StartRescueMate(int64_t playerID, int64_t mateID) | |||||
| return false; | return false; | ||||
| } | } | ||||
| bool Communication::StartTreatMate(int64_t playerID, int64_t mateID) | |||||
| bool Communication::StartEncourageMate(int64_t playerID, int64_t mateID) | |||||
| { | { | ||||
| protobuf::BoolRes healStudentResult; | protobuf::BoolRes healStudentResult; | ||||
| ClientContext context; | ClientContext context; | ||||
| @@ -575,23 +575,23 @@ std::future<bool> StudentDebugAPI::StartLearning() | |||||
| return result; }); | return result; }); | ||||
| } | } | ||||
| std::future<bool> StudentDebugAPI::StartRescueMate(int64_t mateID) | |||||
| std::future<bool> StudentDebugAPI::StartRouseMate(int64_t mateID) | |||||
| { | { | ||||
| logger->info("StartRescueMate: mate id={}, called at {}ms", mateID, Time::TimeSinceStart(startPoint)); | |||||
| logger->info("StartRouseMate: mate id={}, called at {}ms", mateID, Time::TimeSinceStart(startPoint)); | |||||
| return std::async(std::launch::async, [=]() | return std::async(std::launch::async, [=]() | ||||
| { auto result = logic.StartRescueMate(mateID); | |||||
| { auto result = logic.StartRouseMate(mateID); | |||||
| if (!result) | if (!result) | ||||
| logger->warn("StartRescueMate: failed at {}ms", Time::TimeSinceStart(startPoint)); | |||||
| logger->warn("StartRouseMate: failed at {}ms", Time::TimeSinceStart(startPoint)); | |||||
| return result; }); | return result; }); | ||||
| } | } | ||||
| std::future<bool> StudentDebugAPI::StartTreatMate(int64_t mateID) | |||||
| std::future<bool> StudentDebugAPI::StartEncourageMate(int64_t mateID) | |||||
| { | { | ||||
| logger->info("StartTreatMate: mate id={}, called at {}ms", mateID, Time::TimeSinceStart(startPoint)); | |||||
| logger->info("StartEncourageMate: mate id={}, called at {}ms", mateID, Time::TimeSinceStart(startPoint)); | |||||
| return std::async(std::launch::async, [=]() | return std::async(std::launch::async, [=]() | ||||
| { auto result = logic.StartTreatMate(mateID); | |||||
| { auto result = logic.StartEncourageMate(mateID); | |||||
| if (!result) | if (!result) | ||||
| logger->warn("StartTreatMate: failed at {}ms", Time::TimeSinceStart(startPoint)); | |||||
| logger->warn("StartEncourageMate: failed at {}ms", Time::TimeSinceStart(startPoint)); | |||||
| return result; }); | return result; }); | ||||
| } | } | ||||
| @@ -251,16 +251,16 @@ bool Logic::StartLearning() | |||||
| return pComm->StartLearning(playerID); | return pComm->StartLearning(playerID); | ||||
| } | } | ||||
| bool Logic::StartTreatMate(int64_t mateID) | |||||
| bool Logic::StartEncourageMate(int64_t mateID) | |||||
| { | { | ||||
| logger->debug("Called StartTreatMate"); | |||||
| return pComm->StartTreatMate(playerID, mateID); | |||||
| logger->debug("Called StartEncourageMate"); | |||||
| return pComm->StartEncourageMate(playerID, mateID); | |||||
| } | } | ||||
| bool Logic::StartRescueMate(int64_t mateID) | |||||
| bool Logic::StartRouseMate(int64_t mateID) | |||||
| { | { | ||||
| logger->debug("Called StartRescueMate"); | |||||
| return pComm->StartRescueMate(playerID, mateID); | |||||
| logger->debug("Called StartRouseMate"); | |||||
| return pComm->StartRouseMate(playerID, mateID); | |||||
| } | } | ||||
| bool Logic::Attack(double angle) | bool Logic::Attack(double angle) | ||||
| @@ -1,31 +0,0 @@ | |||||
| | |||||
| Microsoft Visual Studio Solution File, Format Version 12.00 | |||||
| # Visual Studio Version 17 | |||||
| VisualStudioVersion = 17.0.32014.148 | |||||
| MinimumVisualStudioVersion = 10.0.40219.1 | |||||
| Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "API", "API\API.vcxproj", "{B9AC3133-177D-453C-8066-ED4702D3F36A}" | |||||
| EndProject | |||||
| Global | |||||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||||
| Debug|x64 = Debug|x64 | |||||
| Debug|x86 = Debug|x86 | |||||
| Release|x64 = Release|x64 | |||||
| Release|x86 = Release|x86 | |||||
| EndGlobalSection | |||||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | |||||
| {B9AC3133-177D-453C-8066-ED4702D3F36A}.Debug|x64.ActiveCfg = Debug|x64 | |||||
| {B9AC3133-177D-453C-8066-ED4702D3F36A}.Debug|x64.Build.0 = Debug|x64 | |||||
| {B9AC3133-177D-453C-8066-ED4702D3F36A}.Debug|x86.ActiveCfg = Debug|Win32 | |||||
| {B9AC3133-177D-453C-8066-ED4702D3F36A}.Debug|x86.Build.0 = Debug|Win32 | |||||
| {B9AC3133-177D-453C-8066-ED4702D3F36A}.Release|x64.ActiveCfg = Release|x64 | |||||
| {B9AC3133-177D-453C-8066-ED4702D3F36A}.Release|x64.Build.0 = Release|x64 | |||||
| {B9AC3133-177D-453C-8066-ED4702D3F36A}.Release|x86.ActiveCfg = Release|Win32 | |||||
| {B9AC3133-177D-453C-8066-ED4702D3F36A}.Release|x86.Build.0 = Release|Win32 | |||||
| EndGlobalSection | |||||
| GlobalSection(SolutionProperties) = preSolution | |||||
| HideSolutionNode = FALSE | |||||
| EndGlobalSection | |||||
| GlobalSection(ExtensibilityGlobals) = postSolution | |||||
| SolutionGuid = {372B1478-522C-4EEB-A527-983D310A3F50} | |||||
| EndGlobalSection | |||||
| EndGlobal | |||||
| @@ -1,6 +1,7 @@ | |||||
| import PyAPI.structures as THUAI6 | import PyAPI.structures as THUAI6 | ||||
| from PyAPI.Interface import IStudentAPI, ITrickerAPI, IAI | from PyAPI.Interface import IStudentAPI, ITrickerAPI, IAI | ||||
| from typing import Union, Final, cast | from typing import Union, Final, cast | ||||
| from PyAPI.constants import Constants | |||||
| import queue | import queue | ||||
| import time | import time | ||||
| @@ -147,4 +148,7 @@ class AI(IAI): | |||||
| api.PrintTricker() | api.PrintTricker() | ||||
| def TrickerPlay(self, api: ITrickerAPI) -> None: | def TrickerPlay(self, api: ITrickerAPI) -> None: | ||||
| api.UseSkill(0) | |||||
| api.UseSkill(1) | |||||
| api.PrintSelfInfo() | |||||
| return | return | ||||
| @@ -157,11 +157,11 @@ class StudentAPI(IStudentAPI, IGameTimer): | |||||
| def StartLearning(self) -> Future[bool]: | def StartLearning(self) -> Future[bool]: | ||||
| return self.__pool.submit(self.__logic.StartLearning) | return self.__pool.submit(self.__logic.StartLearning) | ||||
| def StartTreatMate(self, mateID: int) -> Future[bool]: | |||||
| return self.__pool.submit(self.__logic.StartTreatMate, mateID) | |||||
| def StartEncourageMate(self, mateID: int) -> Future[bool]: | |||||
| return self.__pool.submit(self.__logic.StartEncourageMate, mateID) | |||||
| def StartRescueMate(self, mateID: int) -> Future[bool]: | |||||
| return self.__pool.submit(self.__logic.StartRescueMate, mateID) | |||||
| def StartRouseMate(self, mateID: int) -> Future[bool]: | |||||
| return self.__pool.submit(self.__logic.StartRouseMate, mateID) | |||||
| def GetSelfInfo(self) -> THUAI6.Student: | def GetSelfInfo(self) -> THUAI6.Student: | ||||
| return cast(THUAI6.Student, self.__logic.GetSelfInfo()) | return cast(THUAI6.Student, self.__logic.GetSelfInfo()) | ||||
| @@ -102,7 +102,7 @@ class Communication: | |||||
| else: | else: | ||||
| return learnResult.act_success | return learnResult.act_success | ||||
| def StartTreatMate(self, playerID: int, mateID: int) -> bool: | |||||
| def StartEncourageMate(self, playerID: int, mateID: int) -> bool: | |||||
| try: | try: | ||||
| helpResult = self.__THUAI6Stub.StartTreatMate( | helpResult = self.__THUAI6Stub.StartTreatMate( | ||||
| THUAI62Proto.THUAI62ProtobufTreatAndRescue(playerID, mateID)) | THUAI62Proto.THUAI62ProtobufTreatAndRescue(playerID, mateID)) | ||||
| @@ -111,7 +111,7 @@ class Communication: | |||||
| else: | else: | ||||
| return helpResult.act_success | return helpResult.act_success | ||||
| def StartRescueMate(self, playerID: int, mateID: int) -> bool: | |||||
| def StartRouseMate(self, playerID: int, mateID: int) -> bool: | |||||
| try: | try: | ||||
| helpResult = self.__THUAI6Stub.StartRescueMate( | helpResult = self.__THUAI6Stub.StartRescueMate( | ||||
| THUAI62Proto.THUAI62ProtobufTreatAndRescue(playerID, mateID)) | THUAI62Proto.THUAI62ProtobufTreatAndRescue(playerID, mateID)) | ||||
| @@ -414,31 +414,31 @@ class StudentDebugAPI(IStudentAPI, IGameTimer): | |||||
| return self.__pool.submit(logStart) | return self.__pool.submit(logStart) | ||||
| def StartTreatMate(self, mateID: int) -> Future[bool]: | |||||
| def StartEncourageMate(self, mateID: int) -> Future[bool]: | |||||
| self.__logger.info( | self.__logger.info( | ||||
| f"StartTreatMate: called at {self.__GetTime()}ms") | |||||
| f"StartEncourageMate: called at {self.__GetTime()}ms") | |||||
| def logStartTreatMate() -> bool: | |||||
| result = self.__logic.StartTreatMate(mateID) | |||||
| def logStartEncourageMate() -> bool: | |||||
| result = self.__logic.StartEncourageMate(mateID) | |||||
| if not result: | if not result: | ||||
| self.__logger.warning( | self.__logger.warning( | ||||
| f"StartTreatMate: failed at {self.__GetTime()}ms") | |||||
| f"StartEncourageMate: failed at {self.__GetTime()}ms") | |||||
| return result | return result | ||||
| return self.__pool.submit(logStartTreatMate) | |||||
| return self.__pool.submit(logStartEncourageMate) | |||||
| def StartRescueMate(self, mateID: int) -> Future[bool]: | |||||
| def StartRouseMate(self, mateID: int) -> Future[bool]: | |||||
| self.__logger.info( | self.__logger.info( | ||||
| f"StartRescueMate: called at {self.__GetTime()}ms") | |||||
| f"StartRouseMate: called at {self.__GetTime()}ms") | |||||
| def logStartRescueMate() -> bool: | |||||
| result = self.__logic.StartRescueMate(mateID) | |||||
| def logStartRouseMate() -> bool: | |||||
| result = self.__logic.StartRouseMate(mateID) | |||||
| if not result: | if not result: | ||||
| self.__logger.warning( | self.__logger.warning( | ||||
| f"StartRescueMate: failed at {self.__GetTime()}ms") | |||||
| f"StartRouseMate: failed at {self.__GetTime()}ms") | |||||
| return result | return result | ||||
| return self.__pool.submit(logStartRescueMate) | |||||
| return self.__pool.submit(logStartRouseMate) | |||||
| def GetSelfInfo(self) -> THUAI6.Student: | def GetSelfInfo(self) -> THUAI6.Student: | ||||
| return cast(THUAI6.Student, self.__logic.GetSelfInfo()) | return cast(THUAI6.Student, self.__logic.GetSelfInfo()) | ||||
| @@ -147,11 +147,11 @@ class ILogic(metaclass=ABCMeta): | |||||
| pass | pass | ||||
| @abstractmethod | @abstractmethod | ||||
| def StartTreatMate(self, mateID: int) -> bool: | |||||
| def StartEncourageMate(self, mateID: int) -> bool: | |||||
| pass | pass | ||||
| @abstractmethod | @abstractmethod | ||||
| def StartRescueMate(self, mateID: int) -> bool: | |||||
| def StartRouseMate(self, mateID: int) -> bool: | |||||
| pass | pass | ||||
| @@ -350,11 +350,11 @@ class IStudentAPI(IAPI, metaclass=ABCMeta): | |||||
| pass | pass | ||||
| @abstractmethod | @abstractmethod | ||||
| def StartTreatMate(self, mateID: int) -> Future[bool]: | |||||
| def StartEncourageMate(self, mateID: int) -> Future[bool]: | |||||
| pass | pass | ||||
| @abstractmethod | @abstractmethod | ||||
| def StartRescueMate(self, mateID: int) -> Future[bool]: | |||||
| def StartRouseMate(self, mateID: int) -> Future[bool]: | |||||
| pass | pass | ||||
| @abstractmethod | @abstractmethod | ||||
| @@ -1,4 +1,9 @@ | |||||
| class Constants(): | |||||
| class NoInstance: | |||||
| def __call__(self): | |||||
| raise TypeError("This class cannot be instantiated.") | |||||
| class Constants(NoInstance): | |||||
| numOfGridPerCell = 1000 # 单位坐标数 | numOfGridPerCell = 1000 # 单位坐标数 | ||||
| rows = 50 # 地图行数 | rows = 50 # 地图行数 | ||||
| cols = 50 # 地图列数 | cols = 50 # 地图列数 | ||||
| @@ -224,13 +224,13 @@ class Logic(ILogic): | |||||
| self.__logger.debug("Called StartLearning") | self.__logger.debug("Called StartLearning") | ||||
| return self.__comm.StartLearning(self.__playerID) | return self.__comm.StartLearning(self.__playerID) | ||||
| def StartTreatMate(self, mateID: int) -> bool: | |||||
| self.__logger.debug("Called StartTreatMate") | |||||
| return self.__comm.StartTreatMate(self.__playerID, mateID) | |||||
| def StartEncourageMate(self, mateID: int) -> bool: | |||||
| self.__logger.debug("Called StartEncourageMate") | |||||
| return self.__comm.StartEncourageMate(self.__playerID, mateID) | |||||
| def StartRescueMate(self, mateID: int) -> bool: | |||||
| self.__logger.debug("Called StartRescueMate") | |||||
| return self.__comm.StartRescueMate(self.__playerID, mateID) | |||||
| def StartRouseMate(self, mateID: int) -> bool: | |||||
| self.__logger.debug("Called StartRouseMate") | |||||
| return self.__comm.StartRouseMate(self.__playerID, mateID) | |||||
| def Attack(self, angle: float) -> bool: | def Attack(self, angle: float) -> bool: | ||||
| self.__logger.debug("Called Trick") | self.__logger.debug("Called Trick") | ||||