Skip to content

Commit

Permalink
Merge branch 'dev' of ssh://ssh.github.com:443/hhzzff/THUAI7 into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
hhzzff committed May 25, 2024
2 parents 4a548ce + 3e201cf commit fac8b6e
Show file tree
Hide file tree
Showing 55 changed files with 2,307 additions and 548 deletions.
20 changes: 14 additions & 6 deletions CAPI/cpp/API/include/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ILogic
[[nodiscard]] virtual std::shared_ptr<const THUAI7::GameInfo> GetGameInfo() const = 0;
[[nodiscard]] virtual std::vector<int64_t> GetPlayerGUIDs() const = 0;
[[nodiscard]] virtual THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual std::optional<THUAI7::ConstructionState> GetConstructionState(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetWormholeHp(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetResourceState(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetHomeHp() const = 0;
Expand All @@ -64,6 +64,8 @@ class ILogic
virtual bool Move(int64_t time, double angle) = 0;
virtual bool Recover(int64_t recover) = 0;
virtual bool Produce() = 0;
virtual bool RepairWormhole() = 0;
virtual bool RepairHome() = 0;
virtual bool Rebuild(THUAI7::ConstructionType constructionType) = 0;
virtual bool Construct(THUAI7::ConstructionType constructionType) = 0;
virtual bool Attack(double angle) = 0;
Expand Down Expand Up @@ -97,7 +99,7 @@ class IAPI
[[nodiscard]] virtual std::vector<std::vector<THUAI7::PlaceType>> GetFullMap() const = 0;
[[nodiscard]] virtual std::shared_ptr<const THUAI7::GameInfo> GetGameInfo() const = 0;
[[nodiscard]] virtual THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual std::optional<THUAI7::ConstructionState> GetConstructionState(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetWormholeHp(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetResourceState(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetHomeHp() const = 0;
Expand Down Expand Up @@ -139,6 +141,8 @@ class IShipAPI : public IAPI
virtual std::future<bool> Attack(double angleInRadian) = 0;
virtual std::future<bool> Recover(int64_t recover) = 0;
virtual std::future<bool> Produce() = 0;
virtual std::future<bool> RepairWormhole() = 0;
virtual std::future<bool> RepairHome() = 0;
virtual std::future<bool> Rebuild(THUAI7::ConstructionType constructionType) = 0;
virtual std::future<bool> Construct(THUAI7::ConstructionType constructionType) = 0;
virtual std::shared_ptr<const THUAI7::Ship> GetSelfInfo() const = 0;
Expand Down Expand Up @@ -195,6 +199,8 @@ class ShipAPI : public IShipAPI, public IGameTimer
std::future<bool> Attack(double angleInRadian) override;
std::future<bool> Recover(int64_t recover) override;
std::future<bool> Produce() override;
std::future<bool> RepairWormhole() override;
std::future<bool> RepairHome() override;
std::future<bool> Rebuild(THUAI7::ConstructionType constructionType) override;
std::future<bool> Construct(THUAI7::ConstructionType constructionType) override;

Expand All @@ -203,7 +209,7 @@ class ShipAPI : public IShipAPI, public IGameTimer
[[nodiscard]] std::vector<std::shared_ptr<const THUAI7::Bullet>> GetBullets() const override;
[[nodiscard]] std::vector<std::vector<THUAI7::PlaceType>> GetFullMap() const override;
[[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::optional<THUAI7::ConstructionState> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::shared_ptr<const THUAI7::GameInfo> GetGameInfo() const override;
Expand Down Expand Up @@ -259,7 +265,7 @@ class TeamAPI : public ITeamAPI, public IGameTimer
[[nodiscard]] std::vector<std::shared_ptr<const THUAI7::Bullet>> GetBullets() const override;
[[nodiscard]] std::vector<std::vector<THUAI7::PlaceType>> GetFullMap() const override;
[[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::optional<THUAI7::ConstructionState> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetHomeHp() const override;
Expand Down Expand Up @@ -312,6 +318,8 @@ class ShipDebugAPI : public IShipAPI, public IGameTimer
std::future<bool> Attack(double angleInRadian) override;
std::future<bool> Recover(int64_t recover) override;
std::future<bool> Produce() override;
std::future<bool> RepairWormhole() override;
std::future<bool> RepairHome() override;
std::future<bool> Rebuild(THUAI7::ConstructionType constructionType) override;
std::future<bool> Construct(THUAI7::ConstructionType constructionType) override;

Expand All @@ -320,7 +328,7 @@ class ShipDebugAPI : public IShipAPI, public IGameTimer
[[nodiscard]] std::vector<std::shared_ptr<const THUAI7::Bullet>> GetBullets() const override;
[[nodiscard]] std::vector<std::vector<THUAI7::PlaceType>> GetFullMap() const override;
[[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::optional<THUAI7::ConstructionState> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetHomeHp() const override;
Expand Down Expand Up @@ -366,7 +374,7 @@ class TeamDebugAPI : public ITeamAPI, public IGameTimer
[[nodiscard]] std::vector<std::shared_ptr<const THUAI7::Bullet>> GetBullets() const override;
[[nodiscard]] std::vector<std::vector<THUAI7::PlaceType>> GetFullMap() const override;
[[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::optional<THUAI7::ConstructionState> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetHomeHp() const override;
Expand Down
10 changes: 5 additions & 5 deletions CAPI/cpp/API/include/Communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class Communication
{
public:
Communication(std::string sIP, std::string sPort);
~Communication()
{
}
~Communication() = default;
bool TryConnection(int32_t playerID, int32_t teamID);
protobuf::MessageToClient GetMessage2Client();
void AddPlayer(int32_t playerID, int32_t teamID, THUAI7::ShipType ShipType);
Expand All @@ -35,6 +33,8 @@ class Communication
bool Move(int32_t playerID, int32_t teamID, int64_t time, double angle);
bool Recover(int32_t playerID, int64_t recover, int32_t teamID);
bool Produce(int32_t playerID, int32_t teamID);
bool RepairWormhole(int32_t playerID, int32_t teamID);
bool RepairHome(int32_t playerID, int32_t teamID);
bool Rebuild(int32_t playerID, int32_t teamID, THUAI7::ConstructionType constructionType);
bool Construct(int32_t playerID, int32_t teamID, THUAI7::ConstructionType constructionType);
bool Attack(int32_t playerID, int32_t teamID, double angle);
Expand All @@ -50,8 +50,8 @@ class Communication
protobuf::MessageToClient message2Client;
std::mutex mtxMessage;
std::mutex mtxLimit;
int32_t counter;
int32_t counterMove;
int32_t counter{};
int32_t counterMove{};
static constexpr const int32_t limit = 50;
static constexpr const int32_t moveLimit = 10;
std::condition_variable cvMessage;
Expand Down
51 changes: 27 additions & 24 deletions CAPI/cpp/API/include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,33 @@ namespace Constants
SCCI int32_t numOfGridPerCell = 1000; // 单位坐标数
SCCI int32_t rows = 50; // 地图行数
SCCI int32_t cols = 50; // 地图列数
SCCI int32_t maxResourceProgress = 200;
SCCI int32_t maxResourceProgress = 32000;
SCCI int32_t maxWormholeHp = 18000;
SCCI double robPercent = 0.2; // 击杀获得经济比率
SCCI int32_t DestroyBuildingBonus = 200;
SCCI double recoverMultiplier = 1.2;
SCCI double recycleMultiplier = 0.5;
struct Home
{
SCCI int32_t maxHp = 24000;
SCCI int32_t maxHp = 48000;
SCCI int32_t energySpeed = 100;
SCCI int32_t attackRange = 8000;
SCCI int32_t damage = 300;
};
struct Factory
{
SCCI int32_t maxHp = 8000;
SCCI int32_t energySpeed = 300;
SCCI int32_t maxHp = 12000;
SCCI int32_t energySpeed = 200;
};
struct Community
{
SCCI int32_t maxHp = 6000;
SCCI int32_t maxHp = 10000;
};
struct Fort
{
SCCI int32_t maxHp = 12000;
SCCI int32_t maxHp = 16000;
SCCI int32_t attackRange = 8000;
SCCI int32_t damage = 1200;
SCCI int32_t damage = 300;
};

//
Expand Down Expand Up @@ -120,54 +122,55 @@ namespace Constants
// 子弹
struct Laser
{
SCCI int32_t Damage = 1200;
SCCI int32_t Damage = 800;
SCCI int32_t AttackRange = 4000;
SCCI double ArmorDamageMultiplier = 1.5;
SCCI double ShieldDamageMultiplier = 0.6;
SCCI int32_t Speed = 20000;
SCCI int32_t CastTime = 300; // ms
SCCI int32_t BackSwing = 300;
SCCI int32_t CastTime = 500; // ms
SCCI int32_t BackSwing = 1000;
};
struct Plasma
{
SCCI int32_t Damage = 1300;
SCCI int32_t Damage = 1000;
SCCI int32_t AttackRange = 4000;
SCCI double ArmorDamageMultiplier = 2.0;
SCCI double ShieldDamageMultiplier = 0.4;
SCCI int32_t Speed = 10000;
SCCI int32_t CastTime = 400; // ms
SCCI int32_t BackSwing = 400;
SCCI int32_t CastTime = 800; // ms
SCCI int32_t BackSwing = 1600;
};
struct Shell
{
SCCI int32_t Damage = 1800;
SCCI int32_t Damage = 1200;
SCCI int32_t AttackRange = 4000;
SCCI double ArmorDamageMultiplier = 0.4;
SCCI double ShieldDamageMultiplier = 1.5;
SCCI int32_t Speed = 8000;
SCCI int32_t CastTime = 200; // ms
SCCI int32_t BackSwing = 200;
SCCI int32_t CastTime = 500; // ms
SCCI int32_t BackSwing = 1000;
};
struct Missile
{
SCCI int32_t Damage = 1600;
SCCI int32_t AttackRange = 8000;
SCCI int32_t ExplodeRange = 1600;
SCCI int32_t AttackRange = 6000;
SCCI int32_t ExplodeRange = 1100;
SCCI double ArmorDamageMultiplier = 1.0;
SCCI double ShieldDamageMultiplier = 0.4;
SCCI int32_t Speed = 6000;
SCCI int32_t CastTime = 600; // ms
SCCI int32_t BackSwing = 600;
SCCI int32_t CastTime = 1200; // ms
SCCI int32_t BackSwing = 1800;
};
struct Arc
{
SCCI int32_t Damage = 3200; // 100-3200
SCCI int32_t AttackRange = 8000;
SCCI int32_t MinDamage = 800;
SCCI int32_t MaxDamage = 1600;
SCCI int32_t AttackRange = 6000;
SCCI double ArmorDamageMultiplier = 2.0;
SCCI double ShieldDamageMultiplier = 2.0;
SCCI int32_t Speed = 8000;
SCCI int32_t CastTime = 600; // ms
SCCI int32_t BackSwing = 600;
SCCI int32_t CastTime = 1200; // ms
SCCI int32_t BackSwing = 1800;
};
} // namespace Constants
#endif
7 changes: 5 additions & 2 deletions CAPI/cpp/API/include/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <iostream>
#include <vector>
#include <optional>
#include <thread>
#include <mutex>
#include <condition_variable>
Expand Down Expand Up @@ -62,7 +63,7 @@ class Logic : public ILogic
std::condition_variable cvAI;

// 信息队列
ConcurrentQueue<std::pair<int32_t, std::string>> messageQueue;
ConcurrentQueue<std::pair<int64_t, std::string>> messageQueue;

// 存储状态,分别是现在的状态和缓冲区的状态。
State state[2];
Expand Down Expand Up @@ -98,7 +99,7 @@ class Logic : public ILogic
[[nodiscard]] std::shared_ptr<const THUAI7::GameInfo> GetGameInfo() const;
[[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const;
[[nodiscard]] std::vector<int64_t> GetPlayerGUIDs() const;
[[nodiscard]] std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const;
[[nodiscard]] std::optional<THUAI7::ConstructionState> GetConstructionState(int32_t cellX, int32_t cellY) const;
[[nodiscard]] int32_t GetWormholeHp(int32_t cellX, int32_t cellY) const;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const;
[[nodiscard]] int32_t GetHomeHp() const;
Expand All @@ -117,6 +118,8 @@ class Logic : public ILogic
bool Move(int64_t time, double angle);
bool Recover(int64_t recover);
bool Produce();
bool RepairWormhole();
bool RepairHome();
bool Rebuild(THUAI7::ConstructionType constructionType);
bool Construct(THUAI7::ConstructionType constructionType);
bool Attack(double angle);
Expand Down
52 changes: 33 additions & 19 deletions CAPI/cpp/API/include/structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

namespace THUAI7
{

// 游戏状态
enum class GameState : unsigned char
{
Expand Down Expand Up @@ -197,8 +196,8 @@ namespace THUAI7
int32_t hp; // 血量
int32_t armor; // 装甲
int32_t shield; // 护盾
int32_t playerID; // 船的id
int32_t teamID;
int64_t playerID; // 船的id
int64_t teamID;
int64_t guid; // 全局唯一ID
ShipState shipState; // 船所处状态
ShipType shipType;
Expand All @@ -213,18 +212,18 @@ namespace THUAI7

struct Team
{
int32_t playerID;
int32_t teamID;
int32_t score;
int32_t energy;
int64_t playerID;
int64_t teamID;
int64_t score;
int64_t energy;
};

struct Home
{
int32_t x;
int32_t y;
int32_t hp;
int32_t teamID;
int64_t teamID;
int64_t guid;
};

Expand All @@ -234,13 +233,25 @@ namespace THUAI7
int32_t y; // y坐标
double facingDirection; // 朝向
int64_t guid; //
int32_t teamID; // 子弹所属队伍
int64_t teamID; // 子弹所属队伍
BulletType bulletType; // 子弹类型
int32_t damage; // 伤害值
int32_t attackRange;
int32_t bombRange;
double explodeRange; // 炸弹爆炸范围
int32_t speed; // 子弹速度
double bombRange; // 炸弹爆炸范围
int32_t speed; // 子弹速度
};

struct ConstructionState
{
int64_t teamID;
int32_t hp;
ConstructionType constructionType;
ConstructionState(std::pair<int64_t, int32_t> teamHP, ConstructionType type) :
teamID(teamHP.first),
hp(teamHP.second),
constructionType(type)
{
}
};

// struct BombedBullet
Expand All @@ -253,15 +264,17 @@ namespace THUAI7
// double bombRange,
// };

using cellxy_t = std::pair<int32_t, int32_t>;

struct GameMap
{
// x,y,id,hp
std::map<std::pair<int32_t, int32_t>, std::pair<int32_t, int32_t>> factoryState;
std::map<std::pair<int32_t, int32_t>, std::pair<int32_t, int32_t>> communityState;
std::map<std::pair<int32_t, int32_t>, std::pair<int32_t, int32_t>> fortState;
std::map<std::pair<int32_t, int32_t>, std::pair<int32_t, int32_t>> homeState;
std::map<std::pair<int32_t, int32_t>, int32_t> wormholeState;
std::map<std::pair<int32_t, int32_t>, int32_t> resourceState;
std::map<cellxy_t, std::pair<int64_t, int32_t>> factoryState;
std::map<cellxy_t, std::pair<int64_t, int32_t>> communityState;
std::map<cellxy_t, std::pair<int64_t, int32_t>> fortState;
std::map<cellxy_t, std::pair<int64_t, int32_t>> homeState;
std::map<cellxy_t, int32_t> wormholeState;
std::map<cellxy_t, int32_t> resourceState;
};

struct GameInfo
Expand Down Expand Up @@ -355,7 +368,8 @@ namespace THUAI7
{ModuleType::ModulePlasmaGun, "ModulePlasmaGun"},
{ModuleType::ModuleShellGun, "ModuleShellGun"},
{ModuleType::ModuleMissileGun, "ModuleMissileGun"},
{ModuleType::ModuleArcGun, "ModuleArcGun"}};
{ModuleType::ModuleArcGun, "ModuleArcGun"},
};

inline std::map<MessageOfObj, std::string> messageOfObjDict{
{MessageOfObj::NullMessageOfObj, "NullMessageOfObj"},
Expand Down
Loading

0 comments on commit fac8b6e

Please sign in to comment.