From 5fa43f21353ecd92c3d4c0a28adaed8119f152a7 Mon Sep 17 00:00:00 2001 From: sigureling <1678348940@qq.com> Date: Wed, 21 Feb 2024 19:39:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=9A=80=20Update=20CAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CAPI/cpp/API/include/API.h | 240 +++++++------ CAPI/cpp/API/include/Communication.h | 8 +- CAPI/cpp/API/include/logic.h | 62 ++-- CAPI/cpp/API/include/structures.h | 163 +++++---- CAPI/cpp/API/include/utils.hpp | 39 ++- CAPI/cpp/API/src/AI.cpp | 4 + CAPI/cpp/API/src/API.cpp | 58 +-- CAPI/cpp/API/src/Communication.cpp | 8 +- CAPI/cpp/API/src/DebugAPI.cpp | 506 ++++++++++----------------- CAPI/cpp/API/src/logic.cpp | 292 ++++++++-------- 10 files changed, 635 insertions(+), 745 deletions(-) diff --git a/CAPI/cpp/API/include/API.h b/CAPI/cpp/API/include/API.h index 65a2c99c..f300ce4a 100755 --- a/CAPI/cpp/API/include/API.h +++ b/CAPI/cpp/API/include/API.h @@ -72,7 +72,7 @@ class ILogic // Team使用的部分 virtual bool Recycle(int64_t playerID) = 0; virtual bool InstallModule(int64_t playerID, THUAI7::ModuleType moduleType) = 0; - virtual bool BuildShip(THUAI7::ShipType shipType, int32_t playerID, int32_t cellX, int32_t cellY) = 0; + virtual bool BuildShip(THUAI7::ShipType shipType,int32_t cellX, int32_t cellY) = 0; }; class IAPI @@ -81,8 +81,8 @@ class IAPI // 选手可执行的操作,应当保证所有函数的返回值都应当为std::future,例如下面的移动函数: // 指挥本角色进行移动,`timeInMilliseconds` 为移动时间,单位为毫秒;`angleInRadian` 表示移动的方向,单位是弧度,使用极坐标——竖直向下方向为 x 轴,水平向右方向为 y 轴 // 发送信息、接受信息,注意收消息时无消息则返回nullopt - virtual std::future SendTextMessage(int64_t toPlayerID, int64_t, std::string) = 0; - virtual std::future SendBinaryMessage(int64_t toPlayerID, int64_t, std::string) = 0; + virtual std::future SendTextMessage(int64_t toPlayerID, std::string) = 0; + virtual std::future SendBinaryMessage(int64_t toPlayerID, std::string) = 0; [[nodiscard]] virtual bool HaveMessage() = 0; [[nodiscard]] virtual std::pair GetMessage() = 0; @@ -95,11 +95,12 @@ class IAPI [[nodiscard]] virtual std::vector> GetEnemyShips() const = 0; [[nodiscard]] virtual std::vector> GetBullets() const = 0; [[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 int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const = 0; - [[nodiscard]] virtual int32_t GetWormHp(int32_t cellX, int32_t cellY) = 0; - [[nodiscard]] virtual int32_t GetResourceState(int32_t cellX, int32_t cellY) = 0; - [[nodiscard]] virtual int32_t GetHomeHp() = 0; + [[nodiscard]] virtual int32_t GetWormHp(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; [[nodiscard]] virtual int32_t GetMoney() const = 0; [[nodiscard]] virtual int32_t GetScore() const = 0; [[nodiscard]] virtual std::vector GetPlayerGUIDs() const = 0; @@ -140,8 +141,8 @@ class IShipAPI : public IAPI virtual std::future Produce() = 0; virtual std::future ReBuild(THUAI7::ConstructionType constructionType) = 0; virtual std::future Construct(THUAI7::ConstructionType constructionType) = 0; - [[nodiscard]] virtual std::shared_ptr GetSelfInfo() const = 0; - [[nodiscard]] virtual bool HaveView(int32_t gridX, int32_t gridY) const = 0; + virtual std::shared_ptr GetSelfInfo() const = 0; + virtual bool HaveView(int32_t gridX, int32_t gridY) const = 0; }; class ITeamAPI : public IAPI @@ -150,7 +151,7 @@ class ITeamAPI : public IAPI [[nodiscard]] virtual std::shared_ptr GetSelfInfo() const = 0; virtual std::future InstallModule(int64_t playerID, THUAI7::ModuleType moduletype) = 0; virtual std::future Recycle(int64_t playerID) = 0; - virtual std::future BuildShip(THUAI7::ShipType shipType, int64_t playerID, int32_t cellX, int32_t cellY) = 0; + virtual std::future BuildShip(THUAI7::ShipType shipType,int32_t cellX, int32_t cellY) = 0; }; class IGameTimer @@ -182,7 +183,7 @@ class ShipAPI : public IShipAPI, public IGameTimer [[nodiscard]] std::pair GetMessage() override; [[nodiscard]] int32_t GetFrameCount() const override; - std::future Wait() override; + bool Wait() override; std::future EndAllAction() override; std::future Move(int64_t timeInMilliseconds, double angleInRadian) override; @@ -208,9 +209,9 @@ class ShipAPI : public IShipAPI, public IGameTimer [[nodiscard]] std::shared_ptr GetGameInfo() const override; [[nodiscard]] std::vector GetPlayerGUIDs() const override; [[nodiscard]] std::shared_ptr GetSelfInfo() const override; - [[nodiscard]] std::future HaveView(int32_t gridX, int32_t gridY) const override; - [[nodiscard]] int32_t GetMoney() override; - [[nodiscard]] int32_t GetScore() override; + [[nodiscard]] bool HaveView(int32_t gridX, int32_t gridY) const override; + [[nodiscard]] int32_t GetMoney() const override; + [[nodiscard]] int32_t GetScore() const override; void Print(std::string str) const override { @@ -246,7 +247,7 @@ class TeamAPI : public ITeamAPI, public IGameTimer [[nodiscard]] std::pair GetMessage() override; [[nodiscard]] int32_t GetFrameCount() const override; - std::future Wait() override; + bool Wait() override; std::future EndAllAction() override; [[nodiscard]] std::vector> GetShips() const override; @@ -266,7 +267,7 @@ class TeamAPI : public ITeamAPI, public IGameTimer [[nodiscard]] int32_t GetMoney() const override; std::future InstallModule(int64_t playerID, THUAI7::ModuleType moduleType) override; std::future Recycle(int64_t playerID) override; - std::future BuildShip(THUAI7::ShipType shipType, int64_t playerID, int32_t cellX, int32_t cellY) override; + std::future BuildShip(THUAI7::ShipType shipType,int32_t cellX, int32_t cellY) override; void Print(std::string str) const override { @@ -277,101 +278,120 @@ class TeamAPI : public ITeamAPI, public IGameTimer void PrintSelfInfo() const override { } + +private: + ILogic& logic; }; -// class ShipDebugAPI : public IShipAPI, public IGameTimer -// { -// ShipDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t shipID); -// void StartTimer() override -// { -// } -// void EndTimer() override -// { -// } -// void Play(IAI& ai) override; -// [[nodiscard]] int32_t GetFrameCount() const override; - -// std::future Move(int64_t timeInMilliseconds, double angleInRadian) override; -// std::future MoveRight(int64_t timeInMilliseconds) override; -// std::future MoveUp(int64_t timeInMilliseconds) override; -// std::future MoveLeft(int64_t timeInMilliseconds) override; -// std::future MoveDown(int64_t timeInMilliseconds) override; -// virtual bool InstallModule(const THUAI7::ModuleType type, const THUAI7::ModuleLevel level) override; -// std::future Attack(double angleInRadian) override; -// std::future EndAllAction() override; - -// std::future SendTextMessage(int64_t, std::string) override; -// std::future SendBinaryMessage(int64_t, std::string) override; -// [[nodiscard]] bool HaveMessage() override; -// [[nodiscard]] std::pair GetMessage() override; - -// bool Wait() override; - -// [[nodiscard]] virtual std::vector> GetShips() const override; -// [[nodiscard]] virtual std::vector> GetEnemyShip() const override; -// [[nodiscard]] std::vector> GetBullets() const override; -// [[nodiscard]] virtual std::vector> GetFullMap() const override; -// [[nodiscard]] virtual THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override; -// [[nodiscard]] virtual int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const override; - -// [[nodiscard]] virtual std::shared_ptr GetGameInfo() const override; - -// [[nodiscard]] virtual std::vector GetShipGUIDs() const override; -// [[nodiscard]] virtual std::shared_ptr GetSelfInfo() const override; - -// [[nodiscard]] bool HaveView(int32_t gridX, int32_t gridY) const override; - -// void Print(std::string str) const override -// { -// } -// void PrintShip() const override -// { -// } -// void PrintSelfInfo() const override -// { -// } - -// private: -// std::chrono::system_clock::time_point startPoint; -// std::unique_ptr logger; -// ILogic& logic; -// }; - -// class TeamDebugAPI : public ITeamAPI, public IGameTimer -// { -// TeamDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t TeamID); -// void StartTimer() override -// { -// } -// void EndTimer() override -// { -// } -// void Play(IAI& ai) override; -// [[nodiscard]] int32_t GetFrameCount() const override; -// [[nodiscard]] virtual std::vector> GetShips() const override; -// [[nodiscard]] virtual std::vector> GetEnemyShip() const override; -// [[nodiscard]] virtual int32_t GetEconomy() const override; -// [[nodiscard]] virtual std::vector> GetFullMap() const override; -// [[nodiscard]] virtual THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override; -// [[nodiscard]] virtual int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const override; -// [[nodiscard]] virtual std::shared_ptr GetGameInfo() const override; -// [[nodiscard]] virtual std::shared_ptr GetSelfInfo() const override; -// [[nodiscard]] bool HaveView(int32_t gridX, int32_t gridY) const override; -// virtual bool SendMessage(int64_t toID, std::string message, bool binary) override; -// virtual bool HaveMessage() override; -// virtual std::pair GetMessage() override; -// bool Wait() override; -// void Print(std::string str) const override -// { -// } -// void PrintSelfInfo() const override -// { -// } - -// private: -// std::chrono::system_clock::time_point startPoint; -// std::unique_ptr logger; -// ILogic& logic; -// }; + class ShipDebugAPI : public IShipAPI, public IGameTimer + { + ShipDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t shipID); + void StartTimer() override + { + } + void EndTimer() override + { + } + void Play(IAI& ai) override; + std::future SendTextMessage(int64_t, std::string) override; + std::future SendBinaryMessage(int64_t, std::string) override; + [[nodiscard]] bool HaveMessage() override; + [[nodiscard]] std::pair GetMessage() override; + bool Wait() override; + [[nodiscard]] int32_t GetFrameCount() const override; + std::future EndAllAction() override; + + std::future Move(int64_t timeInMilliseconds, double angleInRadian) override; + std::future MoveRight(int64_t timeInMilliseconds) override; + std::future MoveUp(int64_t timeInMilliseconds) override; + std::future MoveLeft(int64_t timeInMilliseconds) override; + std::future MoveDown(int64_t timeInMilliseconds) override; + std::future Attack(double angleInRadian) override; + std::future Recover() override; + std::future Produce() override; + std::future ReBuild(THUAI7::ConstructionType constructionType) override; + std::future Construct(THUAI7::ConstructionType constructionType) override; -#endif + [[nodiscard]] std::vector> GetShips() const override; + [[nodiscard]] std::vector> GetEnemyShips() const override; + [[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]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const override; + [[nodiscard]] int32_t GetWormHp(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; + [[nodiscard]] std::shared_ptr GetGameInfo() const override; + [[nodiscard]] std::vector GetPlayerGUIDs() const override; + [[nodiscard]] std::shared_ptr GetSelfInfo() const override; + [[nodiscard]] bool HaveView(int32_t gridX, int32_t gridY) const override; + [[nodiscard]] int32_t GetMoney() const override; + [[nodiscard]] int32_t GetScore() const override; + + void Print(std::string str) const override + { + } + void PrintShip() const override + { + } + void PrintSelfInfo() const override + { + } + + private: + std::chrono::system_clock::time_point startPoint; + std::unique_ptr logger; + ILogic& logic; + }; + + class TeamDebugAPI : public ITeamAPI, public IGameTimer + { + TeamDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t TeamID); + void StartTimer() override + { + } + void EndTimer() override + { + } + void Play(IAI& ai) override; + + std::future SendTextMessage(int64_t, std::string) override; + std::future SendBinaryMessage(int64_t, std::string) override; + [[nodiscard]] bool HaveMessage() override; + [[nodiscard]] std::pair GetMessage() override; + + [[nodiscard]] int32_t GetFrameCount() const override; + bool Wait() override; + std::future EndAllAction() override; + + [[nodiscard]] std::vector> GetShips() const override; + [[nodiscard]] std::vector> GetEnemyShips() const override; + [[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]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const override; + [[nodiscard]] int32_t GetWormHp(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; + [[nodiscard]] std::shared_ptr GetGameInfo() const override; + [[nodiscard]] std::vector GetPlayerGUIDs() const override; + [[nodiscard]] std::shared_ptr GetSelfInfo() const override; + + [[nodiscard]] int32_t GetScore() const override; + [[nodiscard]] int32_t GetMoney() const override; + std::future InstallModule(int64_t playerID, THUAI7::ModuleType moduleType) override; + std::future Recycle(int64_t playerID) override; + std::future BuildShip(THUAI7::ShipType shipType,int32_t cellX, int32_t cellY) override; + void Print(std::string str) const override + { + } + void PrintSelfInfo() const override + { + } + private: + std::chrono::system_clock::time_point startPoint; + std::unique_ptr logger; + ILogic& logic; + }; + +#endif \ No newline at end of file diff --git a/CAPI/cpp/API/include/Communication.h b/CAPI/cpp/API/include/Communication.h index 3f17ed8e..10f0dbee 100755 --- a/CAPI/cpp/API/include/Communication.h +++ b/CAPI/cpp/API/include/Communication.h @@ -38,10 +38,10 @@ class Communication bool Rebuild(int64_t playerID, int64_t teamID, THUAI7::ConstructionType constructionType); bool Construct(int64_t playerID, int64_t teamID, THUAI7::ConstructionType constructionType); bool Attack(int64_t playerID, int64_t teamID, double angle); - bool Send(int64_t playerID, int64_t toPlayerID, int64_t teamID, std::string message, bool binary) - // Team - bool InstallModule(int64_t playerID, int64_t teamID, THUAI7::ModuleType moduleType); - bool BuildShip(THUAI7::ShipType shipType, int32_t x, int32_t y); + bool Send(int64_t playerID, int64_t toPlayerID, int64_t teamID, std::string message, bool binary); + // Team + bool InstallModule(int64_t playerID, int64_t teamID, THUAI7::ModuleType moduleType); + bool BuildShip(int64_t teamID,THUAI7::ShipType shipType, int32_t x, int32_t y); bool Recycle(int64_t playerID, int64_t teamID); private: diff --git a/CAPI/cpp/API/include/logic.h b/CAPI/cpp/API/include/logic.h index 53ae2df7..d2fcab82 100755 --- a/CAPI/cpp/API/include/logic.h +++ b/CAPI/cpp/API/include/logic.h @@ -90,43 +90,43 @@ class Logic : public ILogic // 提供给API使用的函数 - [[nodiscard]] virtual std::vector> GetShips() const = 0; - [[nodiscard]] virtual std::vector> GetEnemyShips() const = 0; - [[nodiscard]] virtual std::vector> GetBullets() const = 0; - [[nodiscard]] virtual std::shared_ptr ShipGetSelfInfo() const = 0; - [[nodiscard]] virtual std::shared_ptr TeamGetSelfInfo() const = 0; - [[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::vector GetPlayerGUIDs() const = 0; - [[nodiscard]] virtual int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const = 0; - [[nodiscard]] virtual int32_t GetWormHp(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; - [[nodiscard]] virtual int32_t GetMoney() const = 0; - [[nodiscard]] virtual int32_t GetScore() const = 0; + [[nodiscard]] std::vector> GetShips() const; + [[nodiscard]] std::vector> GetEnemyShips() const; + [[nodiscard]] std::vector> GetBullets() const; + [[nodiscard]] std::shared_ptr ShipGetSelfInfo() const; + [[nodiscard]] std::shared_ptr TeamGetSelfInfo() const; + [[nodiscard]] std::vector> GetFullMap() const; + [[nodiscard]] std::shared_ptr GetGameInfo() const; + [[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const; + [[nodiscard]] std::vector GetPlayerGUIDs() const; + [[nodiscard]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const; + [[nodiscard]] int32_t GetWormHp(int32_t cellX, int32_t cellY) const; + [[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const; + [[nodiscard]] int32_t GetHomeHp() const; + [[nodiscard]] int32_t GetMoney() const; + [[nodiscard]] int32_t GetScore() const; // 供IAPI使用的操作相关的部分 - virtual bool Send(int64_t toPlayerID, std::string message, bool binary) = 0; - virtual bool HaveMessage() = 0; - virtual std::pair GetMessage() = 0; - virtual bool WaitThread() = 0; - virtual int32_t GetCounter() const = 0; - virtual bool EndAllAction() = 0; + bool Send(int64_t toPlayerID, std::string message, bool binary); + bool HaveMessage(); + std::pair GetMessage(); + bool WaitThread(); + int32_t GetCounter() const; + bool EndAllAction(); // IShipAPI使用的部分 - virtual bool Move(int64_t time, double angle) = 0; - virtual bool Recover() = 0; - virtual bool Produce() = 0; - virtual bool ReBuild(THUAI7::ConstructionType constructionType) = 0; - virtual bool Construct(THUAI7::ConstructionType constructionType) = 0; - virtual bool Attack(double angle) = 0; - [[nodiscard]] virtual bool HaveView(int32_t gridX, int32_t gridY, int32_t selfX, int32_t selfY, int32_t viewRange) const = 0; + bool Move(int64_t time, double angle); + bool Recover(); + bool Produce(); + bool ReBuild(THUAI7::ConstructionType constructionType); + bool Construct(THUAI7::ConstructionType constructionType); + bool Attack(double angle); + [[nodiscard]] bool HaveView(int32_t gridX, int32_t gridY, int32_t selfX, int32_t selfY, int32_t viewRange) const; // ITeamAPI - virtual bool Recycle(int64_t playerID) = 0; - virtual bool InstallModule(int64_t playerID, THUAI7::ModuleType moduleType) = 0; - virtual bool BuildShip(THUAI7::ShipType shipType, int32_t playerID, int32_t cellX, int32_t cellY) = 0; + bool Recycle(int64_t playerID); + bool InstallModule(int64_t playerID, THUAI7::ModuleType moduleType); + bool BuildShip(THUAI7::ShipType shipType,int32_t cellX, int32_t cellY); bool TryConnection(); void ProcessMessage(); diff --git a/CAPI/cpp/API/include/structures.h b/CAPI/cpp/API/include/structures.h index 9dd5aa85..62359df5 100755 --- a/CAPI/cpp/API/include/structures.h +++ b/CAPI/cpp/API/include/structures.h @@ -35,7 +35,7 @@ namespace THUAI7 Shadow = 4, Asteroid = 5, Resource = 6, - Building = 7, + Construction = 7, Wormhole = 8, }; @@ -54,6 +54,19 @@ namespace THUAI7 Blue = 2, }; + inline std::map playerTeamDict{ + {PlayerTeam::NullTeam, 0}, + {PlayerTeam::Red, 1}, + {PlayerTeam::Blue, 2}, + }; + + enum class PlayerType : unsigned char + { + NullPlayerType = 0, + Ship = 1, + Team = 2, + }; + enum class ShipType : unsigned char { NullShipType = 0, @@ -197,10 +210,10 @@ namespace THUAI7 ShipType shipType; int32_t viewRange; ProducerType producerType; - ConstructorType constructor_type; - ArmorType armor_type; - ShieldType shield_type; - WeaponType weapon_type; + ConstructorType constructorType; + ArmorType armorType; + ShieldType shieldType; + WeaponType weaponType; double facingDirection; // 朝向 }; @@ -231,6 +244,7 @@ namespace THUAI7 BulletType bulletType; // 子弹类型 int32_t damage; // 伤害值 int32_t attackRange; + int32_t bombRange; double explodeRange; // 炸弹爆炸范围 int32_t speed; // 子弹速度 }; @@ -247,6 +261,7 @@ namespace THUAI7 struct GameMap { + //x,y,id,hp std::map, std::pair> factoryState; std::map, std::pair> communityState; std::map, std::pair> fortState; @@ -269,77 +284,73 @@ namespace THUAI7 // 仅供DEBUG使用,名称可改动 // 还没写完,后面待续 - // inline std::map gameStateDict{ - // {GameState::NullGameState, "NullGameState"}, - // {GameState::GameStart, "GameStart"}, - // {GameState::GameRunning, "GameRunning"}, - // {GameState::GameEnd, "GameEnd"}, - // }; - - // inline std::map shipTypeDict{ - // {ShipType::NullShipType, "NullShipType"}, - // {ShipType::CivilianShip, "CivilianShip"}, - // {ShipType::MilitaryShip, "MilitaryShip"}, - // {ShipType::FlagShip, "FlagShip"}, - // }; - - // inline std::map shipStateDict{ - // {ShipState::NullStatus, "NullState"}, - // {ShipState::Idle, "Idle"}, - // {ShipState::Producing, "Producing"}, - // {ShipState::Constructing, "Constructing"}, - // {ShipState::Recovering, "Recoverying"}, - // {ShipState::Recycling, "Recycling"}, - // {ShipState::Attacking, "Attacking"}, - // {ShipState::Swinging, "Swinging"}, - // {ShipState::Stunned, "Stunned"}, - // }; - - // inline std::map playerTeamDict{ - // {PlayerTeam::NullTeam, "NullTeam"}, - // {PlayerTeam::Up, "Up"}, - // {PlayerTeam::Down, "Down"}, - // }; - - // inline std::map placeTypeDict{ - // {PlaceType::NullPlaceType, "NullPlaceType"}, - // {PlaceType::Home, "Home"}, - // {PlaceType::Space, "Space"}, - // {PlaceType::Ruin, "Ruin"}, - // {PlaceType::Shadow, "Shadow"}, - // {PlaceType::Asteroid, "Asteroid"}, - // {PlaceType::Resource, "Resource"}, - // {PlaceType::Building, "Building"}, - // }; - - // inline std::map bulletTypeDict{ - // {BulletType::NullBulletType, "NullBulletType"}, - // {BulletType::Laser, "Laser"}, - // {BulletType::Plasma, "Plasma"}, - // {BulletType::Shell, "Shell"}, - // {BulletType::Missile, "Missile"}, - // {BulletType::ElectricArc, "ElectricArc"}, - // }; - - // inline std::map messageOfObjDict{ - // {MessageOfObj::NullMessageOfObj, "NullMessageOfObj"}, - // {MessageOfObj::ShipMessage, "ShipMessage"}, - // {MessageOfObj::BuildingMessage, "BuildingMessage"}, - // {MessageOfObj::BulletMessage, "BulletMessage"}, - // {MessageOfObj::ResourceMessage, "ResourceMessage"}, - // {MessageOfObj::HomeMessage, "HomeMessage"}, - // {MessageOfObj::MapMessage, "MapMessage"}, - // }; - // enum class MessageOfObj : unsigned char - // { - // NullMessageOfObj = 0, - // ShipMessage = 1, - // BuildingMessage = 2, - // BulletMessage = 3, - // ResourceMessage = 4, - // HomeMessage = 5, - // MapMessage = 6, - // }; + inline std::map gameStateDict{ + {GameState::NullGameState, "NullGameState"}, + {GameState::GameStart, "GameStart"}, + {GameState::GameRunning, "GameRunning"}, + {GameState::GameEnd, "GameEnd"}, + }; + + inline std::map shipTypeDict{ + {ShipType::NullShipType, "NullShipType"}, + {ShipType::CivilianShip, "CivilianShip"}, + {ShipType::MilitaryShip, "MilitaryShip"}, + {ShipType::FlagShip, "FlagShip"}, + }; + + inline std::map shipStateDict{ + {ShipState::NullStatus, "NullState"}, + {ShipState::Idle, "Idle"}, + {ShipState::Producing, "Producing"}, + {ShipState::Constructing, "Constructing"}, + {ShipState::Recovering, "Recoverying"}, + {ShipState::Recycling, "Recycling"}, + {ShipState::Attacking, "Attacking"}, + {ShipState::Swinging, "Swinging"}, + {ShipState::Stunned, "Stunned"}, + }; + + inline std::map playerTeamDict{ + {PlayerTeam::NullTeam, "NullTeam"}, + {PlayerTeam::Red, "Red"}, + {PlayerTeam::Blue, "Blue"}, + }; + + inline std::map placeTypeDict{ + {PlaceType::NullPlaceType, "NullPlaceType"}, + {PlaceType::Home, "Home"}, + {PlaceType::Space, "Space"}, + {PlaceType::Ruin, "Ruin"}, + {PlaceType::Shadow, "Shadow"}, + {PlaceType::Asteroid, "Asteroid"}, + {PlaceType::Resource, "Resource"}, + {PlaceType::Construction, "Construction"}, + }; + + inline std::map bulletTypeDict{ + {BulletType::NullBulletType, "NullBulletType"}, + {BulletType::Laser, "Laser"}, + {BulletType::Plasma, "Plasma"}, + {BulletType::Shell, "Shell"}, + {BulletType::Missile, "Missile"}, + {BulletType::Arc, "Arc"}, + }; + + inline std::map messageOfObjDict{ + {MessageOfObj::NullMessageOfObj, "NullMessageOfObj"}, + {MessageOfObj::ShipMessage, "ShipMessage"}, + {MessageOfObj::BulletMessage, "BulletMessage"}, + {MessageOfObj::FactoryMessage, "FactoryMessage"}, + {MessageOfObj::CommunityMessage, "CommunityMessage"}, + {MessageOfObj::FortMessage, "FortMessage"}, + {MessageOfObj::WormholeMessage, "WormholeMessage"}, + {MessageOfObj::HomeMessage, "HomeMessage"}, + {MessageOfObj::ResourceMessage, "ResourceMessage"}, + {MessageOfObj::MapMessage, "MapMessage"}, + {MessageOfObj::NewsMessage, "NewsMessage"}, + {MessageOfObj::BombedBulletMessage, "BombedBulletMessage"}, + {MessageOfObj::TeamMessage, "TeamMessage"}, + }; } // namespace THUAI7 #endif diff --git a/CAPI/cpp/API/include/utils.hpp b/CAPI/cpp/API/include/utils.hpp index b901bc99..15c09213 100755 --- a/CAPI/cpp/API/include/utils.hpp +++ b/CAPI/cpp/API/include/utils.hpp @@ -39,7 +39,7 @@ namespace AssistFunction double distance = deltaX * deltaX + deltaY * deltaY; THUAI7::PlaceType myPlace = map[GridToCell(x)][GridToCell(y)]; THUAI7::PlaceType newPlace = map[GridToCell(newX)][GridToCell(newY)]; - if (newPlace == THUAI7::PlaceType::Shadow && myPlace != THUAI6::PlaceType::Shadow) + if (newPlace == THUAI7::PlaceType::Shadow && myPlace != THUAI7::PlaceType::Shadow) return false; int32_t divide = std::max(std::abs(deltaX), std::abs(deltaY)) / 100; if (divide == 0) @@ -61,7 +61,7 @@ namespace AssistFunction { myX += dx; myY += dy; - if (map[GridToCell(myX)][GridToCell(myY)] == THUAI6::PlaceType::Ruin) + if (map[GridToCell(myX)][GridToCell(myY)] == THUAI7::PlaceType::Ruin) return false; } return true; @@ -111,7 +111,7 @@ namespace Proto2THUAI7 }; inline std::map shipStateDict{ - {protobuf::ShipState::NULL_SHIP_STATE, THUAI7::ShipState::NullShipState}, + {protobuf::ShipState::NULL_STATUS, THUAI7::ShipState::NullStatus}, {protobuf::ShipState::IDLE, THUAI7::ShipState::Idle}, {protobuf::ShipState::PRODUCING, THUAI7::ShipState::Producing}, {protobuf::ShipState::CONSTRUCTING, THUAI7::ShipState::Constructing}, @@ -119,8 +119,8 @@ namespace Proto2THUAI7 {protobuf::ShipState::RECYCLING, THUAI7::ShipState::Recycling}, {protobuf::ShipState::ATTACKING, THUAI7::ShipState::Attacking}, {protobuf::ShipState::SWINGING, THUAI7::ShipState::Swinging}, - {protobuf::ShipState::STUUNED, THUAI7::ShipState::Stuuned}, - {protobuff::ShipState::MOVING, THUAI7::ShipState::Moving}, + {protobuf::ShipState::STUNNED, THUAI7::ShipState::Stunned}, + {protobuf::ShipState::MOVING, THUAI7::ShipState::Moving}, }; inline std::map weaponTypeDict{ @@ -252,7 +252,7 @@ namespace Proto2THUAI7 inline std::shared_ptr Protobuf2THUAI7Bullet(const protobuf::MessageOfBullet& bulletMsg) { auto bullet = std::make_shared(); - bullet->bulletType = bulletTypeDict[bulletMsg.bullet_type()]; + bullet->bulletType = bulletTypeDict[bulletMsg.type()]; bullet->x = bulletMsg.x(); bullet->y = bulletMsg.y(); bullet->facingDirection = bulletMsg.facing_direction(); @@ -281,19 +281,18 @@ namespace Proto2THUAI7 team->teamID = teamMsg.team_id(); team->score = teamMsg.score(); team->money = teamMsg.money(); - return team + return team; } inline std::shared_ptr Protobuf2THUAI7GameInfo(const protobuf::MessageOfAll& allMsg) { auto gameInfo = std::make_shared(); gameInfo->gameTime = allMsg.game_time(); - gameInfo->redTeamScore = allMsg.red_team_score(); - gameInfo->blueTeamScore = allMsg.blue_team_score(); + gameInfo->redScore = allMsg.red_team_score(); + gameInfo->blueScore = allMsg.blue_team_score(); } - } // namespace Proto2THUAI7 -// 辅助函数,用于将proto信息转换为THUAI6信息 +// 辅助函数,用于将proto信息转换为THUAI7信息 namespace THUAI72Proto { // 用于将THUAI7的枚举转换为Protobuf的枚举 @@ -336,7 +335,7 @@ namespace THUAI72Proto }; inline std::map shipStateDict{ - {THUAI7::ShipState::NullShipState, protobuf::ShipState::NULL_SHIP_STATE}, + {THUAI7::ShipState::NullStatus, protobuf::ShipState::NULL_STATUS}, {THUAI7::ShipState::Idle, protobuf::ShipState::IDLE}, {THUAI7::ShipState::Producing, protobuf::ShipState::PRODUCING}, {THUAI7::ShipState::Constructing, protobuf::ShipState::CONSTRUCTING}, @@ -344,7 +343,7 @@ namespace THUAI72Proto {THUAI7::ShipState::Recycling, protobuf::ShipState::RECYCLING}, {THUAI7::ShipState::Attacking, protobuf::ShipState::ATTACKING}, {THUAI7::ShipState::Swinging, protobuf::ShipState::SWINGING}, - {THUAI7::ShipState::Stuuned, protobuf::ShipState::STUUNED}, + {THUAI7::ShipState::Stunned, protobuf::ShipState::STUNNED}, {THUAI7::ShipState::Moving, protobuf::ShipState::MOVING}, }; @@ -472,7 +471,7 @@ namespace THUAI72Proto protobuf::ConstructMsg constructMsg; constructMsg.set_player_id(playerID); constructMsg.set_team_id(teamID); - constructMsg.set_construction_type(THUAI72Proto::constructionTypeDict[constructorType]); + constructMsg.set_construction_type(THUAI72Proto::constructionTypeDict[constructionType]); return constructMsg; } @@ -501,7 +500,7 @@ namespace THUAI72Proto inline protobuf::InstallMsg THUAI72ProtobufInstallMsg(int64_t playerID, int64_t teamID, THUAI7::ModuleType moduleType) { protobuf::InstallMsg installMsg; - installMsg.set_module_type(moduleType); + installMsg.set_module_type(THUAI72Proto::moduleTypeDict[moduleType]); installMsg.set_player_id(playerID); installMsg.set_team_id(teamID); return installMsg; @@ -530,5 +529,13 @@ namespace THUAI72Proto // 用于将THUAI7的类转换为Protobuf的类 } // namespace THUAI72Proto - +namespace Time +{ + inline double TimeSinceStart(const std::chrono::system_clock::time_point& sp) + { + std::chrono::system_clock::time_point tp = std::chrono::system_clock::now(); + std::chrono::duration time_span = std::chrono::duration_cast>(tp - sp); + return time_span.count(); + } +} // namespace Time #endif \ No newline at end of file diff --git a/CAPI/cpp/API/src/AI.cpp b/CAPI/cpp/API/src/AI.cpp index 9ba00a8b..ff92a472 100755 --- a/CAPI/cpp/API/src/AI.cpp +++ b/CAPI/cpp/API/src/AI.cpp @@ -21,6 +21,10 @@ extern const std::array shipTypeDict = { void AI::play(IShipAPI& api) { + if (this->playerID == 0) + { + + } else if (this->playerID == 1) { // 玩家1执行操作 diff --git a/CAPI/cpp/API/src/API.cpp b/CAPI/cpp/API/src/API.cpp index 9ab63c9d..cd5016f3 100755 --- a/CAPI/cpp/API/src/API.cpp +++ b/CAPI/cpp/API/src/API.cpp @@ -11,25 +11,25 @@ std::future ShipAPI::SendTextMessage(int64_t toID, std::string message) { return std::async(std::launch::async, [=, message = std::move(message)]() - { return logic.SendMessage(toID, std::move(message), false); }); + { return logic.Send(toID, std::move(message), false); }); } std::future TeamAPI::SendTextMessage(int64_t toID, std::string message) { return std::async(std::launch::async, [=, message = std::move(message)]() - { return logic.SendMessage(toID, std::move(message), false); }); + { return logic.Send(toID, std::move(message), false); }); } std::future ShipAPI::SendBinaryMessage(int64_t toID, std::string message) { return std::async(std::launch::async, [=, message = std::move(message)]() - { return logic.SendMessage(toID, std::move(message), false); }); + { return logic.Send(toID, std::move(message), true); }); } std::future TeamAPI::SendBinaryMessage(int64_t toID, std::string message) { return std::async(std::launch::async, [=, message = std::move(message)]() - { return logic.SendMessage(toID, std::move(message), false); }); + { return logic.Send(toID, std::move(message), true); }); } bool ShipAPI::HaveMessage() @@ -90,12 +90,12 @@ std::future TeamAPI::EndAllAction() { return logic.EndAllAction(); }); } -std::vector> ShipAPI::GetShips() +std::vector> ShipAPI::GetShips() const { return logic.GetShips(); } -std::vector> TeamAPI::GetShips() +std::vector> TeamAPI::GetShips() const { return logic.GetShips(); } @@ -135,47 +135,47 @@ THUAI7::PlaceType ShipAPI::GetPlaceType(int32_t cellX, int32_t cellY) const return logic.GetPlaceType(cellX, cellY); } -THUIAI7::PlaceType TeamAPI::GetPlaceType(int32_t cellX, int32_t cellY) const +THUAI7::PlaceType TeamAPI::GetPlaceType(int32_t cellX, int32_t cellY) const { return logic.GetPlaceType(cellX, cellY); } -int32_t ShipAPI::GetConstructionHp(int32_t cellX, int32_t cellY) +int32_t ShipAPI::GetConstructionHp(int32_t cellX, int32_t cellY) const { - return logic.GetConstructionHp(int32_t cellX, int32_t cellY); + return logic.GetConstructionHp(cellX, cellY); } -int32_t TeamAPI::GetConstructionHp(int32_t cellX, int32_t cellY) +int32_t TeamAPI::GetConstructionHp(int32_t cellX, int32_t cellY) const { - return logic.GetConstructionHp(int32_t cellX, int32_t cellY); + return logic.GetConstructionHp( cellX, cellY); } -int32_t ShipAPI::GetWormHp(int32_t cellX, int32_t cellY) +int32_t ShipAPI::GetWormHp(int32_t cellX, int32_t cellY) const { - return logic.GetWormHp(int32_t cellX, int32_t cellY); + return logic.GetWormHp(cellX, cellY); } -int32_t TeamAPI::GetWormHp(int32_t cellX, int32_t cellY) +int32_t TeamAPI::GetWormHp(int32_t cellX, int32_t cellY) const { - return logic.GetWormHp(int32_t cellX, int32_t cellY); + return logic.GetWormHp(cellX, cellY); } -int32_t ShipAPI::GetResourceState(int32_t cellX, int32_t cellY) +int32_t ShipAPI::GetResourceState(int32_t cellX, int32_t cellY) const { - return logic.GetResourceState(int32_t cellX, int32_t cellY); + return logic.GetResourceState(cellX, cellY); } -int32_t TeamAPI::GetResourceState(int32_t cellX, int32_t cellY) +int32_t TeamAPI::GetResourceState(int32_t cellX, int32_t cellY) const { - return logic.GetResourceState(int32_t cellX, int32_t cellY); + return logic.GetResourceState(cellX, cellY); } -int32_t ShipAPI::GetHomeHp() +int32_t ShipAPI::GetHomeHp() const { return logic.GetHomeHp(); } -int32_t TeamAPI::GetHomeHp() +int32_t TeamAPI::GetHomeHp() const { return logic.GetHomeHp(); } @@ -190,22 +190,22 @@ std::shared_ptr TeamAPI::GetGameInfo() const return logic.GetGameInfo(); } -std::vector ShipAPI::GetPlayerGUIDs() +std::vector ShipAPI::GetPlayerGUIDs() const { return logic.GetPlayerGUIDs(); } -std::vector TeamAPI::GetPlayerGUIDs() +std::vector TeamAPI::GetPlayerGUIDs() const { return logic.GetPlayerGUIDs(); } -std::shared_ptr ShipAPI::GetSelfInfo() +std::shared_ptr ShipAPI::GetSelfInfo() const { return logic.ShipGetSelfInfo(); } -std::shared_ptr TeamAPI::GetSelfInfo() +std::shared_ptr TeamAPI::GetSelfInfo() const { return logic.TeamGetSelfInfo(); } @@ -275,22 +275,22 @@ std::future ShipAPI::Produce() { return logic.Produce(); }); } -std::future ShipAPI::Rebuild(THUAI7::ConstructionType constructionType) +std::future ShipAPI::ReBuild(THUAI7::ConstructionType constructionType) { return std::async(std::launch::async, [=]() - { return logic.Rebuild(ConstructionType); }); + { return logic.ReBuild(constructionType); }); } std::future ShipAPI::Construct(THUAI7::ConstructionType constructionType) { return std::async(std::launch::async, [=]() - { return logic.Construct(ConstructionType); }); + { return logic.Construct(constructionType); }); } bool ShipAPI::HaveView(int32_t gridX, int32_t gridY) const { auto selfInfo = GetSelfInfo(); - return logic.HaveView(gridX, gridY, selfInfo->x, selfInfo->y); + return logic.HaveView(gridX, gridY, selfInfo->x, selfInfo->y,selfInfo->viewRange); } // Team独有 diff --git a/CAPI/cpp/API/src/Communication.cpp b/CAPI/cpp/API/src/Communication.cpp index 3fc3bd92..47ccc078 100755 --- a/CAPI/cpp/API/src/Communication.cpp +++ b/CAPI/cpp/API/src/Communication.cpp @@ -37,7 +37,7 @@ bool Communication::Move(int64_t playerID, int64_t teamID, int64_t time, double return false; } -bool Communication::SendMessage(int64_t playerID, int64_t toPlayerID, int64_t teamID, std::string message, bool binary) +bool Communication::Send(int64_t playerID, int64_t toPlayerID, int64_t teamID, std::string message, bool binary) { { std::lock_guard lock(mtxLimit); @@ -47,8 +47,8 @@ bool Communication::SendMessage(int64_t playerID, int64_t toPlayerID, int64_t te } protobuf::BoolRes sendMessageResult; ClientContext context; - auto request = THUAI72Proto::THUAI72ProtobufSendMsg(playerID, toPlayerID, teamID, std::move(message), toID, binary); - auto status = THUAI7Stub->SendMessage(&context, request, &sendMessageResult); + auto request = THUAI72Proto::THUAI72ProtobufSendMsg(playerID, toPlayerID, teamID, std::move(message),binary); + auto status = THUAI7Stub->Send(&context, request, &sendMessageResult); if (status.ok()) return sendMessageResult.act_success(); else @@ -142,7 +142,7 @@ bool Communication::Construct(int64_t playerID, int64_t teamID, THUAI7::Construc } protobuf::BoolRes constructResult; ClientContext context; - auto request = THUAI72Proto::THUAI72ProtobufConstructMsg(int64_t playerID, int64_t teamID, THUAI7::ConstructionType constructionType); + auto request = THUAI72Proto::THUAI72ProtobufConstructMsg(playerID, teamID, constructionType); auto status = THUAI7Stub->Construct(&context, request, &constructResult); if (status.ok()) return constructResult.act_success(); diff --git a/CAPI/cpp/API/src/DebugAPI.cpp b/CAPI/cpp/API/src/DebugAPI.cpp index 1b8766fc..16549909 100755 --- a/CAPI/cpp/API/src/DebugAPI.cpp +++ b/CAPI/cpp/API/src/DebugAPI.cpp @@ -34,28 +34,6 @@ ShipDebugAPI::ShipDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, logger->flush_on(spdlog::level::warn); } -HomeDebugAPI::HomeDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t playerID) : - logic(logic) -{ - std::string fileName = "logs/api-" + std::to_string(playerID) + "-log.txt"; - auto fileLogger = std::make_shared(fileName, true); - auto printLogger = std::make_shared(); - std::string pattern = "[api" + std::to_string(playerID) + "] [%H:%M:%S.%e] [%l] %v"; - fileLogger->set_pattern(pattern); - printLogger->set_pattern(pattern); - if (file) - fileLogger->set_level(spdlog::level::trace); - else - fileLogger->set_level(spdlog::level::off); - if (print) - printLogger->set_level(spdlog::level::info); - else - printLogger->set_level(spdlog::level::off); - if (warnOnly) - printLogger->set_level(spdlog::level::warn); - logger = std::make_unique("apiLogger", spdlog::sinks_init_list{fileLogger, printLogger}); -} - void ShipDebugAPI::StartTimer() { startPoint = std::chrono::system_clock::now(); @@ -64,69 +42,21 @@ void ShipDebugAPI::StartTimer() logger->info("StartTimer: {}", std::ctime(&t)); } -void HomeDebugAPI::StartTimer() -{ - startPoint = std::chrono::system_clock::now(); - std::time_t t = std::chrono::system_clock::to_time_t(startPoint); - logger->info("=== AI.play() ==="); - logger->info("StartTimer: {}", std::ctime(&t)); -} - void ShipDebugAPI::EndTimer() { logger->info("Time elapsed: {}ms", Time::TimeSinceStart(startPoint)); } -void HomeDebugAPI::EndTimer() -{ - logger->info("Time elapsed: {}ms", Time::TimeSinceStart(startPoint)); -} - int32_t ShipDebugAPI::GetFrameCount() const { return logic.GetCounter(); } -int32_t TrickerDebugAPI::GetFrameCount() const -{ - return logic.GetCounter(); -} - -std::future ShipDebugAPI::Move(int64_t timeInMilliseconds, double angleInRadian) -{ - logger->info("Move: timeInMilliseconds = {}, angleInRadian = {}, called at {}ms", timeInMilliseconds, angleInRadian, Time::TimeSinceStart(startPoint)); - return std::async(std::launch::async, [=]() - { auto result = logic.Move(timeInMilliseconds, angleInRadian); - if (!result) - logger->warn("Move: failed at {}ms", Time::TimeSinceStart(startPoint)); - return result; }); -} - -std::future ShipDebugAPI::MoveDown(int64_t timeInMilliseconds) -{ - return Move(timeInMilliseconds, 0); -} - -std::future ShipDebugAPI::MoveRight(int64_t timeInMilliseconds) -{ - return Move(timeInMilliseconds, PI * 0.5); -} - -std::future ShipDebugAPI::MoveUp(int64_t timeInMilliseconds) -{ - return Move(timeInMilliseconds, PI); -} - -std::future ShipDebugAPI::MoveLeft(int64_t timeInMilliseconds) -{ - return Move(timeInMilliseconds, PI * 1.5); -} - std::future ShipDebugAPI::SendTextMessage(int64_t toID, std::string message) { logger->info("SendTextMessage: toID = {}, message = {}, called at {}ms", toID, message, Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [=, message = std::move(message)]() - { auto result = logic.SendMessage(toID, std::move(message), false); + { auto result = logic.Send(toID, std::move(message), false); if (!result) logger->warn("SendTextMessage: failed at {}ms", Time::TimeSinceStart(startPoint)); return result; }); @@ -136,7 +66,7 @@ std::future ShipDebugAPI::SendBinaryMessage(int64_t toID, std::string mess { logger->info("SendBinaryMessage: toID = {}, message = {}, called at {}ms", toID, message, Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [=, message = std::move(message)]() - { auto result = logic.SendMessage(toID, std::move(message), true); + { auto result = logic.Send(toID, std::move(message), true); if (!result) logger->warn("SendBinaryMessage: failed at {}ms", Time::TimeSinceStart(startPoint)); return result; }); @@ -168,62 +98,79 @@ bool ShipDebugAPI::Wait() else return logic.WaitThread(); } +std::future ShipDebugAPI::Move(int64_t timeInMilliseconds, double angleInRadian) +{ + logger->info("Move: timeInMilliseconds = {}, angleInRadian = {}, called at {}ms", timeInMilliseconds, angleInRadian, Time::TimeSinceStart(startPoint)); + return std::async(std::launch::async, [=]() + { auto result = logic.Move(timeInMilliseconds, angleInRadian); + if (!result) + logger->warn("Move: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); +} -bool HomeDebugAPI::Wait() +std::future ShipDebugAPI::MoveDown(int64_t timeInMilliseconds) { - logger->info("Wait: called at {}ms", Time::TimeSinceStart(startPoint)); - if (logic.GetCounter() == -1) - return false; - else - return logic.WaitThread(); + return Move(timeInMilliseconds, 0); } -std::future ShipDebugAPI::InstallModule(const THUAI7::ModuleType type, const THUAI7::ModuleLevel level) const +std::future ShipDebugAPI::MoveRight(int64_t timeInMilliseconds) { - logger->info("Installmodule: ModuleType:{} ModuleLevel:{}, called at {}ms", type, level, Time::TimeSinceStart(startPoint)); - return std::async(std::launch::async, [=]() - { auto result = logic.StartRouseMate(mateID); - if (!result) - logger->warn("StartRouseMate: failed at {}ms", Time::TimeSinceStart(startPoint)); - return result; }); + return Move(timeInMilliseconds, PI * 0.5); } -std::future ShipDebugAPI::Attack() const +std::future ShipDebugAPI::MoveUp(int64_t timeInMilliseconds) { - return logic.Attack(); + return Move(timeInMilliseconds, PI); } -std::vector> ShipDebugAPI::GetShips() const +std::future ShipDebugAPI::MoveLeft(int64_t timeInMilliseconds) { - return logic.GetShips(); + return Move(timeInMilliseconds, PI * 1.5); } -std::vector> TrickerDebugAPI::GetTrickers() const +std::future ShipDebugAPI::Attack(double angleInRadian) { - return logic.GetTrickers(); + logger->info("Attack: angleInRadian = {}, called at {}ms", angleInRadian, Time::TimeSinceStart(startPoint)); + return std::async(std::launch::async, [=]() + { auto result = logic.Attack(angleInRadian); + if (!result) + logger->warn("Attack: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } -std::vector> TrickerDebugAPI::GetShips() const +std::future ShipDebugAPI::Recover() { - return logic.GetShips(); + return std::async(std::launch::async, [=]() + { return logic.Recover(); }); +} +std::future ShipDebugAPI::Produce() +{ + return std::async(std::launch::async, [=]() + { return logic.Produce(); }); +} +std::future ShipDebugAPI::ReBuild(THUAI7::ConstructionType constructionType) +{ + return std::async(std::launch::async, [=]() + { return logic.ReBuild(constructionType); }); } -std::vector> ShipDebugAPI::GetProps() const +std::future ShipDebugAPI::Construct(THUAI7::ConstructionType constructionType) { - return logic.GetProps(); + return std::async(std::launch::async, [=]() + { return logic.Construct(constructionType); }); } -std::vector> TrickerDebugAPI::GetProps() const +std::vector> ShipDebugAPI::GetShips() const { - return logic.GetProps(); + return logic.GetShips(); } -std::vector> ShipDebugAPI::GetBullets() const +std::vector> ShipDebugAPI::GetEnemyShips() const { - return logic.GetBullets(); + return logic.GetEnemyShips(); } -std::vector> TrickerDebugAPI::GetBullets() const +std::vector> ShipDebugAPI::GetBullets() const { return logic.GetBullets(); } @@ -238,348 +185,249 @@ THUAI7::PlaceType ShipDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const return logic.GetPlaceType(cellX, cellY); } -THUAI7::PlaceType TrickerDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const -{ - return logic.GetPlaceType(cellX, cellY); -} - -std::vector> TrickerDebugAPI::GetFullMap() const +int32_t ShipDebugAPI::GetConstructionHp(int32_t cellX, int32_t cellY) const { - return logic.GetFullMap(); + return logic.GetConstructionHp(cellX, cellY); } -bool ShipDebugAPI::IsDoorOpen(int32_t cellX, int32_t cellY) const +int32_t ShipDebugAPI::GetWormHp(int32_t cellX, int32_t cellY) const { - return logic.IsDoorOpen(cellX, cellY); + return logic.GetWormHp(cellX, cellY); } -bool TrickerDebugAPI::IsDoorOpen(int32_t cellX, int32_t cellY) const +int32_t ShipDebugAPI::GetResourceState(int32_t cellX, int32_t cellY) const { - return logic.IsDoorOpen(cellX, cellY); + return logic.GetResourceState(cellX, cellY); } -int32_t ShipDebugAPI::GetClassroomProgress(int32_t cellX, int32_t cellY) const +int32_t ShipDebugAPI::GetHomeHp() const { - return logic.GetClassroomProgress(cellX, cellY); + return logic.GetHomeHp(); } -int32_t TrickerDebugAPI::GetClassroomProgress(int32_t cellX, int32_t cellY) const +std::shared_ptr ShipDebugAPI::GetGameInfo() const { - return logic.GetClassroomProgress(cellX, cellY); + return logic.GetGameInfo(); } -int32_t ShipDebugAPI::GetChestProgress(int32_t cellX, int32_t cellY) const +std::vector ShipDebugAPI::GetPlayerGUIDs() const { - return logic.GetChestProgress(cellX, cellY); + return logic.GetPlayerGUIDs(); } -int32_t TrickerDebugAPI::GetChestProgress(int32_t cellX, int32_t cellY) const +std::shared_ptr ShipDebugAPI::GetSelfInfo() const { - return logic.GetChestProgress(cellX, cellY); + return logic.ShipGetSelfInfo(); } -int32_t ShipDebugAPI::GetDoorProgress(int32_t cellX, int32_t cellY) const +bool ShipDebugAPI::HaveView(int32_t gridX, int32_t gridY) const { - return logic.GetDoorProgress(cellX, cellY); + auto selfInfo = GetSelfInfo(); + return logic.HaveView(gridX, gridY, selfInfo->x, selfInfo->y, selfInfo->viewRange); } -int32_t TrickerDebugAPI::GetDoorProgress(int32_t cellX, int32_t cellY) const +int32_t ShipDebugAPI::GetMoney() const { - return logic.GetDoorProgress(cellX, cellY); + return logic.GetMoney(); } -THUAI7::HiddenGateState ShipDebugAPI::GetHiddenGateState(int32_t cellX, int32_t cellY) const +int32_t ShipDebugAPI::GetScore() const { - return logic.GetHiddenGateState(cellX, cellY); + return logic.GetScore(); } -THUAI7::HiddenGateState TrickerDebugAPI::GetHiddenGateState(int32_t cellX, int32_t cellY) const +void ShipDebugAPI::Print(std::string str) const { - return logic.GetHiddenGateState(cellX, cellY); + logger->info(str); } -int32_t ShipDebugAPI::GetGateProgress(int32_t cellX, int32_t cellY) const +void ShipDebugAPI::PrintShip() const { - return logic.GetGateProgress(cellX, cellY); + for (const auto& Ship : logic.GetShips()) + { + logger->info("******Ship Info******"); + logger->info("type={}, playerID={}, GUID={}, x={}, y={}", THUAI7::shipTypeDict[Ship->shipType],Ship->playerID, Ship->guid, Ship->x, Ship->y); + logger->info("state={},speed={}, view range={},facing direction={}", THUAI7::shipStateDict[Ship->shipState],Ship->speed, Ship->viewRange,Ship->facingDirection); + logger->info("************************\n"); + } } -int32_t TrickerDebugAPI::GetGateProgress(int32_t cellX, int32_t cellY) const +void ShipDebugAPI::PrintSelfInfo() const { - return logic.GetGateProgress(cellX, cellY); + auto Ship = logic.ShipGetSelfInfo(); + logger->info("******Self Info******"); + logger->info("type={}, playerID={}, GUID={}, x={}, y={}", THUAI7::shipTypeDict[Ship->shipType], Ship->playerID, Ship->guid, Ship->x, Ship->y); + logger->info("state={},speed={}, view range={},facing direction={}", THUAI7::shipStateDict[Ship->shipState], Ship->speed, Ship->viewRange, Ship->facingDirection); + logger->info("*********************\n"); } -std::shared_ptr ShipDebugAPI::GetGameInfo() const +TeamDebugAPI::TeamDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t playerID) : + logic(logic) { - return logic.GetGameInfo(); + std::string fileName = "logs/api-" + std::to_string(playerID) + "-log.txt"; + auto fileLogger = std::make_shared(fileName, true); + auto printLogger = std::make_shared(); + std::string pattern = "[api" + std::to_string(playerID) + "] [%H:%M:%S.%e] [%l] %v"; + fileLogger->set_pattern(pattern); + printLogger->set_pattern(pattern); + if (file) + fileLogger->set_level(spdlog::level::trace); + else + fileLogger->set_level(spdlog::level::off); + if (print) + printLogger->set_level(spdlog::level::info); + else + printLogger->set_level(spdlog::level::off); + if (warnOnly) + printLogger->set_level(spdlog::level::warn); + logger = std::make_unique("apiLogger", spdlog::sinks_init_list{fileLogger, printLogger}); } -std::shared_ptr TrickerDebugAPI::GetGameInfo() const +void TeamDebugAPI::StartTimer() { - return logic.GetGameInfo(); + startPoint = std::chrono::system_clock::now(); + std::time_t t = std::chrono::system_clock::to_time_t(startPoint); + logger->info("=== AI.play() ==="); + logger->info("StartTimer: {}", std::ctime(&t)); } -std::vector ShipDebugAPI::GetPlayerGUIDs() const +void TeamDebugAPI::EndTimer() { - return logic.GetPlayerGUIDs(); + logger->info("Time elapsed: {}ms", Time::TimeSinceStart(startPoint)); } -std::vector TrickerDebugAPI::GetPlayerGUIDs() const +int32_t TeamDebugAPI::GetFrameCount() const { - return logic.GetPlayerGUIDs(); + return logic.GetCounter(); } -std::future ShipDebugAPI::StartLearning() +std::future TeamDebugAPI::SendTextMessage(int64_t toID, std::string message) { - logger->info("StartLearning: called at {}ms", Time::TimeSinceStart(startPoint)); - return std::async(std::launch::async, [this]() - { auto result = logic.StartLearning(); + logger->info("SendTextMessage: toID = {}, message = {}, called at {}ms", toID, message, Time::TimeSinceStart(startPoint)); + return std::async(std::launch::async, [=, message = std::move(message)]() + { auto result = logic.Send(toID, std::move(message), false); if (!result) - logger->warn("StartLearning: failed at {}ms", Time::TimeSinceStart(startPoint)); + logger->warn("SendTextMessage: failed at {}ms", Time::TimeSinceStart(startPoint)); return result; }); } -std::future ShipDebugAPI::StartRouseMate(int64_t mateID) +std::future TeamDebugAPI::SendBinaryMessage(int64_t toID, std::string message) { - logger->info("StartRouseMate: mate id={}, called at {}ms", mateID, Time::TimeSinceStart(startPoint)); - return std::async(std::launch::async, [=]() - { auto result = logic.StartRouseMate(mateID); + logger->info("SendBinaryMessage: toID = {}, message = {}, called at {}ms", toID, message, Time::TimeSinceStart(startPoint)); + return std::async(std::launch::async, [=, message = std::move(message)]() + { auto result = logic.Send(toID, std::move(message), true); if (!result) - logger->warn("StartRouseMate: failed at {}ms", Time::TimeSinceStart(startPoint)); + logger->warn("SendBinaryMessage: failed at {}ms", Time::TimeSinceStart(startPoint)); return result; }); } -std::future ShipDebugAPI::StartEncourageMate(int64_t mateID) +bool TeamDebugAPI::HaveMessage() { - logger->info("StartEncourageMate: mate id={}, called at {}ms", mateID, Time::TimeSinceStart(startPoint)); - return std::async(std::launch::async, [=]() - { auto result = logic.StartEncourageMate(mateID); - if (!result) - logger->warn("StartEncourageMate: failed at {}ms", Time::TimeSinceStart(startPoint)); - return result; }); + logger->info("HaveMessage: called at {}ms", Time::TimeSinceStart(startPoint)); + auto result = logic.HaveMessage(); + if (!result) + logger->warn("HaveMessage: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; } -std::future ShipDebugAPI::Graduate() +std::pair TeamDebugAPI::GetMessage() { - logger->info("Graduate: called at {}ms", Time::TimeSinceStart(startPoint)); - return std::async(std::launch::async, [this]() - { auto result = logic.Graduate(); - if (!result) - logger->warn("Graduate: failed at {}ms", Time::TimeSinceStart(startPoint)); - return result; }); + logger->info("GetMessage: called at {}ms", Time::TimeSinceStart(startPoint)); + auto result = logic.GetMessage(); + if (result.first == -1) + logger->warn("GetMessage: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; } -std::shared_ptr ShipDebugAPI::GetSelfInfo() const +bool TeamDebugAPI::Wait() { - return logic.ShipGetSelfInfo(); + logger->info("Wait: called at {}ms", Time::TimeSinceStart(startPoint)); + if (logic.GetCounter() == -1) + return false; + else + return logic.WaitThread(); } -std::future TrickerDebugAPI::Attack(double angleInRadian) +std::vector> TeamDebugAPI::GetShips() const { - logger->info("Attack: angleInRadian = {}, called at {}ms", angleInRadian, Time::TimeSinceStart(startPoint)); - return std::async(std::launch::async, [=]() - { auto result = logic.Attack(angleInRadian); - if (!result) - logger->warn("Attack: failed at {}ms", Time::TimeSinceStart(startPoint)); - return result; }); + return logic.GetShips(); } -std::future ShipDebugAPI::Attack(double angleInRadian) +std::vector> TeamDebugAPI::GetEnemyShips() const { - logger->info("Attack: angleInRadian = {}, called at {}ms", angleInRadian, Time::TimeSinceStart(startPoint)); - return std::async(std::launch::async, [=]() - { auto result = logic.Attack(angleInRadian); - if (!result) - logger->warn("Attack: failed at {}ms", Time::TimeSinceStart(startPoint)); - return result; }); + return logic.GetEnemyShips(); } -std::shared_ptr TrickerDebugAPI::GetSelfInfo() const +std::vector> TeamDebugAPI::GetBullets() const { - return logic.TrickerGetSelfInfo(); + return logic.GetBullets(); } -bool ShipDebugAPI::HaveView(int32_t gridX, int32_t gridY) const +std::vector> TeamDebugAPI::GetFullMap() const { - auto selfInfo = GetSelfInfo(); - return logic.HaveView(gridX, gridY, selfInfo->x, selfInfo->y, selfInfo->viewRange); + return logic.GetFullMap(); } -bool TrickerDebugAPI::HaveView(int32_t gridX, int32_t gridY) const +THUAI7::PlaceType TeamDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const { - auto selfInfo = GetSelfInfo(); - return logic.HaveView(gridX, gridY, selfInfo->x, selfInfo->y, selfInfo->viewRange); + return logic.GetPlaceType(cellX, cellY); } -void ShipDebugAPI::Print(std::string str) const +int32_t TeamDebugAPI::GetConstructionHp(int32_t cellX, int32_t cellY) const { - logger->info(str); + return logic.GetConstructionHp(cellX, cellY); } -void TrickerDebugAPI::Print(std::string str) const +int32_t TeamDebugAPI::GetWormHp(int32_t cellX, int32_t cellY) const { - logger->info(str); + return logic.GetWormHp(cellX, cellY); } -void ShipDebugAPI::PrintShip() const +int32_t TeamDebugAPI::GetResourceState(int32_t cellX, int32_t cellY) const { - for (const auto& Ship : logic.GetShips()) - { - logger->info("******Ship Info******"); - logger->info("playerID={}, GUID={}, x={}, y={}", Ship->playerID, Ship->guid, Ship->x, Ship->y); - logger->info("speed={}, view range={}, radius={}", Ship->speed, Ship->viewRange, Ship->radius); - std::string skillTime = ""; - for (const auto& time : Ship->timeUntilSkillAvailable) - skillTime += std::to_string(time) + ", "; - logger->info("score={}, facing direction={}, skill time={}", Ship->score, Ship->facingDirection, skillTime); - std::string props = ""; - for (const auto& prop : Ship->props) - props += THUAI7::propTypeDict[prop] + ", "; - logger->info("state={}, bullet={}, props={}", THUAI7::playerStateDict[Ship->playerState], THUAI7::bulletTypeDict[Ship->bulletType], props); - logger->info("type={}, determination={}, addiction={}, danger alert={}", THUAI7::ShipTypeDict[Ship->ShipType], Ship->determination, Ship->addiction, Ship->dangerAlert); - logger->info("learning speed={}, encourage speed={}, encourage progress={}, rouse progress={}", Ship->learningSpeed, Ship->encourageSpeed, Ship->encourageProgress, Ship->rouseProgress); - std::string ShipBuff = ""; - for (const auto& buff : Ship->buff) - ShipBuff += THUAI7::ShipBuffDict[buff] + ", "; - logger->info("buff={}", ShipBuff); - logger->info("************************\n"); - } + return logic.GetResourceState(cellX, cellY); } -void TrickerDebugAPI::PrintShip() const +int32_t TeamDebugAPI::GetHomeHp() const { - for (const auto& Ship : logic.GetShips()) - { - logger->info("******Ship Info******"); - logger->info("playerID={}, GUID={}, x={}, y={}", Ship->playerID, Ship->guid, Ship->x, Ship->y); - logger->info("speed={}, view range={}, radius={}", Ship->speed, Ship->viewRange, Ship->radius); - std::string skillTime = ""; - for (const auto& time : Ship->timeUntilSkillAvailable) - skillTime += std::to_string(time) + ", "; - logger->info("score={}, facing direction={}, skill time={}", Ship->score, Ship->facingDirection, skillTime); - std::string props = ""; - for (const auto& prop : Ship->props) - props += THUAI7::propTypeDict[prop] + ", "; - logger->info("state={}, bullet={}, props={}", THUAI7::playerStateDict[Ship->playerState], THUAI7::bulletTypeDict[Ship->bulletType], props); - logger->info("type={}, determination={}, addiction={}, danger alert={}", THUAI7::ShipTypeDict[Ship->ShipType], Ship->determination, Ship->addiction, Ship->dangerAlert); - logger->info("learning speed={}, encourage speed={}, encourage progress={}, rouse progress={}", Ship->learningSpeed, Ship->encourageSpeed, Ship->encourageProgress, Ship->rouseProgress); - std::string ShipBuff = ""; - for (const auto& buff : Ship->buff) - ShipBuff += THUAI7::ShipBuffDict[buff] + ", "; - logger->info("buff={}", ShipBuff); - logger->info("************************\n"); - } + return logic.GetHomeHp(); } -void ShipDebugAPI::PrintTricker() const +std::shared_ptr TeamDebugAPI::GetGameInfo() const { - for (const auto& tricker : logic.GetTrickers()) - { - logger->info("******Tricker Info******"); - logger->info("playerID={}, GUID={}, x={}, y={}", tricker->playerID, tricker->guid, tricker->x, tricker->y); - logger->info("speed={}, view range={}, radius={}", tricker->speed, tricker->viewRange, tricker->radius); - std::string skillTime = ""; - for (const auto& time : tricker->timeUntilSkillAvailable) - skillTime += std::to_string(time) + ", "; - logger->info("score={}, facing direction={}, skill time={}", tricker->score, tricker->facingDirection, skillTime); - std::string props = ""; - for (const auto& prop : tricker->props) - props += THUAI7::propTypeDict[prop] + ", "; - logger->info("state={}, bullet={}, props={}", THUAI7::playerStateDict[tricker->playerState], THUAI7::bulletTypeDict[tricker->bulletType], props); - logger->info("type={}, trick desire={}, class volume={}", THUAI7::trickerTypeDict[tricker->trickerType], tricker->trickDesire, tricker->classVolume); - std::string trickerBuff = ""; - for (const auto& buff : tricker->buff) - trickerBuff += THUAI7::trickerBuffDict[buff] + ", "; - logger->info("buff={}", trickerBuff); - logger->info("************************\n"); - } + return logic.GetGameInfo(); } -void TrickerDebugAPI::PrintTricker() const +std::vector TeamDebugAPI::GetPlayerGUIDs() const { - for (auto tricker : logic.GetTrickers()) - { - logger->info("******Tricker Info******"); - logger->info("playerID={}, GUID={}, x={}, y={}", tricker->playerID, tricker->guid, tricker->x, tricker->y); - logger->info("speed={}, view range={}, radius={}", tricker->speed, tricker->viewRange, tricker->radius); - std::string skillTime = ""; - for (const auto& time : tricker->timeUntilSkillAvailable) - skillTime += std::to_string(time) + ", "; - logger->info("score={}, facing direction={}, skill time={}", tricker->score, tricker->facingDirection, skillTime); - std::string props = ""; - for (const auto& prop : tricker->props) - props += THUAI7::propTypeDict[prop] + ", "; - logger->info("state={}, bullet={}, props={}", THUAI7::playerStateDict[tricker->playerState], THUAI7::bulletTypeDict[tricker->bulletType], props); - logger->info("type={}, trick desire={}, class volume={}", THUAI7::trickerTypeDict[tricker->trickerType], tricker->trickDesire, tricker->classVolume); - std::string trickerBuff = ""; - for (const auto& buff : tricker->buff) - trickerBuff += THUAI7::trickerBuffDict[buff] + ", "; - logger->info("buff={}", trickerBuff); - logger->info("************************\n"); - } + return logic.GetPlayerGUIDs(); } -void ShipDebugAPI::PrintProp() const +std::shared_ptr TeamDebugAPI::GetSelfInfo() const { - for (auto prop : logic.GetProps()) - { - logger->info("******Prop Info******"); - logger->info("GUID={}, x={}, y={}, facing direction={}", prop->guid, prop->x, prop->y, prop->facingDirection); - logger->info("*********************\n"); - } + return logic.TeamGetSelfInfo(); } -void TrickerDebugAPI::PrintProp() const +int32_t TeamDebugAPI::GetMoney() const { - for (auto prop : logic.GetProps()) - { - logger->info("******Prop Info******"); - logger->info("GUID={}, x={}, y={}, facing direction={}", prop->guid, prop->x, prop->y, prop->facingDirection); - logger->info("*********************\n"); - } + return logic.GetMoney(); } -void ShipDebugAPI::PrintSelfInfo() const +int32_t TeamDebugAPI::GetScore() const { - auto Ship = logic.ShipGetSelfInfo(); - logger->info("******Self Info******"); - logger->info("playerID={}, GUID={}, x={}, y={}", Ship->playerID, Ship->guid, Ship->x, Ship->y); - logger->info("speed={}, view range={}, radius={}", Ship->speed, Ship->viewRange, Ship->radius); - std::string skillTime = ""; - for (const auto& time : Ship->timeUntilSkillAvailable) - skillTime += std::to_string(time) + ", "; - logger->info("score={}, facing direction={}, skill time={}", Ship->score, Ship->facingDirection, skillTime); - std::string props = ""; - for (const auto& prop : Ship->props) - props += THUAI7::propTypeDict[prop] + ", "; - logger->info("state={}, bullet={}, props={}", THUAI7::playerStateDict[Ship->playerState], THUAI7::bulletTypeDict[Ship->bulletType], props); - logger->info("type={}, determination={}, addiction={}, danger alert={}", THUAI7::ShipTypeDict[Ship->ShipType], Ship->determination, Ship->addiction, Ship->dangerAlert); - logger->info("learning speed={}, encourage speed={}, encourage progress={}, rouse progress={}", Ship->learningSpeed, Ship->encourageSpeed, Ship->encourageProgress, Ship->rouseProgress); - std::string ShipBuff = ""; - for (const auto& buff : Ship->buff) - ShipBuff += THUAI7::ShipBuffDict[buff] + ", "; - logger->info("buff={}", ShipBuff); - logger->info("*********************\n"); + return logic.GetScore(); } -void TrickerDebugAPI::PrintSelfInfo() const +std::future TeamDebugAPI::InstallModule(int64_t playerID, THUAI7::ModuleType moduleType) +{ + return std::async(std::launch::async, [=]() + { return logic.InstallModule(playerID, moduleType);}); +} +void TeamDebugAPI::PrintSelfInfo() const { - auto tricker = logic.TrickerGetSelfInfo(); + auto Team = logic.TeamGetSelfInfo(); logger->info("******Self Info******"); - logger->info("playerID={}, GUID={}, x={}, y={}", tricker->playerID, tricker->guid, tricker->x, tricker->y); - logger->info("speed={}, view range={}, radius={}", tricker->speed, tricker->viewRange, tricker->radius); - std::string skillTime = ""; - for (const auto& time : tricker->timeUntilSkillAvailable) - skillTime += std::to_string(time) + ", "; - logger->info("score={}, facing direction={}, skill time={}", tricker->score, tricker->facingDirection, skillTime); - std::string props = ""; - for (const auto& prop : tricker->props) - props += THUAI7::propTypeDict[prop] + ", "; - logger->info("state={}, bullet={}, props={}", THUAI7::playerStateDict[tricker->playerState], THUAI7::bulletTypeDict[tricker->bulletType], props); - logger->info("type={}, trick desire={}, class volume={}", THUAI7::trickerTypeDict[tricker->trickerType], tricker->trickDesire, tricker->classVolume); - std::string trickerBuff = ""; - for (const auto& buff : tricker->buff) - trickerBuff += THUAI7::trickerBuffDict[buff] + ", "; - logger->info("buff={}", trickerBuff); + logger->info("playerID={}, teamID={}, score={}, money={}", Team->playerID, Team->teamID, Team->score, Team->money); logger->info("*********************\n"); } @@ -588,7 +436,7 @@ void ShipDebugAPI::Play(IAI& ai) ai.play(*this); } -void TrickerDebugAPI::Play(IAI& ai) +void TeamDebugAPI::Play(IAI& ai) { ai.play(*this); } diff --git a/CAPI/cpp/API/src/logic.cpp b/CAPI/cpp/API/src/logic.cpp index 3987eafd..c4861652 100755 --- a/CAPI/cpp/API/src/logic.cpp +++ b/CAPI/cpp/API/src/logic.cpp @@ -27,9 +27,9 @@ Logic::Logic(int64_t pID, int64_t tID, THUAI7::PlayerType pType, THUAI7::ShipTyp currentState->mapInfo = std::make_shared(); bufferState->gameInfo = std::make_shared(); bufferState->mapInfo = std::make_shared(); - if (teamID == 0) + if (teamID == 1) playerTeam = THUAI7::PlayerTeam::Red; - else + if (teamID == 2) playerTeam = THUAI7::PlayerTeam::Blue; } @@ -41,7 +41,7 @@ std::vector> Logic::GetShips() const return temp; } -std::vector> Logic::GetEnemyShips() +std::vector> Logic::GetEnemyShips() const { std::unique_lock lock(mtxState); std::vector> temp(currentState->enemyships.begin(), currentState->enemyships.end()); @@ -57,14 +57,14 @@ std::vector> Logic::GetBullets() const return temp; } -std::shared_ptr Logic::ShipGetSelfInfo() +std::shared_ptr Logic::ShipGetSelfInfo() const { std::unique_lock lock(mtxState); logger->debug("Called ShipGetSelfInfo"); return currentState->shipSelf; } -std::shared_ptr Logic::TeamGetSelfInfo() +std::shared_ptr Logic::TeamGetSelfInfo() const { std::unique_lock lock(mtxState); logger->debug("Called TeamGetSelfInfo"); @@ -113,7 +113,7 @@ int32_t Logic::GetConstructionHp(int32_t cellX, int32_t cellY) const } } -int32_t Logic::GetWormHp(int32_t cellX, int32_t cellY) +int32_t Logic::GetWormHp(int32_t cellX, int32_t cellY) const { std::unique_lock lock(mtxState); logger->debug("Called GetWormHp"); @@ -129,17 +129,17 @@ int32_t Logic::GetWormHp(int32_t cellX, int32_t cellY) return -1; } } -int32_t Logic::GetHomeHp() +int32_t Logic::GetHomeHp() const { std::unique_lock lock(mtxState); logger->debug("Called GetHomeHp"); if (playerTeam == THUAI7::PlayerTeam::Red) return currentState->gameInfo->redHomeHp; else - return curretState->gameInfo->blueHomeHp; + return currentState->gameInfo->blueHomeHp; } -int32_t Logic::GetResourceState(int32_t cellX, int32_t cellY) +int32_t Logic::GetResourceState(int32_t cellX, int32_t cellY) const { std::unique_lock lock(mtxState); logger->debug("Called GetResourceState"); @@ -156,7 +156,7 @@ int32_t Logic::GetResourceState(int32_t cellX, int32_t cellY) } } -int32_t Logic::GetMoney() +int32_t Logic::GetMoney() const { std::unique_lock lock(mtxState); logger->debug("Called GetMoney"); @@ -170,7 +170,7 @@ int32_t Logic::GetMoney() return -1; } } -int32_t Logic::GetScore() +int32_t Logic::GetScore() const { std::unique_lock lock(mtxState); logger->debug("Called GetScore"); @@ -198,10 +198,10 @@ bool Logic::Move(int64_t time, double angle) return pComm->Move(playerID, teamID, time, angle); } -bool Logic::SendMessage(int64_t toID, std::string message, bool binary) +bool Logic::Send(int64_t toID, std::string message, bool binary) { logger->debug("Called SendMessage"); - return pComm->SendMessage(playerID, teamID, toID, std::move(message), binary); + return pComm->Send(playerID, teamID, toID, std::move(message), binary); } bool Logic::HaveMessage() @@ -236,13 +236,13 @@ bool Logic::Recover() } // 等待完成 -bool Logic::Recycle() +bool Logic::Recycle(int64_t targetID) { logger->debug("Called Recycle"); - return pComm->Recycle(playerID, teamID); + return pComm->Recycle(targetID, teamID); } -bool Logic::Produce(); +bool Logic::Produce() { logger->debug("Called Produce"); return pComm->Produce(playerID, teamID); @@ -278,6 +278,9 @@ void Logic::ProcessMessage() { try { + //TODO + int32_t x = 0; + int32_t y = 0; logger->info("Message thread start!"); pComm->AddPlayer(playerID, teamID, shipType, x, y); while (gameState != THUAI7::GameState::GameEnd) @@ -399,137 +402,133 @@ void Logic::LoadBufferSelf(const protobuf::MessageToClient& message) void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) { - int32_t x, y, viewRange; - if (isShip) - x = bufferState->shipSelf->x, y = bufferState->shipSelf->y; - else - x = bufferState->homeSelf->x, y = bufferState->homeSelf->y; - - if (isShip && Proto2THUAI7::messageOfObjDict[item.message_of_obj_case()] == THUAI7::MessageOfObj::ShipMessage) + if (playerType == THUAI7::PlayerType::Ship) { - if (playerTeam != item.ship_message().team()) + int32_t x, y, viewRange; + x = bufferState->shipSelf->x, y = bufferState->shipSelf->y, viewRange = bufferState->shipSelf->viewRange; + switch (Proto2THUAI7::messageOfObjDict[item.message_of_obj_case()]) { - if (AssistFunction::HaveView(x, y, item.ship_message().x(), item.ship_message().y(), bufferState->gameMap)) - { - bufferState->enemyships.push_back(Proto2THUAI7::Protobuf2THUAI7Ship(item.ship_message())); - logger->debug("Add Enemyship!"); - } - return; - } - } - - switch (Proto2THUAI7::messageOfObjDict[item.message_of_obj_case()]) - { - case THUAI7::MessageOfObj::BulletMessage: - if (AssistFunction::HaveView(x, y, item.bullet_message().x(), item.bullet_message().y(), bufferState->gameMap)) - { - bufferState->bullets.push_back(Proto2THUAI7::Protobuf2THUAI7Bullet(item.bullet_message())); - logger->debug("Add Bullet!"); - } - break; - case THUAI7::MessageOfObj::FactoryMessage: - if (AssistFunction::HaveView(x, y, item.factory_message().x(), item.factory_message().y(), bufferState->gameMap)) - { - auto pos = std::make_pair(AssistFunction::GridToCell(item.factory_message().x()), AssistFunction::GridToCell(item.factory_message().y())); - if (bufferState->mapInfo->factoryState.count(pos) == 0) - { - bufferState->mapInfo->factoryState.emplace(pos, {item.factory_message().hp(), item.factory_message().team()}); - logger->debug("Add Factory!"); - } - else + case THUAI7::MessageOfObj::ShipMessage: + if (teamID != item.ship_message().team_id()) { - bufferState->mapInfo->factoryState[pos].first = item.factory_message().hp(); - logger->debug("Update Factory!"); - } - } - break; - case THUAI7::MessageOfObj::CommunityMessage: - if (AssistFunction::HaveView(x, y, item.community_message().x(), item.community_message().y(), bufferState->gameMap)) - { - auto pos = std::make_pair(AssistFunction::GridToCell(item.community_message().x()), AssistFunction::GridToCell(item.community_message().y())); - if (bufferState->mapInfo->communityState.count(pos) == 0) - { - bufferState->mapInfo->communityState.emplace(pos, {item.community_message().hp(), item.community_message().team()}); - logger->debug("Add Community!"); - } - else - { - bufferState->mapInfo->communityState[pos].first = item.community_message().hp(); - logger->debug("Update Community!"); - } - } - break; - case THUAI7::MessageOfObj::FortMessage: - if (AssistFunction::HaveView(x, y, item.fort_message().x(), item.fort_message().y(), bufferState->gameMap)) - { - auto pos = std::make_pair(AssistFunction::GridToCell(item.fort_message().x()), AssistFunction::GridToCell(item.fort_message().y())); - if (bufferState->mapInfo->fortState.count(pos) == 0) - { - bufferState->mapInfo->fortState.emplace(pos, {item.fort_message().hp(), item.fort_message().team()}); - logger->debug("Add Fort!"); + if (AssistFunction::HaveView(x, y, item.ship_message().x(), item.ship_message().y(), viewRange, bufferState->gameMap)) + { + bufferState->enemyships.push_back(Proto2THUAI7::Protobuf2THUAI7Ship(item.ship_message())); + logger->debug("Add Enemyship!"); + } } - else + break; + case THUAI7::MessageOfObj::BulletMessage: + if (AssistFunction::HaveView(x, y, item.bullet_message().x(), item.bullet_message().y(),viewRange, bufferState->gameMap)) { - bufferState->mapInfo->fortState[pos].first = item.fort_message().hp(); - logger->debug("Update Fort!"); + bufferState->bullets.push_back(Proto2THUAI7::Protobuf2THUAI7Bullet(item.bullet_message())); + logger->debug("Add Bullet!"); } - } - break; - case THUAI7::MessageOfObj::WormholeMessage: - if (AssistFunction::HaveView(x, y, item.wormhole_message().x(), item.wormhole_message().y(), bufferState->gameMap)) - { - auto pos = std::make_pair(AssistFunction::GridToCell(item.wormhole_message().x()), AssistFunction::GridToCell(item.wormhole_message().y())); - if (bufferState->mapInfo->wormholeState.count(pos) == 0) + break; + case THUAI7::MessageOfObj::FactoryMessage: + if (AssistFunction::HaveView(x, y, item.factory_message().x(), item.factory_message().y(),viewRange, bufferState->gameMap)) { - bufferState->mapInfo->wormholeState.emplace(pos, item.wormhole_message().hp()); - logger->debug("Add Wormhole!"); + auto pos = std::make_pair(AssistFunction::GridToCell(item.factory_message().x()), AssistFunction::GridToCell(item.factory_message().y())); + if (bufferState->mapInfo->factoryState.count(pos) == 0) + { + bufferState->mapInfo->factoryState.emplace(pos, std::make_pair(item.factory_message().team_id() ,item.factory_message().hp())); + logger->debug("Add Factory!"); + } + else + { + bufferState->mapInfo->factoryState[pos].first = item.factory_message().hp(); + logger->debug("Update Factory!"); + } } - else + break; + case THUAI7::MessageOfObj::CommunityMessage: + if (AssistFunction::HaveView(x, y, item.community_message().x(), item.community_message().y(),viewRange, bufferState->gameMap)) { - bufferState->mapInfo->wormholeState[pos] = item.wormhole_message().hp(); - logger->debug("Update Wormhole!"); + auto pos = std::make_pair(AssistFunction::GridToCell(item.community_message().x()), AssistFunction::GridToCell(item.community_message().y())); + if (bufferState->mapInfo->communityState.count(pos) == 0) + { + bufferState->mapInfo->communityState.emplace(pos, std::make_pair(item.community_message().team_id(), item.community_message().hp())); + logger->debug("Add Community!"); + } + else + { + bufferState->mapInfo->communityState[pos].first = item.community_message().hp(); + logger->debug("Update Community!"); + } } - } - break; - case THUAI7::MessageOfObj::ResourceMessage: - if (AssistFunction::HaveView(x, y, item.resource_message().x(), item.resource_message().y(), bufferState->gameMap)) - { - auto pos = std::make_pair(AssistFunction::GridToCell(item.resource_message().x()), AssistFunction::GridToCell(item.resource_message().y())); - if (bufferState->mapInfo->resourceState.count(pos) == 0) + break; + case THUAI7::MessageOfObj::FortMessage: + if (AssistFunction::HaveView(x, y, item.fort_message().x(), item.fort_message().y(),viewRange, bufferState->gameMap)) { - bufferState->mapInfo->resourceState.emplace(pos, item.resource_message().progress()); - logger->debug("Add Resouce!"); + auto pos = std::make_pair(AssistFunction::GridToCell(item.fort_message().x()), AssistFunction::GridToCell(item.fort_message().y())); + if (bufferState->mapInfo->fortState.count(pos) == 0) + { + bufferState->mapInfo->fortState.emplace(pos, std::make_pair(item.fort_message().team_id(), item.fort_message().hp())); + logger->debug("Add Fort!"); + } + else + { + bufferState->mapInfo->fortState[pos].first = item.fort_message().hp(); + logger->debug("Update Fort!"); + } } - else + break; + case THUAI7::MessageOfObj::WormholeMessage: + if (AssistFunction::HaveView(x, y, item.wormhole_message().x(), item.wormhole_message().y(),viewRange, bufferState->gameMap)) { - bufferState->mapInfo->resourceState[pos].first = item.resouce_message().progress(); - logger->debug("Update Resource!"); + auto pos = std::make_pair(AssistFunction::GridToCell(item.wormhole_message().x()), AssistFunction::GridToCell(item.wormhole_message().y())); + if (bufferState->mapInfo->wormholeState.count(pos) == 0) + { + bufferState->mapInfo->wormholeState.emplace(pos, item.wormhole_message().hp()); + logger->debug("Add Wormhole!"); + } + else + { + bufferState->mapInfo->wormholeState[pos] = item.wormhole_message().hp(); + logger->debug("Update Wormhole!"); + } } - } - break; - case THUAI7::MessageOfObj::NewsMessage: - { - auto news = item.news_message(); - if (news.to_id() == APIid) + break; + case THUAI7::MessageOfObj::ResourceMessage: + if (AssistFunction::HaveView(x, y, item.resource_message().x(), item.resource_message().y(),viewRange, bufferState->gameMap)) { - if (Proto2THUAI7::newsTypeDict[news.news_case()] == THUAI7::NewsType::TextMessage) + auto pos = std::make_pair(AssistFunction::GridToCell(item.resource_message().x()), AssistFunction::GridToCell(item.resource_message().y())); + if (bufferState->mapInfo->resourceState.count(pos) == 0) { - messageQueue.emplace(std::make_pair(news.from_id(), news.text_message())); - logger->debug("Add News!"); + bufferState->mapInfo->resourceState.emplace(pos, item.resource_message().progress()); + logger->debug("Add Resouce!"); } - else if (Proto2THUAI7::newsTypeDict[news.news_case()] == THUAI7::NewsType::BinaryMessage) + else { - messageQueue.emplace(std::make_pair(news.from_id(), news.binary_message())); - logger->debug("Add Binary News!"); + bufferState->mapInfo->resourceState[pos] = item.resource_message().progress(); + logger->debug("Update Resource!"); } - else - logger->error("Unknown NewsType!"); } break; - } - case THUAI7::MessageOfObj::NullMessageOfObj: - default: - break; + case THUAI7::MessageOfObj::NewsMessage: + { + auto news = item.news_message(); + if (news.to_id() == playerID) + { + if (Proto2THUAI7::newsTypeDict[news.news_case()] == THUAI7::NewsType::TextMessage) + { + messageQueue.emplace(std::make_pair(news.from_id(), news.text_message())); + logger->debug("Add News!"); + } + else if (Proto2THUAI7::newsTypeDict[news.news_case()] == THUAI7::NewsType::BinaryMessage) + { + messageQueue.emplace(std::make_pair(news.from_id(), news.binary_message())); + logger->debug("Add Binary News!"); + } + else + logger->error("Unknown NewsType!"); + } + break; + } + case THUAI7::MessageOfObj::NullMessageOfObj: + default: + break; + } } } @@ -542,7 +541,7 @@ void Logic::LoadBuffer(const protobuf::MessageToClient& message) // 清空原有信息 bufferState->ships.clear(); bufferState->enemyships.clear(); - bufferState->homes.clear(); + bufferState->teams.clear(); bufferState->bullets.clear(); bufferState->guids.clear(); @@ -551,8 +550,9 @@ void Logic::LoadBuffer(const protobuf::MessageToClient& message) for (const auto& obj : message.obj_message()) if (Proto2THUAI7::messageOfObjDict[obj.message_of_obj_case()] == THUAI7::MessageOfObj::ShipMessage) bufferState->guids.push_back(obj.ship_message().guid()); - else if (Proto2THUAI7::messageOfObjDict[obj.message_of_obj_case()] == THUAI7::MessageOfObj::HomeMessage) - bufferState->guids.push_back(obj.home_message().guid()); + //TODO + //else if (Proto2THUAI7::messageOfObjDict[obj.message_of_obj_case()] == THUAI7::MessageOfObj::HomeMessage) + // bufferState->guids.push_back(obj.home_message().guid()); bufferState->gameInfo = Proto2THUAI7::Protobuf2THUAI7GameInfo(message.all_message()); LoadBufferSelf(message); for (const auto& item : message.obj_message()) @@ -628,13 +628,13 @@ std::vector Logic::GetPlayerGUIDs() const bool Logic::TryConnection() { logger->info("Try to connect to server..."); - return pComm->TryConnection(APIid); + return pComm->TryConnection(playerID,teamID); } -bool Logic::HaveView(int32_t gridX, int32_t gridY, int32_t selfX, int32_t selfY) const +bool Logic::HaveView(int32_t gridX, int32_t gridY, int32_t selfX, int32_t selfY,int32_t viewRange) const { std::unique_lock lock(mtxState); - return AssistFunction::HaveView(selfX, selfY, gridX, gridY, currentState->gameMap); + return AssistFunction::HaveView(selfX, selfY, gridX, gridY,viewRange,currentState->gameMap); } void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port, bool file, bool print, bool warnOnly) @@ -662,10 +662,10 @@ void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port, bool f logger->info("*********Basic Info*********"); logger->info("asynchronous: {}", asynchronous); logger->info("server: {}:{}", IP, port); - if (isShip) - logger->info("ship ID: {}", APIid); + if (playerType==THUAI7::PlayerType::Ship) + logger->info("ship ID: {}", playerID); else - logger->info("home ID: {}", APIid); + logger->info("home ID: {}", playerID); logger->info("player team: {}", THUAI7::playerTeamDict[playerTeam]); logger->info("****************************"); @@ -673,38 +673,38 @@ void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port, bool f pComm = std::make_unique(IP, port); // 构造timer - if (playerTeam == THUAI7::PlayerTeam::Up) + if (playerTeam == THUAI7::PlayerTeam::Red) { - if (isShip) + if (playerType==THUAI7::PlayerType::Ship) { if (!file && !print) timer = std::make_unique(*this); else - timer = std::make_unique(*this, file, print, warnOnly, APIid); + timer = std::make_unique(*this, file, print, warnOnly, playerID); } else { if (!file && !print) - timer = std::make_unique(*this); + timer = std::make_unique(*this); else - timer = std::make_unique(*this, file, print, warnOnly, APIid); + timer = std::make_unique(*this, file, print, warnOnly, playerID); } } - else if (playerTeam == THUAI7::PlayerTeam::Down) + else if (playerTeam == THUAI7::PlayerTeam::Blue) { - if (isShip) + if (playerType==THUAI7::PlayerType::Ship) { if (!file && !print) timer = std::make_unique(*this); else - timer = std::make_unique(*this, file, print, warnOnly, APIid); + timer = std::make_unique(*this, file, print, warnOnly, playerID); } else { if (!file && !print) - timer = std::make_unique(*this); + timer = std::make_unique(*this); else - timer = std::make_unique(*this, file, print, warnOnly, APIid); + timer = std::make_unique(*this, file, print, warnOnly, playerID); } } @@ -718,7 +718,7 @@ void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port, bool f cvAI.wait(lock, [this]() { return AIStart; }); } - auto ai = createAI(APIid); + auto ai = createAI(playerID); while (AILoop) { From 844d7285b06bacfd902b9a48ddc513632d43efd6 Mon Sep 17 00:00:00 2001 From: sigureling <1678348940@qq.com> Date: Wed, 21 Feb 2024 19:58:11 +0800 Subject: [PATCH 2/2] fix: Update CAPI --- CAPI/cpp/API/include/API.h | 195 ++++++++++++++------------- CAPI/cpp/API/include/Communication.h | 2 +- CAPI/cpp/API/include/logic.h | 32 ++--- CAPI/cpp/API/include/structures.h | 136 +++++++++---------- CAPI/cpp/API/src/AI.cpp | 1 - CAPI/cpp/API/src/API.cpp | 12 +- CAPI/cpp/API/src/Communication.cpp | 2 +- CAPI/cpp/API/src/DebugAPI.cpp | 6 +- CAPI/cpp/API/src/logic.cpp | 36 ++--- 9 files changed, 211 insertions(+), 211 deletions(-) diff --git a/CAPI/cpp/API/include/API.h b/CAPI/cpp/API/include/API.h index f300ce4a..f30de826 100755 --- a/CAPI/cpp/API/include/API.h +++ b/CAPI/cpp/API/include/API.h @@ -72,7 +72,7 @@ class ILogic // Team使用的部分 virtual bool Recycle(int64_t playerID) = 0; virtual bool InstallModule(int64_t playerID, THUAI7::ModuleType moduleType) = 0; - virtual bool BuildShip(THUAI7::ShipType shipType,int32_t cellX, int32_t cellY) = 0; + virtual bool BuildShip(THUAI7::ShipType shipType, int32_t cellX, int32_t cellY) = 0; }; class IAPI @@ -151,7 +151,7 @@ class ITeamAPI : public IAPI [[nodiscard]] virtual std::shared_ptr GetSelfInfo() const = 0; virtual std::future InstallModule(int64_t playerID, THUAI7::ModuleType moduletype) = 0; virtual std::future Recycle(int64_t playerID) = 0; - virtual std::future BuildShip(THUAI7::ShipType shipType,int32_t cellX, int32_t cellY) = 0; + virtual std::future BuildShip(THUAI7::ShipType shipType, int32_t cellX, int32_t cellY) = 0; }; class IGameTimer @@ -267,7 +267,7 @@ class TeamAPI : public ITeamAPI, public IGameTimer [[nodiscard]] int32_t GetMoney() const override; std::future InstallModule(int64_t playerID, THUAI7::ModuleType moduleType) override; std::future Recycle(int64_t playerID) override; - std::future BuildShip(THUAI7::ShipType shipType,int32_t cellX, int32_t cellY) override; + std::future BuildShip(THUAI7::ShipType shipType, int32_t cellX, int32_t cellY) override; void Print(std::string str) const override { @@ -283,34 +283,34 @@ class TeamAPI : public ITeamAPI, public IGameTimer ILogic& logic; }; - class ShipDebugAPI : public IShipAPI, public IGameTimer - { - ShipDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t shipID); - void StartTimer() override - { - } - void EndTimer() override - { - } - void Play(IAI& ai) override; - std::future SendTextMessage(int64_t, std::string) override; - std::future SendBinaryMessage(int64_t, std::string) override; - [[nodiscard]] bool HaveMessage() override; - [[nodiscard]] std::pair GetMessage() override; - bool Wait() override; - [[nodiscard]] int32_t GetFrameCount() const override; - std::future EndAllAction() override; - - std::future Move(int64_t timeInMilliseconds, double angleInRadian) override; - std::future MoveRight(int64_t timeInMilliseconds) override; - std::future MoveUp(int64_t timeInMilliseconds) override; - std::future MoveLeft(int64_t timeInMilliseconds) override; - std::future MoveDown(int64_t timeInMilliseconds) override; - std::future Attack(double angleInRadian) override; - std::future Recover() override; - std::future Produce() override; - std::future ReBuild(THUAI7::ConstructionType constructionType) override; - std::future Construct(THUAI7::ConstructionType constructionType) override; +class ShipDebugAPI : public IShipAPI, public IGameTimer +{ + ShipDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t shipID); + void StartTimer() override + { + } + void EndTimer() override + { + } + void Play(IAI& ai) override; + std::future SendTextMessage(int64_t, std::string) override; + std::future SendBinaryMessage(int64_t, std::string) override; + [[nodiscard]] bool HaveMessage() override; + [[nodiscard]] std::pair GetMessage() override; + bool Wait() override; + [[nodiscard]] int32_t GetFrameCount() const override; + std::future EndAllAction() override; + + std::future Move(int64_t timeInMilliseconds, double angleInRadian) override; + std::future MoveRight(int64_t timeInMilliseconds) override; + std::future MoveUp(int64_t timeInMilliseconds) override; + std::future MoveLeft(int64_t timeInMilliseconds) override; + std::future MoveDown(int64_t timeInMilliseconds) override; + std::future Attack(double angleInRadian) override; + std::future Recover() override; + std::future Produce() override; + std::future ReBuild(THUAI7::ConstructionType constructionType) override; + std::future Construct(THUAI7::ConstructionType constructionType) override; [[nodiscard]] std::vector> GetShips() const override; [[nodiscard]] std::vector> GetEnemyShips() const override; @@ -328,70 +328,71 @@ class TeamAPI : public ITeamAPI, public IGameTimer [[nodiscard]] int32_t GetMoney() const override; [[nodiscard]] int32_t GetScore() const override; - void Print(std::string str) const override - { - } - void PrintShip() const override - { - } - void PrintSelfInfo() const override - { - } - - private: - std::chrono::system_clock::time_point startPoint; - std::unique_ptr logger; - ILogic& logic; - }; - - class TeamDebugAPI : public ITeamAPI, public IGameTimer - { - TeamDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t TeamID); - void StartTimer() override - { - } - void EndTimer() override - { - } - void Play(IAI& ai) override; - - std::future SendTextMessage(int64_t, std::string) override; - std::future SendBinaryMessage(int64_t, std::string) override; - [[nodiscard]] bool HaveMessage() override; - [[nodiscard]] std::pair GetMessage() override; - - [[nodiscard]] int32_t GetFrameCount() const override; - bool Wait() override; - std::future EndAllAction() override; - - [[nodiscard]] std::vector> GetShips() const override; - [[nodiscard]] std::vector> GetEnemyShips() const override; - [[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]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const override; - [[nodiscard]] int32_t GetWormHp(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; - [[nodiscard]] std::shared_ptr GetGameInfo() const override; - [[nodiscard]] std::vector GetPlayerGUIDs() const override; - [[nodiscard]] std::shared_ptr GetSelfInfo() const override; - - [[nodiscard]] int32_t GetScore() const override; - [[nodiscard]] int32_t GetMoney() const override; - std::future InstallModule(int64_t playerID, THUAI7::ModuleType moduleType) override; - std::future Recycle(int64_t playerID) override; - std::future BuildShip(THUAI7::ShipType shipType,int32_t cellX, int32_t cellY) override; - void Print(std::string str) const override - { - } - void PrintSelfInfo() const override - { - } - private: - std::chrono::system_clock::time_point startPoint; - std::unique_ptr logger; - ILogic& logic; - }; - + void Print(std::string str) const override + { + } + void PrintShip() const override + { + } + void PrintSelfInfo() const override + { + } + +private: + std::chrono::system_clock::time_point startPoint; + std::unique_ptr logger; + ILogic& logic; +}; + +class TeamDebugAPI : public ITeamAPI, public IGameTimer +{ + TeamDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t TeamID); + void StartTimer() override + { + } + void EndTimer() override + { + } + void Play(IAI& ai) override; + + std::future SendTextMessage(int64_t, std::string) override; + std::future SendBinaryMessage(int64_t, std::string) override; + [[nodiscard]] bool HaveMessage() override; + [[nodiscard]] std::pair GetMessage() override; + + [[nodiscard]] int32_t GetFrameCount() const override; + bool Wait() override; + std::future EndAllAction() override; + + [[nodiscard]] std::vector> GetShips() const override; + [[nodiscard]] std::vector> GetEnemyShips() const override; + [[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]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const override; + [[nodiscard]] int32_t GetWormHp(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; + [[nodiscard]] std::shared_ptr GetGameInfo() const override; + [[nodiscard]] std::vector GetPlayerGUIDs() const override; + [[nodiscard]] std::shared_ptr GetSelfInfo() const override; + + [[nodiscard]] int32_t GetScore() const override; + [[nodiscard]] int32_t GetMoney() const override; + std::future InstallModule(int64_t playerID, THUAI7::ModuleType moduleType) override; + std::future Recycle(int64_t playerID) override; + std::future BuildShip(THUAI7::ShipType shipType, int32_t cellX, int32_t cellY) override; + void Print(std::string str) const override + { + } + void PrintSelfInfo() const override + { + } + +private: + std::chrono::system_clock::time_point startPoint; + std::unique_ptr logger; + ILogic& logic; +}; + #endif \ No newline at end of file diff --git a/CAPI/cpp/API/include/Communication.h b/CAPI/cpp/API/include/Communication.h index 10f0dbee..a22ed2f1 100755 --- a/CAPI/cpp/API/include/Communication.h +++ b/CAPI/cpp/API/include/Communication.h @@ -41,7 +41,7 @@ class Communication bool Send(int64_t playerID, int64_t toPlayerID, int64_t teamID, std::string message, bool binary); // Team bool InstallModule(int64_t playerID, int64_t teamID, THUAI7::ModuleType moduleType); - bool BuildShip(int64_t teamID,THUAI7::ShipType shipType, int32_t x, int32_t y); + bool BuildShip(int64_t teamID, THUAI7::ShipType shipType, int32_t x, int32_t y); bool Recycle(int64_t playerID, int64_t teamID); private: diff --git a/CAPI/cpp/API/include/logic.h b/CAPI/cpp/API/include/logic.h index d2fcab82..f306b4bb 100755 --- a/CAPI/cpp/API/include/logic.h +++ b/CAPI/cpp/API/include/logic.h @@ -107,26 +107,26 @@ class Logic : public ILogic [[nodiscard]] int32_t GetScore() const; // 供IAPI使用的操作相关的部分 - bool Send(int64_t toPlayerID, std::string message, bool binary); - bool HaveMessage(); - std::pair GetMessage(); - bool WaitThread(); - int32_t GetCounter() const; - bool EndAllAction(); + bool Send(int64_t toPlayerID, std::string message, bool binary); + bool HaveMessage(); + std::pair GetMessage(); + bool WaitThread(); + int32_t GetCounter() const; + bool EndAllAction(); // IShipAPI使用的部分 - bool Move(int64_t time, double angle); - bool Recover(); - bool Produce(); - bool ReBuild(THUAI7::ConstructionType constructionType); - bool Construct(THUAI7::ConstructionType constructionType); - bool Attack(double angle); - [[nodiscard]] bool HaveView(int32_t gridX, int32_t gridY, int32_t selfX, int32_t selfY, int32_t viewRange) const; + bool Move(int64_t time, double angle); + bool Recover(); + bool Produce(); + bool ReBuild(THUAI7::ConstructionType constructionType); + bool Construct(THUAI7::ConstructionType constructionType); + bool Attack(double angle); + [[nodiscard]] bool HaveView(int32_t gridX, int32_t gridY, int32_t selfX, int32_t selfY, int32_t viewRange) const; // ITeamAPI - bool Recycle(int64_t playerID); - bool InstallModule(int64_t playerID, THUAI7::ModuleType moduleType); - bool BuildShip(THUAI7::ShipType shipType,int32_t cellX, int32_t cellY); + bool Recycle(int64_t playerID); + bool InstallModule(int64_t playerID, THUAI7::ModuleType moduleType); + bool BuildShip(THUAI7::ShipType shipType, int32_t cellX, int32_t cellY); bool TryConnection(); void ProcessMessage(); diff --git a/CAPI/cpp/API/include/structures.h b/CAPI/cpp/API/include/structures.h index 62359df5..a1aba408 100755 --- a/CAPI/cpp/API/include/structures.h +++ b/CAPI/cpp/API/include/structures.h @@ -261,7 +261,7 @@ namespace THUAI7 struct GameMap { - //x,y,id,hp + // x,y,id,hp std::map, std::pair> factoryState; std::map, std::pair> communityState; std::map, std::pair> fortState; @@ -284,73 +284,73 @@ namespace THUAI7 // 仅供DEBUG使用,名称可改动 // 还没写完,后面待续 - inline std::map gameStateDict{ - {GameState::NullGameState, "NullGameState"}, - {GameState::GameStart, "GameStart"}, - {GameState::GameRunning, "GameRunning"}, - {GameState::GameEnd, "GameEnd"}, - }; - - inline std::map shipTypeDict{ - {ShipType::NullShipType, "NullShipType"}, - {ShipType::CivilianShip, "CivilianShip"}, - {ShipType::MilitaryShip, "MilitaryShip"}, - {ShipType::FlagShip, "FlagShip"}, - }; - - inline std::map shipStateDict{ - {ShipState::NullStatus, "NullState"}, - {ShipState::Idle, "Idle"}, - {ShipState::Producing, "Producing"}, - {ShipState::Constructing, "Constructing"}, - {ShipState::Recovering, "Recoverying"}, - {ShipState::Recycling, "Recycling"}, - {ShipState::Attacking, "Attacking"}, - {ShipState::Swinging, "Swinging"}, - {ShipState::Stunned, "Stunned"}, - }; - - inline std::map playerTeamDict{ - {PlayerTeam::NullTeam, "NullTeam"}, - {PlayerTeam::Red, "Red"}, - {PlayerTeam::Blue, "Blue"}, - }; - - inline std::map placeTypeDict{ - {PlaceType::NullPlaceType, "NullPlaceType"}, - {PlaceType::Home, "Home"}, - {PlaceType::Space, "Space"}, - {PlaceType::Ruin, "Ruin"}, - {PlaceType::Shadow, "Shadow"}, - {PlaceType::Asteroid, "Asteroid"}, - {PlaceType::Resource, "Resource"}, - {PlaceType::Construction, "Construction"}, - }; - - inline std::map bulletTypeDict{ - {BulletType::NullBulletType, "NullBulletType"}, - {BulletType::Laser, "Laser"}, - {BulletType::Plasma, "Plasma"}, - {BulletType::Shell, "Shell"}, - {BulletType::Missile, "Missile"}, - {BulletType::Arc, "Arc"}, - }; - - inline std::map messageOfObjDict{ - {MessageOfObj::NullMessageOfObj, "NullMessageOfObj"}, - {MessageOfObj::ShipMessage, "ShipMessage"}, - {MessageOfObj::BulletMessage, "BulletMessage"}, - {MessageOfObj::FactoryMessage, "FactoryMessage"}, - {MessageOfObj::CommunityMessage, "CommunityMessage"}, - {MessageOfObj::FortMessage, "FortMessage"}, - {MessageOfObj::WormholeMessage, "WormholeMessage"}, - {MessageOfObj::HomeMessage, "HomeMessage"}, - {MessageOfObj::ResourceMessage, "ResourceMessage"}, - {MessageOfObj::MapMessage, "MapMessage"}, - {MessageOfObj::NewsMessage, "NewsMessage"}, - {MessageOfObj::BombedBulletMessage, "BombedBulletMessage"}, - {MessageOfObj::TeamMessage, "TeamMessage"}, - }; + inline std::map gameStateDict{ + {GameState::NullGameState, "NullGameState"}, + {GameState::GameStart, "GameStart"}, + {GameState::GameRunning, "GameRunning"}, + {GameState::GameEnd, "GameEnd"}, + }; + + inline std::map shipTypeDict{ + {ShipType::NullShipType, "NullShipType"}, + {ShipType::CivilianShip, "CivilianShip"}, + {ShipType::MilitaryShip, "MilitaryShip"}, + {ShipType::FlagShip, "FlagShip"}, + }; + + inline std::map shipStateDict{ + {ShipState::NullStatus, "NullState"}, + {ShipState::Idle, "Idle"}, + {ShipState::Producing, "Producing"}, + {ShipState::Constructing, "Constructing"}, + {ShipState::Recovering, "Recoverying"}, + {ShipState::Recycling, "Recycling"}, + {ShipState::Attacking, "Attacking"}, + {ShipState::Swinging, "Swinging"}, + {ShipState::Stunned, "Stunned"}, + }; + + inline std::map playerTeamDict{ + {PlayerTeam::NullTeam, "NullTeam"}, + {PlayerTeam::Red, "Red"}, + {PlayerTeam::Blue, "Blue"}, + }; + + inline std::map placeTypeDict{ + {PlaceType::NullPlaceType, "NullPlaceType"}, + {PlaceType::Home, "Home"}, + {PlaceType::Space, "Space"}, + {PlaceType::Ruin, "Ruin"}, + {PlaceType::Shadow, "Shadow"}, + {PlaceType::Asteroid, "Asteroid"}, + {PlaceType::Resource, "Resource"}, + {PlaceType::Construction, "Construction"}, + }; + + inline std::map bulletTypeDict{ + {BulletType::NullBulletType, "NullBulletType"}, + {BulletType::Laser, "Laser"}, + {BulletType::Plasma, "Plasma"}, + {BulletType::Shell, "Shell"}, + {BulletType::Missile, "Missile"}, + {BulletType::Arc, "Arc"}, + }; + + inline std::map messageOfObjDict{ + {MessageOfObj::NullMessageOfObj, "NullMessageOfObj"}, + {MessageOfObj::ShipMessage, "ShipMessage"}, + {MessageOfObj::BulletMessage, "BulletMessage"}, + {MessageOfObj::FactoryMessage, "FactoryMessage"}, + {MessageOfObj::CommunityMessage, "CommunityMessage"}, + {MessageOfObj::FortMessage, "FortMessage"}, + {MessageOfObj::WormholeMessage, "WormholeMessage"}, + {MessageOfObj::HomeMessage, "HomeMessage"}, + {MessageOfObj::ResourceMessage, "ResourceMessage"}, + {MessageOfObj::MapMessage, "MapMessage"}, + {MessageOfObj::NewsMessage, "NewsMessage"}, + {MessageOfObj::BombedBulletMessage, "BombedBulletMessage"}, + {MessageOfObj::TeamMessage, "TeamMessage"}, + }; } // namespace THUAI7 #endif diff --git a/CAPI/cpp/API/src/AI.cpp b/CAPI/cpp/API/src/AI.cpp index ff92a472..bb5b42e9 100755 --- a/CAPI/cpp/API/src/AI.cpp +++ b/CAPI/cpp/API/src/AI.cpp @@ -23,7 +23,6 @@ void AI::play(IShipAPI& api) { if (this->playerID == 0) { - } else if (this->playerID == 1) { diff --git a/CAPI/cpp/API/src/API.cpp b/CAPI/cpp/API/src/API.cpp index cd5016f3..dcb8a561 100755 --- a/CAPI/cpp/API/src/API.cpp +++ b/CAPI/cpp/API/src/API.cpp @@ -147,27 +147,27 @@ int32_t ShipAPI::GetConstructionHp(int32_t cellX, int32_t cellY) const int32_t TeamAPI::GetConstructionHp(int32_t cellX, int32_t cellY) const { - return logic.GetConstructionHp( cellX, cellY); + return logic.GetConstructionHp(cellX, cellY); } int32_t ShipAPI::GetWormHp(int32_t cellX, int32_t cellY) const { - return logic.GetWormHp(cellX, cellY); + return logic.GetWormHp(cellX, cellY); } int32_t TeamAPI::GetWormHp(int32_t cellX, int32_t cellY) const { - return logic.GetWormHp(cellX, cellY); + return logic.GetWormHp(cellX, cellY); } int32_t ShipAPI::GetResourceState(int32_t cellX, int32_t cellY) const { - return logic.GetResourceState(cellX, cellY); + return logic.GetResourceState(cellX, cellY); } int32_t TeamAPI::GetResourceState(int32_t cellX, int32_t cellY) const { - return logic.GetResourceState(cellX, cellY); + return logic.GetResourceState(cellX, cellY); } int32_t ShipAPI::GetHomeHp() const @@ -290,7 +290,7 @@ std::future ShipAPI::Construct(THUAI7::ConstructionType constructionType) bool ShipAPI::HaveView(int32_t gridX, int32_t gridY) const { auto selfInfo = GetSelfInfo(); - return logic.HaveView(gridX, gridY, selfInfo->x, selfInfo->y,selfInfo->viewRange); + return logic.HaveView(gridX, gridY, selfInfo->x, selfInfo->y, selfInfo->viewRange); } // Team独有 diff --git a/CAPI/cpp/API/src/Communication.cpp b/CAPI/cpp/API/src/Communication.cpp index 47ccc078..e45646aa 100755 --- a/CAPI/cpp/API/src/Communication.cpp +++ b/CAPI/cpp/API/src/Communication.cpp @@ -47,7 +47,7 @@ bool Communication::Send(int64_t playerID, int64_t toPlayerID, int64_t teamID, s } protobuf::BoolRes sendMessageResult; ClientContext context; - auto request = THUAI72Proto::THUAI72ProtobufSendMsg(playerID, toPlayerID, teamID, std::move(message),binary); + auto request = THUAI72Proto::THUAI72ProtobufSendMsg(playerID, toPlayerID, teamID, std::move(message), binary); auto status = THUAI7Stub->Send(&context, request, &sendMessageResult); if (status.ok()) return sendMessageResult.act_success(); diff --git a/CAPI/cpp/API/src/DebugAPI.cpp b/CAPI/cpp/API/src/DebugAPI.cpp index 16549909..413fc7dc 100755 --- a/CAPI/cpp/API/src/DebugAPI.cpp +++ b/CAPI/cpp/API/src/DebugAPI.cpp @@ -246,8 +246,8 @@ void ShipDebugAPI::PrintShip() const for (const auto& Ship : logic.GetShips()) { logger->info("******Ship Info******"); - logger->info("type={}, playerID={}, GUID={}, x={}, y={}", THUAI7::shipTypeDict[Ship->shipType],Ship->playerID, Ship->guid, Ship->x, Ship->y); - logger->info("state={},speed={}, view range={},facing direction={}", THUAI7::shipStateDict[Ship->shipState],Ship->speed, Ship->viewRange,Ship->facingDirection); + logger->info("type={}, playerID={}, GUID={}, x={}, y={}", THUAI7::shipTypeDict[Ship->shipType], Ship->playerID, Ship->guid, Ship->x, Ship->y); + logger->info("state={},speed={}, view range={},facing direction={}", THUAI7::shipStateDict[Ship->shipState], Ship->speed, Ship->viewRange, Ship->facingDirection); logger->info("************************\n"); } } @@ -421,7 +421,7 @@ int32_t TeamDebugAPI::GetScore() const std::future TeamDebugAPI::InstallModule(int64_t playerID, THUAI7::ModuleType moduleType) { return std::async(std::launch::async, [=]() - { return logic.InstallModule(playerID, moduleType);}); + { return logic.InstallModule(playerID, moduleType); }); } void TeamDebugAPI::PrintSelfInfo() const { diff --git a/CAPI/cpp/API/src/logic.cpp b/CAPI/cpp/API/src/logic.cpp index c4861652..fee7d5a0 100755 --- a/CAPI/cpp/API/src/logic.cpp +++ b/CAPI/cpp/API/src/logic.cpp @@ -278,7 +278,7 @@ void Logic::ProcessMessage() { try { - //TODO + // TODO int32_t x = 0; int32_t y = 0; logger->info("Message thread start!"); @@ -419,19 +419,19 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } break; case THUAI7::MessageOfObj::BulletMessage: - if (AssistFunction::HaveView(x, y, item.bullet_message().x(), item.bullet_message().y(),viewRange, bufferState->gameMap)) + if (AssistFunction::HaveView(x, y, item.bullet_message().x(), item.bullet_message().y(), viewRange, bufferState->gameMap)) { bufferState->bullets.push_back(Proto2THUAI7::Protobuf2THUAI7Bullet(item.bullet_message())); logger->debug("Add Bullet!"); } break; case THUAI7::MessageOfObj::FactoryMessage: - if (AssistFunction::HaveView(x, y, item.factory_message().x(), item.factory_message().y(),viewRange, bufferState->gameMap)) + if (AssistFunction::HaveView(x, y, item.factory_message().x(), item.factory_message().y(), viewRange, bufferState->gameMap)) { auto pos = std::make_pair(AssistFunction::GridToCell(item.factory_message().x()), AssistFunction::GridToCell(item.factory_message().y())); if (bufferState->mapInfo->factoryState.count(pos) == 0) { - bufferState->mapInfo->factoryState.emplace(pos, std::make_pair(item.factory_message().team_id() ,item.factory_message().hp())); + bufferState->mapInfo->factoryState.emplace(pos, std::make_pair(item.factory_message().team_id(), item.factory_message().hp())); logger->debug("Add Factory!"); } else @@ -442,7 +442,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } break; case THUAI7::MessageOfObj::CommunityMessage: - if (AssistFunction::HaveView(x, y, item.community_message().x(), item.community_message().y(),viewRange, bufferState->gameMap)) + if (AssistFunction::HaveView(x, y, item.community_message().x(), item.community_message().y(), viewRange, bufferState->gameMap)) { auto pos = std::make_pair(AssistFunction::GridToCell(item.community_message().x()), AssistFunction::GridToCell(item.community_message().y())); if (bufferState->mapInfo->communityState.count(pos) == 0) @@ -458,7 +458,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } break; case THUAI7::MessageOfObj::FortMessage: - if (AssistFunction::HaveView(x, y, item.fort_message().x(), item.fort_message().y(),viewRange, bufferState->gameMap)) + if (AssistFunction::HaveView(x, y, item.fort_message().x(), item.fort_message().y(), viewRange, bufferState->gameMap)) { auto pos = std::make_pair(AssistFunction::GridToCell(item.fort_message().x()), AssistFunction::GridToCell(item.fort_message().y())); if (bufferState->mapInfo->fortState.count(pos) == 0) @@ -474,7 +474,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } break; case THUAI7::MessageOfObj::WormholeMessage: - if (AssistFunction::HaveView(x, y, item.wormhole_message().x(), item.wormhole_message().y(),viewRange, bufferState->gameMap)) + if (AssistFunction::HaveView(x, y, item.wormhole_message().x(), item.wormhole_message().y(), viewRange, bufferState->gameMap)) { auto pos = std::make_pair(AssistFunction::GridToCell(item.wormhole_message().x()), AssistFunction::GridToCell(item.wormhole_message().y())); if (bufferState->mapInfo->wormholeState.count(pos) == 0) @@ -490,7 +490,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } break; case THUAI7::MessageOfObj::ResourceMessage: - if (AssistFunction::HaveView(x, y, item.resource_message().x(), item.resource_message().y(),viewRange, bufferState->gameMap)) + if (AssistFunction::HaveView(x, y, item.resource_message().x(), item.resource_message().y(), viewRange, bufferState->gameMap)) { auto pos = std::make_pair(AssistFunction::GridToCell(item.resource_message().x()), AssistFunction::GridToCell(item.resource_message().y())); if (bufferState->mapInfo->resourceState.count(pos) == 0) @@ -528,7 +528,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::NullMessageOfObj: default: break; - } + } } } @@ -550,9 +550,9 @@ void Logic::LoadBuffer(const protobuf::MessageToClient& message) for (const auto& obj : message.obj_message()) if (Proto2THUAI7::messageOfObjDict[obj.message_of_obj_case()] == THUAI7::MessageOfObj::ShipMessage) bufferState->guids.push_back(obj.ship_message().guid()); - //TODO - //else if (Proto2THUAI7::messageOfObjDict[obj.message_of_obj_case()] == THUAI7::MessageOfObj::HomeMessage) - // bufferState->guids.push_back(obj.home_message().guid()); + // TODO + // else if (Proto2THUAI7::messageOfObjDict[obj.message_of_obj_case()] == THUAI7::MessageOfObj::HomeMessage) + // bufferState->guids.push_back(obj.home_message().guid()); bufferState->gameInfo = Proto2THUAI7::Protobuf2THUAI7GameInfo(message.all_message()); LoadBufferSelf(message); for (const auto& item : message.obj_message()) @@ -628,13 +628,13 @@ std::vector Logic::GetPlayerGUIDs() const bool Logic::TryConnection() { logger->info("Try to connect to server..."); - return pComm->TryConnection(playerID,teamID); + return pComm->TryConnection(playerID, teamID); } -bool Logic::HaveView(int32_t gridX, int32_t gridY, int32_t selfX, int32_t selfY,int32_t viewRange) const +bool Logic::HaveView(int32_t gridX, int32_t gridY, int32_t selfX, int32_t selfY, int32_t viewRange) const { std::unique_lock lock(mtxState); - return AssistFunction::HaveView(selfX, selfY, gridX, gridY,viewRange,currentState->gameMap); + return AssistFunction::HaveView(selfX, selfY, gridX, gridY, viewRange, currentState->gameMap); } void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port, bool file, bool print, bool warnOnly) @@ -662,7 +662,7 @@ void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port, bool f logger->info("*********Basic Info*********"); logger->info("asynchronous: {}", asynchronous); logger->info("server: {}:{}", IP, port); - if (playerType==THUAI7::PlayerType::Ship) + if (playerType == THUAI7::PlayerType::Ship) logger->info("ship ID: {}", playerID); else logger->info("home ID: {}", playerID); @@ -675,7 +675,7 @@ void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port, bool f // 构造timer if (playerTeam == THUAI7::PlayerTeam::Red) { - if (playerType==THUAI7::PlayerType::Ship) + if (playerType == THUAI7::PlayerType::Ship) { if (!file && !print) timer = std::make_unique(*this); @@ -692,7 +692,7 @@ void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port, bool f } else if (playerTeam == THUAI7::PlayerTeam::Blue) { - if (playerType==THUAI7::PlayerType::Ship) + if (playerType == THUAI7::PlayerType::Ship) { if (!file && !print) timer = std::make_unique(*this);