| @@ -27,11 +27,11 @@ class ILogic | |||||
| public: | public: | ||||
| // 获取服务器发来的消息 | // 获取服务器发来的消息 | ||||
| virtual std::vector<std::shared_ptr<THUAI6::Butcher>> GetButchers() const = 0; | |||||
| virtual std::vector<std::shared_ptr<THUAI6::Human>> GetHumans() const = 0; | |||||
| virtual std::vector<std::shared_ptr<THUAI6::Prop>> GetProps() const = 0; | |||||
| virtual std::shared_ptr<THUAI6::Human> HumanGetSelfInfo() const = 0; | |||||
| virtual std::shared_ptr<THUAI6::Butcher> ButcherGetSelfInfo() const = 0; | |||||
| virtual std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButchers() const = 0; | |||||
| virtual std::vector<std::shared_ptr<const THUAI6::Human>> GetHumans() const = 0; | |||||
| virtual std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const = 0; | |||||
| virtual std::shared_ptr<const THUAI6::Human> HumanGetSelfInfo() const = 0; | |||||
| virtual std::shared_ptr<const THUAI6::Butcher> ButcherGetSelfInfo() const = 0; | |||||
| virtual std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const = 0; | virtual std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const = 0; | ||||
| @@ -79,7 +79,7 @@ public: | |||||
| virtual std::future<bool> MoveDown(int64_t timeInMilliseconds) = 0; | virtual std::future<bool> MoveDown(int64_t timeInMilliseconds) = 0; | ||||
| // 捡道具、使用技能 | // 捡道具、使用技能 | ||||
| virtual std::future<bool> PickProp() = 0; | |||||
| virtual std::future<bool> PickProp(THUAI6::PropType prop) = 0; | |||||
| virtual std::future<bool> UseProp() = 0; | virtual std::future<bool> UseProp() = 0; | ||||
| virtual std::future<bool> UseSkill() = 0; | virtual std::future<bool> UseSkill() = 0; | ||||
| @@ -179,32 +179,16 @@ public: | |||||
| { | { | ||||
| } | } | ||||
| std::future<bool> MoveRight(int64_t timeInMilliseconds) override | |||||
| { | |||||
| } | |||||
| std::future<bool> MoveUp(int64_t timeInMilliseconds) override | |||||
| { | |||||
| } | |||||
| std::future<bool> MoveLeft(int64_t timeInMilliseconds) override | |||||
| { | |||||
| } | |||||
| std::future<bool> MoveDown(int64_t timeInMilliseconds) override | |||||
| { | |||||
| } | |||||
| std::future<bool> MoveRight(int64_t timeInMilliseconds) override; | |||||
| std::future<bool> MoveUp(int64_t timeInMilliseconds) override; | |||||
| std::future<bool> MoveLeft(int64_t timeInMilliseconds) override; | |||||
| std::future<bool> MoveDown(int64_t timeInMilliseconds) override; | |||||
| std::future<bool> PickProp() override | |||||
| { | |||||
| } | |||||
| std::future<bool> UseProp() override | |||||
| { | |||||
| } | |||||
| std::future<bool> UseSkill() override | |||||
| { | |||||
| } | |||||
| std::future<bool> PickProp(THUAI6::PropType prop) override; | |||||
| std::future<bool> UseProp() override; | |||||
| std::future<bool> UseSkill() override; | |||||
| std::future<bool> SendMessage(int64_t, std::string) override | |||||
| { | |||||
| } | |||||
| std::future<bool> SendMessage(int64_t, std::string) override; | |||||
| [[nodiscard]] std::future<bool> HaveMessage() override | [[nodiscard]] std::future<bool> HaveMessage() override | ||||
| { | { | ||||
| } | } | ||||
| @@ -216,20 +200,12 @@ public: | |||||
| { | { | ||||
| } | } | ||||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Human>> GetHuman() const override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButcher() const override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Human>> GetHuman() const override; | |||||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButcher() const override; | |||||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const override; | |||||
| [[nodiscard]] std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const override; | |||||
| [[nodiscard]] THUAI6::PlaceType GetPlaceType(int32_t CellX, int32_t CellY) const override | [[nodiscard]] THUAI6::PlaceType GetPlaceType(int32_t CellX, int32_t CellY) const override | ||||
| { | { | ||||
| } | } | ||||
| @@ -282,40 +258,21 @@ public: | |||||
| } | } | ||||
| void Play(IAI& ai) override; | void Play(IAI& ai) override; | ||||
| std::future<bool> Move(int64_t timeInMilliseconds, double angleInRadian) override | |||||
| { | |||||
| } | |||||
| std::future<bool> Move(int64_t timeInMilliseconds, double angleInRadian) override; | |||||
| [[nodiscard]] int GetFrameCount() const override | [[nodiscard]] int GetFrameCount() const override | ||||
| { | { | ||||
| } | } | ||||
| std::future<bool> MoveRight(int64_t timeInMilliseconds) override | |||||
| { | |||||
| } | |||||
| std::future<bool> MoveUp(int64_t timeInMilliseconds) override | |||||
| { | |||||
| } | |||||
| std::future<bool> MoveLeft(int64_t timeInMilliseconds) override | |||||
| { | |||||
| } | |||||
| std::future<bool> MoveDown(int64_t timeInMilliseconds) override | |||||
| { | |||||
| } | |||||
| std::future<bool> MoveRight(int64_t timeInMilliseconds) override; | |||||
| std::future<bool> MoveUp(int64_t timeInMilliseconds) override; | |||||
| std::future<bool> MoveLeft(int64_t timeInMilliseconds) override; | |||||
| std::future<bool> MoveDown(int64_t timeInMilliseconds) override; | |||||
| std::future<bool> PickProp(THUAI6::PropType prop) override; | |||||
| std::future<bool> UseProp() override; | |||||
| std::future<bool> UseSkill() override; | |||||
| std::future<bool> PickProp() override | |||||
| { | |||||
| } | |||||
| std::future<bool> UseProp() override | |||||
| { | |||||
| } | |||||
| std::future<bool> UseSkill() override | |||||
| { | |||||
| } | |||||
| std::future<bool> SendMessage(int64_t, std::string) override | |||||
| { | |||||
| } | |||||
| std::future<bool> SendMessage(int64_t, std::string) override; | |||||
| [[nodiscard]] std::future<bool> HaveMessage() override | [[nodiscard]] std::future<bool> HaveMessage() override | ||||
| { | { | ||||
| } | } | ||||
| @@ -405,7 +362,7 @@ public: | |||||
| { | { | ||||
| } | } | ||||
| std::future<bool> PickProp() override | |||||
| std::future<bool> PickProp(THUAI6::PropType prop) override | |||||
| { | { | ||||
| } | } | ||||
| std::future<bool> UseProp() override | std::future<bool> UseProp() override | ||||
| @@ -516,7 +473,7 @@ public: | |||||
| { | { | ||||
| } | } | ||||
| std::future<bool> PickProp() override | |||||
| std::future<bool> PickProp(THUAI6::PropType prop) override | |||||
| { | { | ||||
| } | } | ||||
| std::future<bool> UseProp() override | std::future<bool> UseProp() override | ||||
| @@ -83,11 +83,11 @@ private: | |||||
| // 获取服务器发来的消息 | // 获取服务器发来的消息 | ||||
| std::vector<std::shared_ptr<THUAI6::Butcher>> GetButchers() const override; | |||||
| std::vector<std::shared_ptr<THUAI6::Human>> GetHumans() const override; | |||||
| std::vector<std::shared_ptr<THUAI6::Prop>> GetProps() const override; | |||||
| std::shared_ptr<THUAI6::Human> HumanGetSelfInfo() const override; | |||||
| std::shared_ptr<THUAI6::Butcher> ButcherGetSelfInfo() const override; | |||||
| std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButchers() const override; | |||||
| std::vector<std::shared_ptr<const THUAI6::Human>> GetHumans() const override; | |||||
| std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const override; | |||||
| std::shared_ptr<const THUAI6::Human> HumanGetSelfInfo() const override; | |||||
| std::shared_ptr<const THUAI6::Butcher> ButcherGetSelfInfo() const override; | |||||
| std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const override; | std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const override; | ||||
| @@ -1,5 +1,6 @@ | |||||
| #include "AI.h" | #include "AI.h" | ||||
| #include "API.h" | #include "API.h" | ||||
| #define PI 3.14159265358979323846 | |||||
| std::future<bool> HumanAPI::Move(int64_t timeInMilliseconds, double angleInRadian) | std::future<bool> HumanAPI::Move(int64_t timeInMilliseconds, double angleInRadian) | ||||
| { | { | ||||
| @@ -7,6 +8,128 @@ std::future<bool> HumanAPI::Move(int64_t timeInMilliseconds, double angleInRadia | |||||
| { return logic.Move(timeInMilliseconds, angleInRadian); }); | { return logic.Move(timeInMilliseconds, angleInRadian); }); | ||||
| } | } | ||||
| std::future<bool> HumanAPI::MoveDown(int64_t timeInMilliseconds) | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, 0); }); | |||||
| } | |||||
| std::future<bool> HumanAPI::MoveRight(int64_t timeInMilliseconds) | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, PI * 0.5); }); | |||||
| } | |||||
| std::future<bool> HumanAPI::MoveUp(int64_t timeInMilliseconds) | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, PI); }); | |||||
| } | |||||
| std::future<bool> HumanAPI::MoveLeft(int64_t timeInMilliseconds) | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, PI * 1.5); }); | |||||
| } | |||||
| std::future<bool> ButcherAPI::Move(int64_t timeInMilliseconds, double angleInRadian) | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, angleInRadian); }); | |||||
| } | |||||
| std::future<bool> ButcherAPI::MoveDown(int64_t timeInMilliseconds) | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, 0); }); | |||||
| } | |||||
| std::future<bool> ButcherAPI::MoveRight(int64_t timeInMilliseconds) | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, PI * 0.5); }); | |||||
| } | |||||
| std::future<bool> ButcherAPI::MoveUp(int64_t timeInMilliseconds) | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, PI); }); | |||||
| } | |||||
| std::future<bool> ButcherAPI::MoveLeft(int64_t timeInMilliseconds) | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, PI * 1.5); }); | |||||
| } | |||||
| std::future<bool> HumanAPI::PickProp(THUAI6::PropType prop) | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.PickProp(prop); }); | |||||
| } | |||||
| std::future<bool> HumanAPI::UseProp() | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.UseProp(); }); | |||||
| } | |||||
| std::future<bool> ButcherAPI::PickProp(THUAI6::PropType prop) | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.PickProp(prop); }); | |||||
| } | |||||
| std::future<bool> ButcherAPI::UseProp() | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.UseProp(); }); | |||||
| } | |||||
| std::future<bool> HumanAPI::UseSkill() | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.UseSkill(); }); | |||||
| } | |||||
| std::future<bool> ButcherAPI::UseSkill() | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.UseSkill(); }); | |||||
| } | |||||
| std::future<bool> HumanAPI::SendMessage(int64_t toID, std::string message) | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.SendMessage(toID, message); }); | |||||
| } | |||||
| std::future<bool> ButcherAPI::SendMessage(int64_t toID, std::string message) | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.SendMessage(toID, message); }); | |||||
| } | |||||
| std::vector<std::shared_ptr<const THUAI6::Butcher>> HumanAPI::GetButcher() const | |||||
| { | |||||
| return logic.GetButchers(); | |||||
| } | |||||
| std::vector<std::shared_ptr<const THUAI6::Human>> HumanAPI::GetHuman() const | |||||
| { | |||||
| return logic.GetHumans(); | |||||
| } | |||||
| std::vector<std::shared_ptr<const THUAI6::Prop>> HumanAPI::GetProps() const | |||||
| { | |||||
| return logic.GetProps(); | |||||
| } | |||||
| std::vector<std::vector<THUAI6::PlaceType>> HumanAPI::GetFullMap() const | |||||
| { | |||||
| return logic.GetFullMap(); | |||||
| } | |||||
| void HumanAPI::Play(IAI& ai) | void HumanAPI::Play(IAI& ai) | ||||
| { | { | ||||
| ai.play(*this); | ai.play(*this); | ||||
| @@ -20,31 +20,37 @@ Logic::Logic(THUAI6::PlayerType type, int64_t ID, THUAI6::ButcherType butcher, T | |||||
| bufferState = &state[1]; | bufferState = &state[1]; | ||||
| } | } | ||||
| std::vector<std::shared_ptr<THUAI6::Butcher>> Logic::GetButchers() const | |||||
| std::vector<std::shared_ptr<const THUAI6::Butcher>> Logic::GetButchers() const | |||||
| { | { | ||||
| std::lock_guard<std::mutex> lock(mtxState); | std::lock_guard<std::mutex> lock(mtxState); | ||||
| return currentState->butchers; | |||||
| std::vector<std::shared_ptr<const THUAI6::Butcher>> temp; | |||||
| temp.assign(currentState->butchers.begin(), currentState->butchers.end()); | |||||
| return temp; | |||||
| } | } | ||||
| std::vector<std::shared_ptr<THUAI6::Human>> Logic::GetHumans() const | |||||
| std::vector<std::shared_ptr<const THUAI6::Human>> Logic::GetHumans() const | |||||
| { | { | ||||
| std::lock_guard<std::mutex> lock(mtxState); | std::lock_guard<std::mutex> lock(mtxState); | ||||
| return currentState->humans; | |||||
| std::vector<std::shared_ptr<const THUAI6::Human>> temp; | |||||
| temp.assign(currentState->humans.begin(), currentState->humans.end()); | |||||
| return temp; | |||||
| } | } | ||||
| std::vector<std::shared_ptr<THUAI6::Prop>> Logic::GetProps() const | |||||
| std::vector<std::shared_ptr<const THUAI6::Prop>> Logic::GetProps() const | |||||
| { | { | ||||
| std::lock_guard<std::mutex> lock(mtxState); | std::lock_guard<std::mutex> lock(mtxState); | ||||
| return currentState->props; | |||||
| std::vector<std::shared_ptr<const THUAI6::Prop>> temp; | |||||
| temp.assign(currentState->props.begin(), currentState->props.end()); | |||||
| return temp; | |||||
| } | } | ||||
| std::shared_ptr<THUAI6::Human> Logic::HumanGetSelfInfo() const | |||||
| std::shared_ptr<const THUAI6::Human> Logic::HumanGetSelfInfo() const | |||||
| { | { | ||||
| std::lock_guard<std::mutex> lock(mtxState); | std::lock_guard<std::mutex> lock(mtxState); | ||||
| return currentState->humanSelf; | return currentState->humanSelf; | ||||
| } | } | ||||
| std::shared_ptr<THUAI6::Butcher> Logic::ButcherGetSelfInfo() const | |||||
| std::shared_ptr<const THUAI6::Butcher> Logic::ButcherGetSelfInfo() const | |||||
| { | { | ||||
| std::lock_guard<std::mutex> lock(mtxState); | std::lock_guard<std::mutex> lock(mtxState); | ||||
| return currentState->butcherSelf; | return currentState->butcherSelf; | ||||