Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加API.cpp #59

Merged
merged 10 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CAPI/cpp/API/include/AI.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class IAI
public:
virtual ~IAI() = default;
IAI() = default;
virtual void play(IShipAPI& api) = 0;
virtual void play(ICharacterAPI& api) = 0;
virtual void play(ITeamAPI& api) = 0;
};

Expand All @@ -27,7 +27,7 @@ class AI : public IAI
playerID(pID)
{
}
void play(IShipAPI& api) override;
void play(ICharacterAPI& api) override;
void play(ITeamAPI& api) override;

private:
Expand Down
8 changes: 4 additions & 4 deletions CAPI/cpp/API/include/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class IAPI
// 用于DEBUG的输出函数,选手仅在开启Debug模式的情况下可以使用

virtual void Print(std::string str) const = 0;
virtual void PrintShip() const = 0;
virtual void PrintCharacter() const = 0;
virtual void PrintTeam() const = 0;
virtual void PrintSelfInfo() const = 0;
};
Expand All @@ -133,8 +133,8 @@ class ICharacterAPI : public IAPI
virtual std::future<bool> MoveUp(int32_t speed, int64_t timeInMilliseconds) = 0;
virtual std::future<bool> MoveLeft(int32_t speed, int64_t timeInMilliseconds) = 0;
virtual std::future<bool> MoveDown(int32_t speed, int64_t timeInMilliseconds) = 0;
virtual std::future<bool> Skill_Attack(double angleInRadian) = 0;
virtual std::future<bool> Common_Attack(double angleInRadian) = 0;
virtual std::future<bool> Skill_Attack(int64_t attackedPlayerID) = 0;
virtual std::future<bool> Common_Attack(int64_t attackedPlayerID) = 0;
virtual std::future<bool> Recover(int64_t recover) = 0;
virtual std::future<bool> Harvest() = 0;
virtual std::future<bool> Rebuild(THUAI8::ConstructionType constructionType) = 0;
Expand Down Expand Up @@ -269,7 +269,7 @@ class TeamAPI : public ITeamAPI, public IGameTimer
void Print(std::string str) const
{
}
void PrintShip() const
void PrintCharacter() const
{
}
void PrintTeam() const
Expand Down
8 changes: 4 additions & 4 deletions CAPI/cpp/API/include/Communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ class 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);
void AddPlayer(int32_t playerID, int32_t teamID, THUAI8::CharacterType CharacterType);
bool EndAllAction(int32_t playerID, int32_t teamID);
// Character
bool Move(int32_t speed, 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 Rebuild(int32_t playerID, int32_t teamID, THUAI7::ConstructionType constructionType);
bool Construct(int32_t playerID, int32_t teamID, THUAI7::ConstructionType constructionType);
bool Rebuild(int32_t playerID, int32_t teamID, THUAI8::ConstructionType constructionType);
bool Construct(int32_t playerID, int32_t teamID, THUAI8::ConstructionType constructionType);
bool Skill_Attack(int32_t playerID, int32_t teamID, double angle);
bool Common_Attack(int32_t playerID, int32_t teamID, double angle);
bool Send(int32_t playerID, int32_t toPlayerID, int32_t teamID, std::string message, bool binary);
// Team
bool InstallEquipment(int32_t playerID, int32_t teamID, THUAI7::EquipmentType equipmentType);
bool InstallEquipment(int32_t playerID, int32_t teamID, THUAI8::EquipmentType equipmentType);
bool BuildCharacter(int32_t teamID, THUAI8::CharacterType CharacterType, int32_t birthIndex);
bool Recycle(int32_t playerID, int32_t teamID);

Expand Down
2 changes: 1 addition & 1 deletion CAPI/cpp/API/include/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Logic : public ILogic
void Wait() noexcept;

public:
Logic(int32_t playerID, int32_t teamID, THUAI7::PlayerType playerType, THUAI7::ShipType ShipType);
Logic(int32_t playerID, int32_t teamID, THUAI8::PlayerType playerType, THUAI8::CharacterType CharacterType);

~Logic()
{
Expand Down
54 changes: 54 additions & 0 deletions CAPI/cpp/API/src/AI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <vector>
#include <thread>
#include <array>
#include <map>
#include "AI.h"
#include "constants.h"
// 注意不要使用conio.h,Windows.h等非标准库
// 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新,大致一帧更新一次
extern const bool asynchronous = false;

// 选手需要依次将player1到player4的角色类型在这里定义
extern const std::array<THUAI8::CharacterType, 12> CharacterTypeDict = {
THUAI8::CharacterType::Monk,
THUAI8::CharacterType::MonkeyKing,
THUAI8::CharacterType::Pigsy,
THUAI8::CharacterType::ShaWujing,
THUAI8::CharacterType::Whitedragonhorse,
THUAI8::CharacterType::JiuTouYuanSheng,
THUAI8::CharacterType::Honghaier,
THUAI8::CharacterType::Gyuumao,
THUAI8::CharacterType::Princess_Iron_Fan,
THUAI8::CharacterType::Spider,
};

// 可以在AI.cpp内部声明变量与函数

void AI::play(ICharacterAPI& api)
{
if (this->playerID == 1)
{
// player1的操作
}
else if (this->playerID == 2)
{
// player2的操作
}
else if (this->playerID == 3)
{
// player3的操作
}
else if (this->playerID == 4)
{
// player4的操作
}
else if (this->playerID == 5)
{
// player5的操作
}
}

void AI::play(ITeamAPI& api) // 默认team playerID 为0
{
// player0的操作
}
Loading
Loading