diff --git a/CAPI/API/include/AI.h b/CAPI/API/include/AI.h index 5f8cf30..7f6e0cf 100644 --- a/CAPI/API/include/AI.h +++ b/CAPI/API/include/AI.h @@ -4,13 +4,11 @@ #include "API.h" -// 暂定版本:Human和Butcher全部继承AI类, class IAI { public: - IAI() - { - } + virtual ~IAI() = default; + IAI() = default; virtual void play(IHumanAPI& api) = 0; virtual void play(IButcherAPI& api) = 0; }; diff --git a/CAPI/API/include/API.h b/CAPI/API/include/API.h index f6ead45..baf7db7 100644 --- a/CAPI/API/include/API.h +++ b/CAPI/API/include/API.h @@ -128,6 +128,13 @@ public: { return grid / num_of_grid_per_cell; } + + // 用于DEBUG的输出函数,选手仅在开启Debug模式的情况下可以使用 + + virtual void PrintHuman() const = 0; + virtual void PrintButcher() const = 0; + virtual void PrintProp() const = 0; + virtual void PrintSelfInfo() const = 0; }; class IHumanAPI : public IAPI @@ -158,6 +165,7 @@ public: class IGameTimer { public: + virtual ~IGameTimer() = default; virtual void StartTimer() = 0; virtual void EndTimer() = 0; virtual void Play(IAI& ai) = 0; @@ -214,6 +222,19 @@ public: std::future Escape() override; [[nodiscard]] std::shared_ptr GetSelfInfo() const override; + void PrintHuman() const override + { + } + void PrintButcher() const override + { + } + void PrintProp() const override + { + } + void PrintSelfInfo() const override + { + } + private: ILogic& logic; }; @@ -267,6 +288,19 @@ public: std::future HangHuman() override; [[nodiscard]] std::shared_ptr GetSelfInfo() const override; + void PrintHuman() const override + { + } + void PrintButcher() const override + { + } + void PrintProp() const override + { + } + void PrintSelfInfo() const override + { + } + private: ILogic& logic; }; @@ -314,6 +348,11 @@ public: std::future Escape() override; [[nodiscard]] virtual std::shared_ptr GetSelfInfo() const override; + void PrintHuman() const override; + void PrintButcher() const override; + void PrintProp() const override; + void PrintSelfInfo() const override; + private: std::chrono::system_clock::time_point startPoint; std::unique_ptr logger; @@ -362,6 +401,11 @@ public: std::future HangHuman() override; [[nodiscard]] std::shared_ptr GetSelfInfo() const override; + void PrintHuman() const override; + void PrintButcher() const override; + void PrintProp() const override; + void PrintSelfInfo() const override; + private: std::chrono::system_clock::time_point startPoint; std::unique_ptr logger; diff --git a/CAPI/API/include/structures.h b/CAPI/API/include/structures.h index 648aa89..9fd4dd8 100644 --- a/CAPI/API/include/structures.h +++ b/CAPI/API/include/structures.h @@ -159,7 +159,29 @@ namespace THUAI6 // 仅供DEBUG使用,名称可改动 // 还没写完,后面待续 - inline std::map placeDict{ + inline std::map gameStateDict{ + {GameState::NullGameState, "NullGameState"}, + {GameState::GameStart, "GameStart"}, + {GameState::GameRunning, "GameRunning"}, + {GameState::GameEnd, "GameEnd"}, + }; + + inline std::map humanStateDict{ + {HumanState::NullHumanState, "NullHumanState"}, + {HumanState::Idle, "Idle"}, + {HumanState::Fixing, "Fixing"}, + {HumanState::Dying, "Dying"}, + {HumanState::OnChair, "OnChair"}, + {HumanState::Dead, "Dead"}, + }; + + inline std::map playerTypeDict{ + {PlayerType::NullPlayerType, "NullPlayerType"}, + {PlayerType::HumanPlayer, "HumanPlayer"}, + {PlayerType::ButcherPlayer, "ButcherPlayer"}, + }; + + inline std::map placeTypeDict{ {PlaceType::NullPlaceType, "NullPlaceType"}, {PlaceType::Land, "Land"}, {PlaceType::Wall, "Wall"}, @@ -169,11 +191,21 @@ namespace THUAI6 {PlaceType::HiddenGate, "HiddenGate"}, }; - inline std::map propDict{ + inline std::map propTypeDict{ {PropType::NullPropType, "NullPropType"}, }; + inline std::map humanBuffDict{ + {HumanBuffType::NullHumanBuffType, "NullHumanBuffType"}, + + }; + + inline std::map butcherBuffDict{ + {ButcherBuffType::NullButcherBuffType, "NullButcherBuffType"}, + + }; + } // namespace THUAI6 #endif diff --git a/CAPI/API/src/DebugAPI.cpp b/CAPI/API/src/DebugAPI.cpp index 0872427..25ca799 100644 --- a/CAPI/API/src/DebugAPI.cpp +++ b/CAPI/API/src/DebugAPI.cpp @@ -148,7 +148,7 @@ std::future ButcherDebugAPI::MoveLeft(int64_t timeInMilliseconds) std::future HumanDebugAPI::PickProp(THUAI6::PropType prop) { - logger->info("PickProp: prop = {}, called at {}ms", THUAI6::propDict[prop], Time::TimeSinceStart(startPoint)); + logger->info("PickProp: prop = {}, called at {}ms", THUAI6::propTypeDict[prop], Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [=]() { auto result = logic.PickProp(prop); if (!result) @@ -168,7 +168,7 @@ std::future HumanDebugAPI::UseProp() std::future ButcherDebugAPI::PickProp(THUAI6::PropType prop) { - logger->info("PickProp: prop = {}, called at {}ms", THUAI6::propDict[prop], Time::TimeSinceStart(startPoint)); + logger->info("PickProp: prop = {}, called at {}ms", THUAI6::propTypeDict[prop], Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [=]() { auto result = logic.PickProp(prop); if (!result) @@ -448,6 +448,118 @@ std::shared_ptr ButcherDebugAPI::GetSelfInfo() const return logic.ButcherGetSelfInfo(); } +void HumanDebugAPI::PrintHuman() const +{ + for (auto human : logic.GetHumans()) + { + logger->info("******Human Info******"); + logger->info("playerID={}, GUID={}, x={}, y={}", human->playerID, human->guid, human->x, human->y); + logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", human->speed, human->viewRange, human->timeUntilSkillAvailable, THUAI6::propTypeDict[human->prop], THUAI6::placeTypeDict[human->place]); + logger->info("state={}, life={}, hangedTime={}", THUAI6::humanStateDict[human->state], human->life, human->hangedTime); + std::string humanBuff = "buff="; + for (auto buff : human->buff) + humanBuff += THUAI6::humanBuffDict[buff] + ", "; + logger->info(humanBuff); + logger->info("**********************"); + } +} + +void ButcherDebugAPI::PrintHuman() const +{ + for (auto human : logic.GetHumans()) + { + logger->info("******Human Info******"); + logger->info("playerID={}, GUID={}, x={}, y={}", human->playerID, human->guid, human->x, human->y); + logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", human->speed, human->viewRange, human->timeUntilSkillAvailable, THUAI6::propTypeDict[human->prop], THUAI6::placeTypeDict[human->place]); + logger->info("state={}, life={}, hangedTime={}", THUAI6::humanStateDict[human->state], human->life, human->hangedTime); + std::string humanBuff = "buff="; + for (auto buff : human->buff) + humanBuff += THUAI6::humanBuffDict[buff] + ", "; + logger->info(humanBuff); + logger->info("**********************"); + } +} + +void HumanDebugAPI::PrintButcher() const +{ + for (auto butcher : logic.GetButchers()) + { + logger->info("******Butcher Info******"); + logger->info("playerID={}, GUID={}, x={}, y={}", butcher->playerID, butcher->guid, butcher->x, butcher->y); + logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", butcher->speed, butcher->viewRange, butcher->timeUntilSkillAvailable, THUAI6::propTypeDict[butcher->prop], THUAI6::placeTypeDict[butcher->place]); + logger->info("damage={}, movable={}", butcher->damage, butcher->movable); + std::string butcherBuff = "buff="; + for (auto buff : butcher->buff) + butcherBuff += THUAI6::butcherBuffDict[buff] + ", "; + logger->info(butcherBuff); + logger->info("************************"); + } +} + +void ButcherDebugAPI::PrintButcher() const +{ + for (auto butcher : logic.GetButchers()) + { + logger->info("******Butcher Info******"); + logger->info("playerID={}, GUID={}, x={}, y={}", butcher->playerID, butcher->guid, butcher->x, butcher->y); + logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", butcher->speed, butcher->viewRange, butcher->timeUntilSkillAvailable, THUAI6::propTypeDict[butcher->prop], THUAI6::placeTypeDict[butcher->place]); + logger->info("damage={}, movable={}", butcher->damage, butcher->movable); + std::string butcherBuff = "buff="; + for (auto buff : butcher->buff) + butcherBuff += THUAI6::butcherBuffDict[buff] + ", "; + logger->info(butcherBuff); + logger->info("************************"); + } +} + +void HumanDebugAPI::PrintProp() const +{ + for (auto prop : logic.GetProps()) + { + logger->info("******Prop Info******"); + logger->info("GUID={}, x={}, y={}, place={}, is moving={}", prop->guid, prop->x, prop->y, THUAI6::placeTypeDict[prop->place], prop->isMoving); + logger->info("*********************"); + } +} + +void ButcherDebugAPI::PrintProp() const +{ + for (auto prop : logic.GetProps()) + { + logger->info("******Prop Info******"); + logger->info("GUID={}, x={}, y={}, place={}, is moving={}", prop->guid, prop->x, prop->y, THUAI6::placeTypeDict[prop->place], prop->isMoving); + logger->info("*********************"); + } +} + +void HumanDebugAPI::PrintSelfInfo() const +{ + auto self = logic.HumanGetSelfInfo(); + logger->info("******Self Info******"); + logger->info("playerID={}, GUID={}, x={}, y={}", self->playerID, self->guid, self->x, self->y); + logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", self->speed, self->viewRange, self->timeUntilSkillAvailable, THUAI6::propTypeDict[self->prop], THUAI6::placeTypeDict[self->place]); + logger->info("state={}, life={}, hangedTime={}", THUAI6::humanStateDict[self->state], self->life, self->hangedTime); + std::string humanBuff = "buff="; + for (auto buff : self->buff) + humanBuff += THUAI6::humanBuffDict[buff] + ", "; + logger->info(humanBuff); + logger->info("*********************"); +} + +void ButcherDebugAPI::PrintSelfInfo() const +{ + auto self = logic.ButcherGetSelfInfo(); + logger->info("******Self Info******"); + logger->info("playerID={}, GUID={}, x={}, y={}", self->playerID, self->guid, self->x, self->y); + logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", self->speed, self->viewRange, self->timeUntilSkillAvailable, THUAI6::propTypeDict[self->prop], THUAI6::placeTypeDict[self->place]); + logger->info("damage={}, movable={}", self->damage, self->movable); + std::string butcherBuff = "buff="; + for (auto buff : self->buff) + butcherBuff += THUAI6::butcherBuffDict[buff] + ", "; + logger->info(butcherBuff); + logger->info("*********************"); +} + void HumanDebugAPI::Play(IAI& ai) { ai.play(*this); diff --git a/CAPI/API/src/logic.cpp b/CAPI/API/src/logic.cpp index 073638f..a9634db 100644 --- a/CAPI/API/src/logic.cpp +++ b/CAPI/API/src/logic.cpp @@ -451,6 +451,14 @@ void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port, bool f printLogger->set_level(spdlog::level::warn); logger = std::make_unique("logicLogger", spdlog::sinks_init_list{fileLogger, printLogger}); + // 打印当前的调试信息 + logger->info("*********Basic Info*********"); + logger->info("asynchronous: {}", asynchronous); + logger->info("server: {}:{}", IP, port); + logger->info("player ID: {}", playerID); + logger->info("player type: {}", THUAI6::playerTypeDict[playerType]); + logger->info("****************************"); + // 建立与服务器之间通信的组件 pComm = std::make_unique(IP, port); @@ -499,12 +507,13 @@ void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port, bool f } }; - tAI = std::thread(AIThread); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); // 连接服务器 if (TryConnection()) { logger->info("Connect to the server successfully, AI thread will be start."); + tAI = std::thread(AIThread); if (tAI.joinable()) { logger->info("Join the AI thread!"); @@ -516,7 +525,7 @@ void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port, bool f } else { - logger->error("Connect to the server failed, AI thread will not be start."); + logger->error("Connect to the server failed, AI thread will not be started."); return; } } diff --git a/CAPI/API/src/main.cpp b/CAPI/API/src/main.cpp index 41bb9ae..a985d58 100644 --- a/CAPI/API/src/main.cpp +++ b/CAPI/API/src/main.cpp @@ -20,7 +20,7 @@ int THUAI6Main(int argc, char** argv, CreateAIFunc AIBuilder) extern const THUAI6::HumanType humanType; // 仅供早期调试使用 { - file = true; + file = false; print = true; Logic logic(playerType, pID, butcherType, humanType); logic.Main(AIBuilder, sIP, sPort, file, print, warnOnly);