Skip to content

Commit

Permalink
Merge pull request #60 from sigureling/dev
Browse files Browse the repository at this point in the history
cpp CAPI
  • Loading branch information
panxuc authored Dec 30, 2023
2 parents 9a5e99c + b2c7884 commit cdc279b
Show file tree
Hide file tree
Showing 32 changed files with 6,987 additions and 9,640 deletions.
4 changes: 2 additions & 2 deletions CAPI/cpp/API/include/AI.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class IAI
virtual ~IAI() = default;
IAI() = default;
virtual void play(IShipAPI& api) = 0;
virtual void play(IHomeAPI& api) = 0;
virtual void play(ITeamAPI& api) = 0;
};

using CreateAIFunc = std::unique_ptr<IAI> (*)(int64_t playerID);
Expand All @@ -28,7 +28,7 @@ class AI : public IAI
{
}
void play(IShipAPI& api) override;
void play(IHomeAPI& api) override;
void play(ITeamAPI& api) override;

private:
int64_t playerID;
Expand Down
311 changes: 158 additions & 153 deletions CAPI/cpp/API/include/API.h

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions CAPI/cpp/API/include/Communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ class Communication
~Communication()
{
}
bool TryConnection(int64_t playerID);
bool TryConnection(int64_t playerID, int64_t teamID);
protobuf::MessageToClient GetMessage2Client();
void AddPlayer(int64_t playerID, THUAI7::PlayerType playerType, THUAI7::ShipType shipType);
bool EndAllAction(int64_t playerID);
//
bool Move(int64_t time, double angle, int64_t playerID);
bool Recover(int64_t playerID);
bool Produce(int64_t playerID, int32_t x, int32_t y);
bool Rebuild(int64_t playerID, int32_t x, int32_t y);
bool Construct(int64_t playerID, THUAI7::BuildingType buidingType, int32_t x, int32_t y);
bool Attack(double angle, int64_t playerID);

// 大本营
bool InstallModule(THUAI7::Module module, int64_t playerID);
void AddPlayer(int64_t playerID, int64_t teamID, THUAI7::ShipType shipType, int32_t x, int32_t y);
bool EndAllAction(int64_t playerID, int64_t teamID);
// Ship
bool Move(int64_t playerID, int64_t teamID, int64_t time, double angle);
bool Recover(int64_t playerID, int64_t teamID);
bool Produce(int64_t playerID, int64_t teamID);
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 Recycle(int64_t playerID);
bool Recycle(int64_t playerID, int64_t teamID);

private:
std::unique_ptr<protobuf::AvailableService::Stub> THUAI7Stub;
Expand Down
78 changes: 39 additions & 39 deletions CAPI/cpp/API/include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ namespace Constants
SCCI double recycleMultiplier = 0.5;
struct Home
{
SCCI int32_t Hp = 24000;
SCCI int32_t economy = 1;
SCCI int32_t maxHp = 24000;
SCCI int32_t moneySpeed = 1;
};
struct Factory
{
SCCI int32_t Hp = 8000;
SCCI int32_t economy = 3;
SCCI int32_t maxHp = 8000;
SCCI int32_t moneySpeed = 3;
};
struct Community
{
SCCI int32_t Hp = 6000;
SCCI int32_t maxHp = 6000;
};
struct Fortress
struct Fort
{
SCCI int32_t Hp = 12000;
SCCI int32_t maxHp = 12000;
SCCI int32_t attackRange = 8000;
SCCI int32_t damage = 1200;
};
Expand All @@ -48,73 +48,73 @@ namespace Constants
SCCI int32_t sizeofShip = 800;
struct CivilianShip
{
SCCI int32_t Hp = 3000;
SCCI int32_t maxHp = 3000;
SCCI int32_t basicArmor = 0;
SCCI int32_t basicShield = 0;
SCCI int32_t Speed = 3000;
SCCI int32_t Cost = 40;
};
struct MilitaryShip
{
SCCI int32_t Hp = 4000;
SCCI int32_t maxHp = 4000;
SCCI int32_t basicArmor = 400;
SCCI int32_t basicShield = 400;
SCCI int32_t Speed = 2800;
SCCI int32_t Cost = 120;
};
struct FlagShip
{
SCCI int32_t Hp = 12000;
SCCI int32_t maxHp = 12000;
SCCI int32_t basicArmor = 800;
SCCI int32_t basicShield = 800;
SCCI int32_t Speed = 2700;
SCCI int32_t Cost = 500;
};

// 模块
struct Collector
struct Producer
{
SCCI int32_t basicEconomy = 5;
SCCI int32_t advancedEconomy = 7;
SCCI int32_t ultimateEconomy = 10;
SCCI int32_t basicCost = 0;
SCCI int32_t advancedCost = 40;
SCCI int32_t ultimateCost = 80;
SCCI int32_t moneySpeed1 = 5;
SCCI int32_t moneySpeed2 = 7;
SCCI int32_t moneySpeed3 = 10;
SCCI int32_t Cost1 = 0;
SCCI int32_t Cost2 = 40;
SCCI int32_t Cost3 = 80;
};
struct Builder
struct Constructor
{
SCCI int32_t basicBuildSpeed = 500;
SCCI int32_t advancedBuildSpeed = 750;
SCCI int32_t ultimateBuildSpeed = 1000;
SCCI int32_t basicCost = 0;
SCCI int32_t advancedCost = 40;
SCCI int32_t ultimateCost = 80;
SCCI int32_t constructSpeed1 = 500;
SCCI int32_t constructSpeed2 = 750;
SCCI int32_t constructSpeed3 = 1000;
SCCI int32_t Cost1 = 0;
SCCI int32_t Cost2 = 40;
SCCI int32_t Cost3 = 80;
};
struct Armor
{
SCCI int32_t basicArmor = 2000;
SCCI int32_t advancedArmor = 3000;
SCCI int32_t ultimateArmor = 4000;
SCCI int32_t basicCost = 60;
SCCI int32_t advancedCost = 120;
SCCI int32_t ultimateCost = 180;
SCCI int32_t armor1 = 2000;
SCCI int32_t armor2 = 3000;
SCCI int32_t armor3 = 4000;
SCCI int32_t Cost1 = 60;
SCCI int32_t Cost2 = 120;
SCCI int32_t Cost3 = 180;
};
struct Shield
{
SCCI int32_t basicShield = 2000;
SCCI int32_t advancedShield = 3000;
SCCI int32_t ultimateShield = 4000;
SCCI int32_t basicCost = 60;
SCCI int32_t advancedCost = 120;
SCCI int32_t ultimateCost = 180;
SCCI int32_t shield1 = 2000;
SCCI int32_t shield2 = 3000;
SCCI int32_t shield3 = 4000;
SCCI int32_t Cost1 = 60;
SCCI int32_t Cost2 = 120;
SCCI int32_t Cost3 = 180;
};
struct Weapon
{
SCCI int32_t LaserCost = 0;
SCCI int32_t PlasmaCost = 120;
SCCI int32_t ShellCost = 130;
SCCI int32_t MissileCost = 180;
SCCI int32_t ElectricArc = 240;
SCCI int32_t ArcCost = 240;
};

// 子弹
Expand Down Expand Up @@ -154,12 +154,12 @@ namespace Constants
SCCI int32_t AttackRange = 8000;
SCCI int32_t ExplodeRange = 1600;
SCCI double ArmorDamageMultiplier = 1.0;
// SCCI double ShieldDamageMultiplier = 0.4;
SCCI double ShieldDamageMultiplier = 0.4;
SCCI int32_t Speed = 6000;
SCCI int32_t CastTime = 600; // ms
SCCI int32_t BackSwing = 600;
};
struct ElectricArc
struct Arc
{
SCCI int32_t Damage = 3200; // 100-3200
SCCI int32_t AttackRange = 8000;
Expand Down
69 changes: 38 additions & 31 deletions CAPI/cpp/API/include/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class Logic : public ILogic

// ID
THUAI7::PlayerType playerType;
int64_t player_id;
int64_t playerID;
int64_t teamID;
THUAI7::PlayerTeam playerTeam;
THUAI7::ShipType shipType;

std::unique_ptr<IGameTimer> timer;
Expand Down Expand Up @@ -88,39 +90,44 @@ class Logic : public ILogic

// 提供给API使用的函数

[[nodiscard]] std::vector<std::shared_ptr<const THUAI7::Ship>> GetShips() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI7::Ship>> GetEnemyShip() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI7::Bullet>> GetBullets() const override;
[[nodiscard]] std::shared_ptr<const THUAI7::Ship> GetSelfInfo() const override;
[[nodiscard]] std::shared_ptr<const THUAI7::Home> GetSelfInfo() 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]] int32_t GetBuildingHp(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetWormHp(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::shared_ptr<const THUAI7::GameInfo> GetGameInfo() const override;
[[nodiscard]] int32_t GetEconomy() const override;
[[nodiscard]] virtual std::vector<std::shared_ptr<const THUAI7::Ship>> GetShips() const = 0;
[[nodiscard]] virtual std::vector<std::shared_ptr<const THUAI7::Ship>> GetEnemyShips() const = 0;
[[nodiscard]] virtual std::vector<std::shared_ptr<const THUAI7::Bullet>> GetBullets() const = 0;
[[nodiscard]] virtual std::shared_ptr<const THUAI7::Ship> ShipGetSelfInfo() const = 0;
[[nodiscard]] virtual std::shared_ptr<const THUAI7::Team> TeamGetSelfInfo() const = 0;
[[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::vector<int64_t> 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;

// 供IAPI使用的操作相关的部分
bool Move(int64_t time, double angle) override;
bool SendMessage(int64_t toID, std::string message, bool binary) override;
bool HaveMessage() override;
std::pair<int64_t, std::string> GetMessage() override;

int32_t GetCounter() const override;
virtual bool Send(int64_t toPlayerID, std::string message, bool binary) = 0;
virtual bool HaveMessage() = 0;
virtual std::pair<int64_t, std::string> GetMessage() = 0;
virtual bool WaitThread() = 0;
virtual int32_t GetCounter() const = 0;
virtual bool EndAllAction() = 0;

// IShipAPI使用的部分
bool Recover() override;
bool Recycle() override;
bool Produce(int32_t x, int32_t y) override;
bool Rebuild(int32_t cellX, int32_t cellY) override;
bool InstallModule(THUAI7::Module module) override;
bool EndAllAction() override;
bool Attack(double angle) override;
std::vector<int64_t> GetShipGUIDs() const override;
[[nodiscard]] bool HaveView(int32_t gridX, int32_t gridY, int32_t selfX, int32_t selfY, int32_t viewRange) const override;

bool WaitThread() override;
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;

// 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 TryConnection();
void ProcessMessage();

Expand All @@ -140,7 +147,7 @@ class Logic : public ILogic

public:
// 构造函数还需要传更多参数,有待补充
Logic(int64_t playerID, THUAI7::PlayerType player_type, THUAI7::ShipType shipType);
Logic(int64_t playerID, int64_t teamID, THUAI7::PlayerType playerType, THUAI7::ShipType shipType);

~Logic()
{
Expand Down
4 changes: 2 additions & 2 deletions CAPI/cpp/API/include/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ struct State
{
// 自身信息,根据playerType的不同,可以调用的值也不同。
std::shared_ptr<THUAI7::Ship> shipSelf;
std::shared_ptr<THUAI7::Home> homeSelf;
std::shared_ptr<THUAI7::Team> teamSelf;

std::vector<std::shared_ptr<THUAI7::Ship>> ships;
std::vector<std::shared_ptr<THUAI7::Ship>> enemyships;
std::vector<std::shared_ptr<THUAI7::Home>> homes;
std::vector<std::shared_ptr<THUAI7::Team>> teams;
std::vector<std::shared_ptr<THUAI7::Bullet>> bullets;

std::vector<std::vector<THUAI7::PlaceType>> gameMap;
Expand Down
Loading

0 comments on commit cdc279b

Please sign in to comment.