Browse Source

refactor(CAPI): 🎨 affect proto rename to capi

tags/0.1.0
DragonAura 2 years ago
parent
commit
c8f2e25613
14 changed files with 638 additions and 626 deletions
  1. +4
    -4
      CAPI/API/include/AI.h
  2. +82
    -82
      CAPI/API/include/API.h
  3. +10
    -10
      CAPI/API/include/Communication.h
  4. +2
    -2
      CAPI/API/include/constants.h
  5. +16
    -16
      CAPI/API/include/logic.h
  6. +4
    -4
      CAPI/API/include/state.h
  7. +68
    -62
      CAPI/API/include/structures.h
  8. +117
    -111
      CAPI/API/include/utils.hpp
  9. +5
    -5
      CAPI/API/src/AI.cpp
  10. +66
    -66
      CAPI/API/src/API.cpp
  11. +39
    -39
      CAPI/API/src/Communication.cpp
  12. +143
    -143
      CAPI/API/src/DebugAPI.cpp
  13. +78
    -78
      CAPI/API/src/logic.cpp
  14. +4
    -4
      CAPI/API/src/main.cpp

+ 4
- 4
CAPI/API/include/AI.h View File

@@ -9,8 +9,8 @@ class IAI
public:
virtual ~IAI() = default;
IAI() = default;
virtual void play(IHumanAPI& api) = 0;
virtual void play(IButcherAPI& api) = 0;
virtual void play(IStudentAPI& api) = 0;
virtual void play(ITrickerAPI& api) = 0;
};

using CreateAIFunc = std::unique_ptr<IAI> (*)();
@@ -22,8 +22,8 @@ public:
IAI()
{
}
void play(IHumanAPI& api) override;
void play(IButcherAPI& api) override;
void play(IStudentAPI& api) override;
void play(ITrickerAPI& api) override;
};

#endif

+ 82
- 82
CAPI/API/include/API.h View File

@@ -32,11 +32,11 @@ class ILogic

public:
// 获取服务器发来的消息
virtual std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButchers() const = 0;
virtual std::vector<std::shared_ptr<const THUAI6::Human>> GetHumans() const = 0;
virtual std::vector<std::shared_ptr<const THUAI6::Tricker>> GetTrickers() const = 0;
virtual std::vector<std::shared_ptr<const THUAI6::Student>> GetStudents() const = 0;
virtual std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const = 0;
virtual std::shared_ptr<const THUAI6::Human> HumanGetSelfInfo() const = 0;
virtual std::shared_ptr<const THUAI6::Butcher> ButcherGetSelfInfo() const = 0;
virtual std::shared_ptr<const THUAI6::Student> StudentGetSelfInfo() const = 0;
virtual std::shared_ptr<const THUAI6::Tricker> TrickerGetSelfInfo() const = 0;

virtual std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const = 0;
virtual THUAI6::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const = 0;
@@ -54,20 +54,20 @@ public:

virtual int GetCounter() const = 0;

// IHumanAPI使用的部分
virtual bool Escape() = 0;
// IStudentAPI使用的部分
virtual bool Graduate() = 0;

virtual bool StartFixMachine() = 0;
virtual bool EndFixMachine() = 0;
virtual bool StartLearning() = 0;
virtual bool EndLearning() = 0;

virtual bool StartSaveHuman() = 0;
virtual bool EndSaveHuman() = 0;
virtual bool StartHelpMate() = 0;
virtual bool EndHelpMate() = 0;

// IButcherAPI使用的部分
virtual bool Attack(double angle) = 0;
virtual bool CarryHuman() = 0;
virtual bool ReleaseHuman() = 0;
virtual bool HangHuman() = 0;
// ITrickerAPI使用的部分
virtual bool Trick(double angle) = 0;
virtual bool StartExam() = 0;
virtual bool EndExam() = 0;
virtual bool MakeFail() = 0;

virtual const std::vector<int64_t> GetPlayerGUIDs() const = 0;
};
@@ -98,9 +98,9 @@ public:
// 等待下一帧
virtual std::future<bool> Wait() = 0;

// 获取视野内可见的人类/屠夫的信息
[[nodiscard]] virtual std::vector<std::shared_ptr<const THUAI6::Human>> GetHumans() const = 0;
[[nodiscard]] virtual std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButchers() const = 0;
// 获取视野内可见的学生/捣蛋鬼的信息
[[nodiscard]] virtual std::vector<std::shared_ptr<const THUAI6::Student>> GetStudents() const = 0;
[[nodiscard]] virtual std::vector<std::shared_ptr<const THUAI6::Tricker>> GetTrickers() const = 0;

// 获取视野内可见的道具信息
[[nodiscard]] virtual std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const = 0;
@@ -131,35 +131,35 @@ public:

// 用于DEBUG的输出函数,选手仅在开启Debug模式的情况下可以使用

virtual void PrintHuman() const = 0;
virtual void PrintButcher() const = 0;
virtual void PrintStudent() const = 0;
virtual void PrintTricker() const = 0;
virtual void PrintProp() const = 0;
virtual void PrintSelfInfo() const = 0;
};

class IHumanAPI : public IAPI
class IStudentAPI : public IAPI
{
public:
/*****人类阵营的特定函数*****/
virtual std::future<bool> StartFixMachine() = 0;
virtual std::future<bool> EndFixMachine() = 0;
virtual std::future<bool> StartSaveHuman() = 0;
virtual std::future<bool> EndSaveHuman() = 0;
virtual std::future<bool> Escape() = 0;
[[nodiscard]] virtual std::shared_ptr<const THUAI6::Human> GetSelfInfo() const = 0;
/*****学生阵营的特定函数*****/
virtual std::future<bool> StartLearning() = 0;
virtual std::future<bool> EndLearning() = 0;
virtual std::future<bool> StartHelpMate() = 0;
virtual std::future<bool> EndHelpMate() = 0;
virtual std::future<bool> Graduate() = 0;
[[nodiscard]] virtual std::shared_ptr<const THUAI6::Student> GetSelfInfo() const = 0;
};

class IButcherAPI : public IAPI
class ITrickerAPI : public IAPI
{
public:
/*****屠夫阵营的特定函数*****/
/*****捣蛋鬼阵营的特定函数*****/

virtual std::future<bool> Attack(double angleInRadian) = 0;
virtual std::future<bool> CarryHuman() = 0;
virtual std::future<bool> ReleaseHuman() = 0;
virtual std::future<bool> HangHuman() = 0;
[[nodiscard]] virtual std::shared_ptr<const THUAI6::Butcher> GetSelfInfo() const = 0;
virtual std::future<bool> Trick(double angleInRadian) = 0;
virtual std::future<bool> StartExam() = 0;
virtual std::future<bool> EndExam() = 0;
virtual std::future<bool> MakeFail() = 0;
[[nodiscard]] virtual std::shared_ptr<const THUAI6::Tricker> GetSelfInfo() const = 0;
};

class IGameTimer
@@ -171,10 +171,10 @@ public:
virtual void Play(IAI& ai) = 0;
};

class HumanAPI : public IHumanAPI, public IGameTimer
class StudentAPI : public IStudentAPI, public IGameTimer
{
public:
HumanAPI(ILogic& logic) :
StudentAPI(ILogic& logic) :
logic(logic)
{
}
@@ -205,8 +205,8 @@ public:

std::future<bool> Wait() override;

[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Human>> GetHumans() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButchers() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Student>> GetStudents() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Tricker>> GetTrickers() const override;

[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const override;

@@ -215,17 +215,17 @@ public:

[[nodiscard]] const std::vector<int64_t> GetPlayerGUIDs() const override;

std::future<bool> StartFixMachine() override;
std::future<bool> EndFixMachine() override;
std::future<bool> StartSaveHuman() override;
std::future<bool> EndSaveHuman() override;
std::future<bool> Escape() override;
[[nodiscard]] std::shared_ptr<const THUAI6::Human> GetSelfInfo() const override;
std::future<bool> StartLearning() override;
std::future<bool> EndLearning() override;
std::future<bool> StartHelpMate() override;
std::future<bool> EndHelpMate() override;
std::future<bool> Graduate() override;
[[nodiscard]] std::shared_ptr<const THUAI6::Student> GetSelfInfo() const override;

void PrintHuman() const override
void PrintStudent() const override
{
}
void PrintButcher() const override
void PrintTricker() const override
{
}
void PrintProp() const override
@@ -239,10 +239,10 @@ private:
ILogic& logic;
};

class ButcherAPI : public IButcherAPI, public IGameTimer
class TrickerAPI : public ITrickerAPI, public IGameTimer
{
public:
ButcherAPI(ILogic& logic) :
TrickerAPI(ILogic& logic) :
logic(logic)
{
}
@@ -272,8 +272,8 @@ public:

std::future<bool> Wait() override;

[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Human>> GetHumans() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButchers() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Student>> GetStudents() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Tricker>> GetTrickers() const override;

[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const override;

@@ -282,16 +282,16 @@ public:

[[nodiscard]] const std::vector<int64_t> GetPlayerGUIDs() const override;

std::future<bool> Attack(double angleInRadian) override;
std::future<bool> CarryHuman() override;
std::future<bool> ReleaseHuman() override;
std::future<bool> HangHuman() override;
[[nodiscard]] std::shared_ptr<const THUAI6::Butcher> GetSelfInfo() const override;
std::future<bool> Trick(double angleInRadian) override;
std::future<bool> StartExam() override;
std::future<bool> EndExam() override;
std::future<bool> MakeFail() override;
[[nodiscard]] std::shared_ptr<const THUAI6::Tricker> GetSelfInfo() const override;

void PrintHuman() const override
void PrintStudent() const override
{
}
void PrintButcher() const override
void PrintTricker() const override
{
}
void PrintProp() const override
@@ -305,10 +305,10 @@ private:
ILogic& logic;
};

class HumanDebugAPI : public IHumanAPI, public IGameTimer
class StudentDebugAPI : public IStudentAPI, public IGameTimer
{
public:
HumanDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t playerID);
StudentDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t playerID);
void StartTimer() override;
void EndTimer() override;
void Play(IAI& ai) override;
@@ -331,8 +331,8 @@ public:

std::future<bool> Wait() override;

[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Human>> GetHumans() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButchers() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Student>> GetStudents() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Tricker>> GetTrickers() const override;

[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const override;

@@ -341,15 +341,15 @@ public:

[[nodiscard]] const std::vector<int64_t> GetPlayerGUIDs() const override;

std::future<bool> StartFixMachine() override;
std::future<bool> EndFixMachine() override;
std::future<bool> StartSaveHuman() override;
std::future<bool> EndSaveHuman() override;
std::future<bool> Escape() override;
[[nodiscard]] virtual std::shared_ptr<const THUAI6::Human> GetSelfInfo() const override;
std::future<bool> StartLearning() override;
std::future<bool> EndLearning() override;
std::future<bool> StartHelpMate() override;
std::future<bool> EndHelpMate() override;
std::future<bool> Graduate() override;
[[nodiscard]] virtual std::shared_ptr<const THUAI6::Student> GetSelfInfo() const override;

void PrintHuman() const override;
void PrintButcher() const override;
void PrintStudent() const override;
void PrintTricker() const override;
void PrintProp() const override;
void PrintSelfInfo() const override;

@@ -359,10 +359,10 @@ private:
ILogic& logic;
};

class ButcherDebugAPI : public IButcherAPI, public IGameTimer
class TrickerDebugAPI : public ITrickerAPI, public IGameTimer
{
public:
ButcherDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t playerID);
TrickerDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t playerID);
void StartTimer() override;
void EndTimer() override;
void Play(IAI& ai) override;
@@ -385,8 +385,8 @@ public:

std::future<bool> Wait() override;

[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Human>> GetHumans() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButchers() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Student>> GetStudents() const override;
[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Tricker>> GetTrickers() const override;

[[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const override;

@@ -395,14 +395,14 @@ public:

[[nodiscard]] const std::vector<int64_t> GetPlayerGUIDs() const override;

std::future<bool> Attack(double angleInRadian) override;
std::future<bool> CarryHuman() override;
std::future<bool> ReleaseHuman() override;
std::future<bool> HangHuman() override;
[[nodiscard]] std::shared_ptr<const THUAI6::Butcher> GetSelfInfo() const override;
std::future<bool> Trick(double angleInRadian) override;
std::future<bool> StartExam() override;
std::future<bool> EndExam() override;
std::future<bool> MakeFail() override;
[[nodiscard]] std::shared_ptr<const THUAI6::Tricker> GetSelfInfo() const override;

void PrintHuman() const override;
void PrintButcher() const override;
void PrintStudent() const override;
void PrintTricker() const override;
void PrintProp() const override;
void PrintSelfInfo() const override;



+ 10
- 10
CAPI/API/include/Communication.h View File

@@ -31,22 +31,22 @@ public:
std::optional<std::pair<int64_t, std::string>> GetMessage();
bool HaveMessage();
bool SendMessage(int64_t toID, std::string message, int64_t playerID);
bool Escape(int64_t playerID);
bool Graduate(int64_t playerID);

bool StartFixMachine(int64_t playerID);
bool EndFixMachine(int64_t playerID);
bool StartSaveHuman(int64_t playerID);
bool EndSaveHuman(int64_t playerID);
bool StartLearning(int64_t playerID);
bool EndLearning(int64_t playerID);
bool StartHelpMate(int64_t playerID);
bool EndHelpMate(int64_t playerID);

bool Attack(double angle, int64_t playerID);
bool Trick(double angle, int64_t playerID);

bool CarryHuman(int64_t playerID);
bool ReleaseHuman(int64_t playerID);
bool HangHuman(int64_t playerID);
bool StartExam(int64_t playerID);
bool EndExam(int64_t playerID);
bool MakeFail(int64_t playerID);

bool TryConnection(int64_t playerID);
protobuf::MessageToClient GetMessage2Client();
void AddPlayer(int64_t playerID, THUAI6::PlayerType playerType, THUAI6::HumanType humanType, THUAI6::ButcherType butcherType);
void AddPlayer(int64_t playerID, THUAI6::PlayerType playerType, THUAI6::StudentType studentType, THUAI6::TrickerType trickerType);

void ReadMessage(int64_t playerID);



+ 2
- 2
CAPI/API/include/constants.h View File

@@ -6,11 +6,11 @@ namespace Constants
{
static const constexpr inline numOfGridPerCell = 1000;

struct HumanConstants
struct StudentConstants
{
};

struct ButcherConstants
struct TrickerConstants
{
};



+ 16
- 16
CAPI/API/include/logic.h View File

@@ -45,8 +45,8 @@ private:
THUAI6::PlayerType playerType;

// 类型记录
THUAI6::HumanType humanType;
THUAI6::ButcherType butcherType;
THUAI6::StudentType studentType;
THUAI6::TrickerType trickerType;

// GUID信息
std::vector<int64_t> playerGUIDs;
@@ -90,11 +90,11 @@ private:

// 提供给API使用的函数

std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButchers() const override;
std::vector<std::shared_ptr<const THUAI6::Human>> GetHumans() const override;
std::vector<std::shared_ptr<const THUAI6::Tricker>> GetTrickers() const override;
std::vector<std::shared_ptr<const THUAI6::Student>> GetStudents() const override;
std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const override;
std::shared_ptr<const THUAI6::Human> HumanGetSelfInfo() const override;
std::shared_ptr<const THUAI6::Butcher> ButcherGetSelfInfo() const override;
std::shared_ptr<const THUAI6::Student> StudentGetSelfInfo() const override;
std::shared_ptr<const THUAI6::Tricker> TrickerGetSelfInfo() const override;

std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const override;
THUAI6::PlaceType GetPlaceType(int32_t CellX, int32_t CellY) const override;
@@ -109,18 +109,18 @@ private:
bool HaveMessage() override;
std::optional<std::pair<int64_t, std::string>> GetMessage() override;

bool Escape() override;
bool Graduate() override;

bool StartFixMachine() override;
bool EndFixMachine() override;
bool StartLearning() override;
bool EndLearning() override;

bool StartSaveHuman() override;
bool EndSaveHuman() override;
bool StartHelpMate() override;
bool EndHelpMate() override;

bool Attack(double angle) override;
bool CarryHuman() override;
bool ReleaseHuman() override;
bool HangHuman() override;
bool Trick(double angle) override;
bool StartExam() override;
bool EndExam() override;
bool MakeFail() override;

bool WaitThread() override;

@@ -146,7 +146,7 @@ private:

public:
// 构造函数还需要传更多参数,有待补充
Logic(THUAI6::PlayerType type, int64_t ID, THUAI6::ButcherType butcher, THUAI6::HumanType human);
Logic(THUAI6::PlayerType type, int64_t ID, THUAI6::TrickerType tricker, THUAI6::StudentType student);

~Logic()
{


+ 4
- 4
CAPI/API/include/state.h View File

@@ -13,11 +13,11 @@ struct State
int32_t teamScore;

// 自身信息,根据playerType的不同,可以调用的值也不同。
std::shared_ptr<THUAI6::Human> humanSelf;
std::shared_ptr<THUAI6::Butcher> butcherSelf;
std::shared_ptr<THUAI6::Student> studentSelf;
std::shared_ptr<THUAI6::Tricker> trickerSelf;

std::vector<std::shared_ptr<THUAI6::Human>> humans;
std::vector<std::shared_ptr<THUAI6::Butcher>> butchers;
std::vector<std::shared_ptr<THUAI6::Student>> students;
std::vector<std::shared_ptr<THUAI6::Tricker>> trickers;
std::vector<std::shared_ptr<THUAI6::Prop>> props;

std::vector<std::vector<THUAI6::PlaceType>> gamemap;


+ 68
- 62
CAPI/API/include/structures.h View File

@@ -26,9 +26,10 @@ namespace THUAI6
Land = 1,
Wall = 2,
Grass = 3,
Machine = 4,
Gate = 5,
HiddenGate = 6,
ClassRoom = 4,
BlackRoom = 5,
Gate = 6,
HiddenGate = 7,
};

// 形状标志
@@ -53,58 +54,59 @@ namespace THUAI6
enum class PlayerType : unsigned char
{
NullPlayerType = 0,
HumanPlayer = 1,
ButcherPlayer = 2,
StudentPlayer = 1,
TrickerPlayer = 2,
};

// 人类类型
enum class HumanType : unsigned char
// 学生类型
enum class StudentType : unsigned char
{
NullHumanType = 0,
HumanType1 = 1,
HumanType2 = 2,
HumanType3 = 3,
HumanType4 = 4,
NullStudentType = 0,
StudentType1 = 1,
StudentType2 = 2,
StudentType3 = 3,
StudentType4 = 4,
};

// 屠夫类型
enum class ButcherType : unsigned char
// 捣蛋鬼类型
enum class TrickerType : unsigned char
{
NullButcherType = 0,
ButcherType1 = 1,
ButcherType2 = 2,
ButcherType3 = 3,
ButcherType4 = 4,
NullTrickerType = 0,
TrickerType1 = 1,
TrickerType2 = 2,
TrickerType3 = 3,
TrickerType4 = 4,
};

// 人类Buff类型
enum class HumanBuffType : unsigned char
// 学生Buff类型
enum class StudentBuffType : unsigned char
{
NullHumanBuffType = 0,
HumanBuffType1 = 1,
HumanBuffType2 = 2,
HumanBuffType3 = 3,
HumanBuffType4 = 4,
NullStudentBuffType = 0,
StudentBuffType1 = 1,
StudentBuffType2 = 2,
StudentBuffType3 = 3,
StudentBuffType4 = 4,
};

enum class ButcherBuffType : unsigned char
enum class TrickerBuffType : unsigned char
{
NullButcherBuffType = 0,
ButcherBuffType1 = 1,
ButcherBuffType2 = 2,
ButcherBuffType3 = 3,
ButcherBuffType4 = 4,
NullTrickerBuffType = 0,
TrickerBuffType1 = 1,
TrickerBuffType2 = 2,
TrickerBuffType3 = 3,
TrickerBuffType4 = 4,
};

// 人类状态枚举
enum class HumanState : unsigned char
// 学生状态枚举
enum class StudentState : unsigned char
{
NullHumanState = 0,
NullStudentState = 0,
Idle = 1,
Fixing = 2,
Dying = 3,
OnChair = 4,
Dead = 5,
Learning = 2,
Fail = 3,
Emotional = 4,
Quit = 5,
Graduated = 6,
};

// 玩家类
@@ -125,23 +127,25 @@ namespace THUAI6
PlaceType place; // 所处格子的类型
};

struct Human : public Player
struct Student : public Player
{
HumanState state; // 人类状态
int32_t life; // 剩余生命(本次倒地之前还能承受的伤害)
int32_t hangedTime; // 被挂的次数
StudentState state; // 学生状态
int32_t determination; // 剩余毅力(本次Emo之前还能承受的伤害)
int32_t failNum; // 挂科数量
double failTime; // 挂科时间
double emoTime; // EMO时间

HumanType humanType; // 人类类型
std::vector<HumanBuffType> buff; // buff
StudentType studentType; // 学生类型
std::vector<StudentBuffType> buff; // buff
};

struct Butcher : public Player
struct Tricker : public Player
{
int32_t damage; // 攻击伤害
bool movable; // 是否处在攻击后摇中

ButcherType butcherType; // 屠夫类型
std::vector<ButcherBuffType> buff; // buff
TrickerType trickerType; // 捣蛋鬼类型
std::vector<TrickerBuffType> buff; // buff
};

struct Prop
@@ -166,19 +170,20 @@ namespace THUAI6
{GameState::GameEnd, "GameEnd"},
};

inline std::map<HumanState, std::string> humanStateDict{
{HumanState::NullHumanState, "NullHumanState"},
{HumanState::Idle, "Idle"},
{HumanState::Fixing, "Fixing"},
{HumanState::Dying, "Dying"},
{HumanState::OnChair, "OnChair"},
{HumanState::Dead, "Dead"},
inline std::map<StudentState, std::string> studentStateDict{
{StudentState::NullStudentState, "NullStudentState"},
{StudentState::Idle, "Idle"},
{StudentState::Learning, "Learning"},
{StudentState::Fail, "Fail"},
{StudentState::Emotional, "Emotional"},
{StudentState::Quit, "Quit"},
{StudentState::Graduated, "Graduated"},
};

inline std::map<PlayerType, std::string> playerTypeDict{
{PlayerType::NullPlayerType, "NullPlayerType"},
{PlayerType::HumanPlayer, "HumanPlayer"},
{PlayerType::ButcherPlayer, "ButcherPlayer"},
{PlayerType::StudentPlayer, "StudentPlayer"},
{PlayerType::TrickerPlayer, "TrickerPlayer"},
};

inline std::map<PlaceType, std::string> placeTypeDict{
@@ -186,7 +191,8 @@ namespace THUAI6
{PlaceType::Land, "Land"},
{PlaceType::Wall, "Wall"},
{PlaceType::Grass, "Grass"},
{PlaceType::Machine, "Machine"},
{PlaceType::ClassRoom, "ClassRoom"},
{PlaceType::BlackRoom, "BlackRoom"},
{PlaceType::Gate, "Gate"},
{PlaceType::HiddenGate, "HiddenGate"},
};
@@ -196,13 +202,13 @@ namespace THUAI6

};

inline std::map<HumanBuffType, std::string> humanBuffDict{
{HumanBuffType::NullHumanBuffType, "NullHumanBuffType"},
inline std::map<StudentBuffType, std::string> studentBuffDict{
{StudentBuffType::NullStudentBuffType, "NullStudentBuffType"},

};

inline std::map<ButcherBuffType, std::string> butcherBuffDict{
{ButcherBuffType::NullButcherBuffType, "NullButcherBuffType"},
inline std::map<TrickerBuffType, std::string> trickerBuffDict{
{TrickerBuffType::NullTrickerBuffType, "NullTrickerBuffType"},

};



+ 117
- 111
CAPI/API/include/utils.hpp View File

@@ -55,7 +55,8 @@ namespace Proto2THUAI6
{protobuf::PlaceType::LAND, THUAI6::PlaceType::Land},
{protobuf::PlaceType::WALL, THUAI6::PlaceType::Wall},
{protobuf::PlaceType::GRASS, THUAI6::PlaceType::Grass},
{protobuf::PlaceType::MACHINE, THUAI6::PlaceType::Machine},
{protobuf::PlaceType::CLASSROOM, THUAI6::PlaceType::ClassRoom},
{protobuf::PlaceType::BLACKROOM, THUAI6::PlaceType::BlackRoom},
{protobuf::PlaceType::GATE, THUAI6::PlaceType::Gate},
{protobuf::PlaceType::HIDDEN_GATE, THUAI6::PlaceType::HiddenGate},
};
@@ -76,49 +77,50 @@ namespace Proto2THUAI6

inline std::map<protobuf::PlayerType, THUAI6::PlayerType> playerTypeDict{
{protobuf::PlayerType::NULL_PLAYER_TYPE, THUAI6::PlayerType::NullPlayerType},
{protobuf::PlayerType::HUMAN_PLAYER, THUAI6::PlayerType::HumanPlayer},
{protobuf::PlayerType::BUTCHER_PLAYER, THUAI6::PlayerType::ButcherPlayer},
{protobuf::PlayerType::STUDENT_PLAYER, THUAI6::PlayerType::StudentPlayer},
{protobuf::PlayerType::TRICKER_PLAYER, THUAI6::PlayerType::TrickerPlayer},
};

inline std::map<protobuf::HumanType, THUAI6::HumanType> humanTypeDict{
{protobuf::HumanType::NULL_HUMAN_TYPE, THUAI6::HumanType::NullHumanType},
{protobuf::HumanType::HUMANTYPE1, THUAI6::HumanType::HumanType1},
{protobuf::HumanType::HUMANTYPE2, THUAI6::HumanType::HumanType2},
{protobuf::HumanType::HUMANTYPE3, THUAI6::HumanType::HumanType3},
{protobuf::HumanType::HUMANTYPE4, THUAI6::HumanType::HumanType4},
inline std::map<protobuf::StudentType, THUAI6::StudentType> studentTypeDict{
{protobuf::StudentType::NULL_STUDENT_TYPE, THUAI6::StudentType::NullStudentType},
{protobuf::StudentType::STUDENTTYPE1, THUAI6::StudentType::StudentType1},
{protobuf::StudentType::STUDENTTYPE2, THUAI6::StudentType::StudentType2},
{protobuf::StudentType::STUDENTTYPE3, THUAI6::StudentType::StudentType3},
{protobuf::StudentType::STUDENTTYPE4, THUAI6::StudentType::StudentType4},
};

inline std::map<protobuf::ButcherType, THUAI6::ButcherType> butcherTypeDict{
{protobuf::ButcherType::NULL_BUTCHER_TYPE, THUAI6::ButcherType::NullButcherType},
{protobuf::ButcherType::BUTCHERTYPE1, THUAI6::ButcherType::ButcherType1},
{protobuf::ButcherType::BUTCHERTYPE2, THUAI6::ButcherType::ButcherType2},
{protobuf::ButcherType::BUTCHERTYPE3, THUAI6::ButcherType::ButcherType3},
{protobuf::ButcherType::BUTCHERTYPE4, THUAI6::ButcherType::ButcherType4},
inline std::map<protobuf::TrickerType, THUAI6::TrickerType> trickerTypeDict{
{protobuf::TrickerType::NULL_TRICKER_TYPE, THUAI6::TrickerType::NullTrickerType},
{protobuf::TrickerType::TRICKERTYPE1, THUAI6::TrickerType::TrickerType1},
{protobuf::TrickerType::TRICKERTYPE2, THUAI6::TrickerType::TrickerType2},
{protobuf::TrickerType::TRICKERTYPE3, THUAI6::TrickerType::TrickerType3},
{protobuf::TrickerType::TRICKERTYPE4, THUAI6::TrickerType::TrickerType4},
};

inline std::map<protobuf::HumanBuffType, THUAI6::HumanBuffType> humanBuffTypeDict{
{protobuf::HumanBuffType::NULL_HBUFF_TYPE, THUAI6::HumanBuffType::NullHumanBuffType},
{protobuf::HumanBuffType::HBUFFTYPE1, THUAI6::HumanBuffType::HumanBuffType1},
{protobuf::HumanBuffType::HBUFFTYPE2, THUAI6::HumanBuffType::HumanBuffType2},
{protobuf::HumanBuffType::HBUFFTYPE3, THUAI6::HumanBuffType::HumanBuffType3},
{protobuf::HumanBuffType::HBUFFTYPE4, THUAI6::HumanBuffType::HumanBuffType4},
inline std::map<protobuf::StudentBuffType, THUAI6::StudentBuffType> studentBuffTypeDict{
{protobuf::StudentBuffType::NULL_SBUFF_TYPE, THUAI6::StudentBuffType::NullStudentBuffType},
{protobuf::StudentBuffType::SBUFFTYPE1, THUAI6::StudentBuffType::StudentBuffType1},
{protobuf::StudentBuffType::SBUFFTYPE2, THUAI6::StudentBuffType::StudentBuffType2},
{protobuf::StudentBuffType::SBUFFTYPE3, THUAI6::StudentBuffType::StudentBuffType3},
{protobuf::StudentBuffType::SBUFFTYPE4, THUAI6::StudentBuffType::StudentBuffType4},
};

inline std::map<protobuf::ButcherBuffType, THUAI6::ButcherBuffType> butcherBuffTypeDict{
{protobuf::ButcherBuffType::NULL_BBUFF_TYPE, THUAI6::ButcherBuffType::NullButcherBuffType},
{protobuf::ButcherBuffType::BBUFFTYPE1, THUAI6::ButcherBuffType::ButcherBuffType1},
{protobuf::ButcherBuffType::BBUFFTYPE2, THUAI6::ButcherBuffType::ButcherBuffType2},
{protobuf::ButcherBuffType::BBUFFTYPE3, THUAI6::ButcherBuffType::ButcherBuffType3},
{protobuf::ButcherBuffType::BBUFFTYPE4, THUAI6::ButcherBuffType::ButcherBuffType4},
inline std::map<protobuf::TrickerBuffType, THUAI6::TrickerBuffType> trickerBuffTypeDict{
{protobuf::TrickerBuffType::NULL_TBUFF_TYPE, THUAI6::TrickerBuffType::NullTrickerBuffType},
{protobuf::TrickerBuffType::TBUFFTYPE1, THUAI6::TrickerBuffType::TrickerBuffType1},
{protobuf::TrickerBuffType::TBUFFTYPE2, THUAI6::TrickerBuffType::TrickerBuffType2},
{protobuf::TrickerBuffType::TBUFFTYPE3, THUAI6::TrickerBuffType::TrickerBuffType3},
{protobuf::TrickerBuffType::TBUFFTYPE4, THUAI6::TrickerBuffType::TrickerBuffType4},
};

inline std::map<protobuf::HumanState, THUAI6::HumanState> humanStateDict{
{protobuf::HumanState::NULL_STATUS, THUAI6::HumanState::NullHumanState},
{protobuf::HumanState::IDLE, THUAI6::HumanState::Idle},
{protobuf::HumanState::FIXING, THUAI6::HumanState::Fixing},
{protobuf::HumanState::DYING, THUAI6::HumanState::Dying},
{protobuf::HumanState::ON_CHAIR, THUAI6::HumanState::OnChair},
{protobuf::HumanState::DEAD, THUAI6::HumanState::Dead},
inline std::map<protobuf::StudentState, THUAI6::StudentState> studentStateDict{
{protobuf::StudentState::NULL_STATUS, THUAI6::StudentState::NullStudentState},
{protobuf::StudentState::IDLE, THUAI6::StudentState::Idle},
{protobuf::StudentState::LEARNING, THUAI6::StudentState::Learning},
{protobuf::StudentState::FAIL, THUAI6::StudentState::Fail},
{protobuf::StudentState::EMOTIONAL, THUAI6::StudentState::Emotional},
{protobuf::StudentState::QUIT, THUAI6::StudentState::Quit},
{protobuf::StudentState::GRADUATED, THUAI6::StudentState::Graduated},
};

inline std::map<protobuf::GameState, THUAI6::GameState> gameStateDict{
@@ -129,54 +131,56 @@ namespace Proto2THUAI6
};

// 用于将Protobuf中的类转换为THUAI6的类
inline std::shared_ptr<THUAI6::Butcher> Protobuf2THUAI6Butcher(const protobuf::MessageOfButcher& butcherMsg)
inline std::shared_ptr<THUAI6::Tricker> Protobuf2THUAI6Tricker(const protobuf::MessageOfTricker& trickerMsg)
{
auto butcher = std::make_shared<THUAI6::Butcher>();
butcher->x = butcherMsg.x();
butcher->y = butcherMsg.y();
butcher->speed = butcherMsg.speed();
butcher->damage = butcherMsg.damage();
butcher->timeUntilSkillAvailable = butcherMsg.time_until_skill_available();
butcher->place = placeTypeDict[butcherMsg.place()];
butcher->prop = propTypeDict[butcherMsg.prop()];
butcher->butcherType = butcherTypeDict[butcherMsg.butcher_type()];
butcher->guid = butcherMsg.guid();
butcher->movable = butcherMsg.movable();
butcher->playerID = butcherMsg.player_id();
butcher->viewRange = butcherMsg.view_range();
butcher->radius = butcherMsg.radius();
butcher->buff.clear();
for (int i = 0; i < butcherMsg.buff().size(); i++)
auto tricker = std::make_shared<THUAI6::Tricker>();
tricker->x = trickerMsg.x();
tricker->y = trickerMsg.y();
tricker->speed = trickerMsg.speed();
tricker->damage = trickerMsg.damage();
tricker->timeUntilSkillAvailable = trickerMsg.time_until_skill_available();
tricker->place = placeTypeDict[trickerMsg.place()];
tricker->prop = propTypeDict[trickerMsg.prop()];
tricker->trickerType = trickerTypeDict[trickerMsg.tricker_type()];
tricker->guid = trickerMsg.guid();
tricker->movable = trickerMsg.movable();
tricker->playerID = trickerMsg.player_id();
tricker->viewRange = trickerMsg.view_range();
tricker->radius = trickerMsg.radius();
tricker->buff.clear();
for (int i = 0; i < trickerMsg.buff().size(); i++)
{
butcher->buff.push_back(butcherBuffTypeDict[butcherMsg.buff(i)]);
tricker->buff.push_back(trickerBuffTypeDict[trickerMsg.buff(i)]);
}
return butcher;
return tricker;
}

inline std::shared_ptr<THUAI6::Human> Protobuf2THUAI6Human(const protobuf::MessageOfHuman& humanMsg)
inline std::shared_ptr<THUAI6::Student> Protobuf2THUAI6Student(const protobuf::MessageOfStudent& studentMsg)
{
auto human = std::make_shared<THUAI6::Human>();
human->x = humanMsg.x();
human->y = humanMsg.y();
human->speed = humanMsg.speed();
human->viewRange = humanMsg.view_range();
human->playerID = humanMsg.player_id();
human->guid = humanMsg.guid();
human->radius = humanMsg.radius();
human->timeUntilSkillAvailable = humanMsg.time_until_skill_available();
human->playerType = THUAI6::PlayerType::HumanPlayer;
human->prop = propTypeDict[humanMsg.prop()];
human->place = placeTypeDict[humanMsg.place()];
human->state = humanStateDict[humanMsg.state()];
human->life = humanMsg.life();
human->hangedTime = humanMsg.hanged_time();
human->humanType = humanTypeDict[humanMsg.human_type()];
human->buff.clear();
for (int i = 0; i < humanMsg.buff_size(); i++)
auto student = std::make_shared<THUAI6::Student>();
student->x = studentMsg.x();
student->y = studentMsg.y();
student->speed = studentMsg.speed();
student->viewRange = studentMsg.view_range();
student->playerID = studentMsg.player_id();
student->guid = studentMsg.guid();
student->radius = studentMsg.radius();
student->timeUntilSkillAvailable = studentMsg.time_until_skill_available();
student->playerType = THUAI6::PlayerType::StudentPlayer;
student->prop = propTypeDict[studentMsg.prop()];
student->place = placeTypeDict[studentMsg.place()];
student->state = studentStateDict[studentMsg.state()];
student->determination = studentMsg.determination();
student->failNum = studentMsg.fail_num();
student->failTime = studentMsg.fail_time();
student->emoTime = studentMsg.emo_time();
student->studentType = studentTypeDict[studentMsg.student_type()];
student->buff.clear();
for (int i = 0; i < studentMsg.buff_size(); i++)
{
human->buff.push_back(humanBuffTypeDict[humanMsg.buff(i)]);
student->buff.push_back(studentBuffTypeDict[studentMsg.buff(i)]);
}
return human;
return student;
}

inline std::shared_ptr<THUAI6::Prop> Protobuf2THUAI6Prop(const protobuf::MessageOfProp& propMsg)
@@ -218,7 +222,8 @@ namespace THUAI62Proto
{THUAI6::PlaceType::Land, protobuf::PlaceType::LAND},
{THUAI6::PlaceType::Wall, protobuf::PlaceType::WALL},
{THUAI6::PlaceType::Grass, protobuf::PlaceType::GRASS},
{THUAI6::PlaceType::Machine, protobuf::PlaceType::MACHINE},
{THUAI6::PlaceType::ClassRoom, protobuf::PlaceType::CLASSROOM},
{THUAI6::PlaceType::BlackRoom, protobuf::PlaceType::BLACKROOM},
{THUAI6::PlaceType::Gate, protobuf::PlaceType::GATE},
{THUAI6::PlaceType::HiddenGate, protobuf::PlaceType::HIDDEN_GATE},
};
@@ -239,58 +244,59 @@ namespace THUAI62Proto

inline std::map<THUAI6::PlayerType, protobuf::PlayerType> playerTypeDict{
{THUAI6::PlayerType::NullPlayerType, protobuf::PlayerType::NULL_PLAYER_TYPE},
{THUAI6::PlayerType::HumanPlayer, protobuf::PlayerType::HUMAN_PLAYER},
{THUAI6::PlayerType::ButcherPlayer, protobuf::PlayerType::BUTCHER_PLAYER},
{THUAI6::PlayerType::StudentPlayer, protobuf::PlayerType::STUDENT_PLAYER},
{THUAI6::PlayerType::TrickerPlayer, protobuf::PlayerType::TRICKER_PLAYER},
};

inline std::map<THUAI6::HumanType, protobuf::HumanType> humanTypeDict{
{THUAI6::HumanType::NullHumanType, protobuf::HumanType::NULL_HUMAN_TYPE},
{THUAI6::HumanType::HumanType1, protobuf::HumanType::HUMANTYPE1},
{THUAI6::HumanType::HumanType2, protobuf::HumanType::HUMANTYPE2},
{THUAI6::HumanType::HumanType3, protobuf::HumanType::HUMANTYPE3},
{THUAI6::HumanType::HumanType4, protobuf::HumanType::HUMANTYPE4},
inline std::map<THUAI6::StudentType, protobuf::StudentType> studentTypeDict{
{THUAI6::StudentType::NullStudentType, protobuf::StudentType::NULL_STUDENT_TYPE},
{THUAI6::StudentType::StudentType1, protobuf::StudentType::STUDENTTYPE1},
{THUAI6::StudentType::StudentType2, protobuf::StudentType::STUDENTTYPE2},
{THUAI6::StudentType::StudentType3, protobuf::StudentType::STUDENTTYPE3},
{THUAI6::StudentType::StudentType4, protobuf::StudentType::STUDENTTYPE4},
};

inline std::map<THUAI6::HumanBuffType, protobuf::HumanBuffType> humanBuffTypeDict{
{THUAI6::HumanBuffType::NullHumanBuffType, protobuf::HumanBuffType::NULL_HBUFF_TYPE},
{THUAI6::HumanBuffType::HumanBuffType1, protobuf::HumanBuffType::HBUFFTYPE1},
{THUAI6::HumanBuffType::HumanBuffType2, protobuf::HumanBuffType::HBUFFTYPE2},
{THUAI6::HumanBuffType::HumanBuffType3, protobuf::HumanBuffType::HBUFFTYPE3},
{THUAI6::HumanBuffType::HumanBuffType4, protobuf::HumanBuffType::HBUFFTYPE4},
inline std::map<THUAI6::StudentBuffType, protobuf::StudentBuffType> studentBuffTypeDict{
{THUAI6::StudentBuffType::NullStudentBuffType, protobuf::StudentBuffType::NULL_SBUFF_TYPE},
{THUAI6::StudentBuffType::StudentBuffType1, protobuf::StudentBuffType::SBUFFTYPE1},
{THUAI6::StudentBuffType::StudentBuffType2, protobuf::StudentBuffType::SBUFFTYPE2},
{THUAI6::StudentBuffType::StudentBuffType3, protobuf::StudentBuffType::SBUFFTYPE3},
{THUAI6::StudentBuffType::StudentBuffType4, protobuf::StudentBuffType::SBUFFTYPE4},
};

inline std::map<THUAI6::ButcherType, protobuf::ButcherType> butcherTypeDict{
{THUAI6::ButcherType::NullButcherType, protobuf::ButcherType::NULL_BUTCHER_TYPE},
{THUAI6::ButcherType::ButcherType1, protobuf::ButcherType::BUTCHERTYPE1},
{THUAI6::ButcherType::ButcherType2, protobuf::ButcherType::BUTCHERTYPE2},
{THUAI6::ButcherType::ButcherType3, protobuf::ButcherType::BUTCHERTYPE3},
{THUAI6::ButcherType::ButcherType4, protobuf::ButcherType::BUTCHERTYPE4},
inline std::map<THUAI6::TrickerType, protobuf::TrickerType> trickerTypeDict{
{THUAI6::TrickerType::NullTrickerType, protobuf::TrickerType::NULL_TRICKER_TYPE},
{THUAI6::TrickerType::TrickerType1, protobuf::TrickerType::TRICKERTYPE1},
{THUAI6::TrickerType::TrickerType2, protobuf::TrickerType::TRICKERTYPE2},
{THUAI6::TrickerType::TrickerType3, protobuf::TrickerType::TRICKERTYPE3},
{THUAI6::TrickerType::TrickerType4, protobuf::TrickerType::TRICKERTYPE4},
};

inline std::map<THUAI6::ButcherBuffType, protobuf::ButcherBuffType> butcherBuffTypeDict{
{THUAI6::ButcherBuffType::NullButcherBuffType, protobuf::ButcherBuffType::NULL_BBUFF_TYPE},
{THUAI6::ButcherBuffType::ButcherBuffType1, protobuf::ButcherBuffType::BBUFFTYPE1},
{THUAI6::ButcherBuffType::ButcherBuffType2, protobuf::ButcherBuffType::BBUFFTYPE2},
{THUAI6::ButcherBuffType::ButcherBuffType3, protobuf::ButcherBuffType::BBUFFTYPE3},
{THUAI6::ButcherBuffType::ButcherBuffType4, protobuf::ButcherBuffType::BBUFFTYPE4},
inline std::map<THUAI6::TrickerBuffType, protobuf::TrickerBuffType> trickerBuffTypeDict{
{THUAI6::TrickerBuffType::NullTrickerBuffType, protobuf::TrickerBuffType::NULL_TBUFF_TYPE},
{THUAI6::TrickerBuffType::TrickerBuffType1, protobuf::TrickerBuffType::TBUFFTYPE1},
{THUAI6::TrickerBuffType::TrickerBuffType2, protobuf::TrickerBuffType::TBUFFTYPE2},
{THUAI6::TrickerBuffType::TrickerBuffType3, protobuf::TrickerBuffType::TBUFFTYPE3},
{THUAI6::TrickerBuffType::TrickerBuffType4, protobuf::TrickerBuffType::TBUFFTYPE4},
};

// 用于将THUAI6的类转换为Protobuf的消息
inline protobuf::PlayerMsg THUAI62ProtobufPlayer(int64_t playerID, THUAI6::PlayerType playerType, THUAI6::HumanType humanType, THUAI6::ButcherType butcherType)
inline protobuf::PlayerMsg THUAI62ProtobufPlayer(int64_t playerID, THUAI6::PlayerType playerType, THUAI6::StudentType studentType, THUAI6::TrickerType trickerType)
{
protobuf::PlayerMsg playerMsg;
playerMsg.set_player_id(playerID);
playerMsg.set_player_type(playerTypeDict[playerType]);
if (playerType == THUAI6::PlayerType::HumanPlayer)
if (playerType == THUAI6::PlayerType::StudentPlayer)
{
playerMsg.set_human_type(humanTypeDict[humanType]);
playerMsg.set_student_type(studentTypeDict[studentType]);
}
else if (playerType == THUAI6::PlayerType::ButcherPlayer)
else if (playerType == THUAI6::PlayerType::TrickerPlayer)
{
playerMsg.set_butcher_type(butcherTypeDict[butcherType]);
playerMsg.set_tricker_type(trickerTypeDict[trickerType]);
}
return playerMsg;
}

inline protobuf::IDMsg THUAI62ProtobufID(int playerID)
{
protobuf::IDMsg idMsg;
@@ -324,12 +330,12 @@ namespace THUAI62Proto
return sendMsg;
}

inline protobuf::AttackMsg THUAI62ProtobufAttack(double angle, int64_t id)
inline protobuf::TrickMsg THUAI62ProtobufTrick(double angle, int64_t id)
{
protobuf::AttackMsg attackMsg;
attackMsg.set_angle(angle);
attackMsg.set_player_id(id);
return attackMsg;
protobuf::TrickMsg trickMsg;
trickMsg.set_angle(angle);
trickMsg.set_player_id(id);
return trickMsg;
}
} // namespace THUAI62Proto



+ 5
- 5
CAPI/API/src/AI.cpp View File

@@ -6,20 +6,20 @@
extern const bool asynchronous = false;

// 选手必须定义该变量来选择自己的阵营
extern const THUAI6::PlayerType playerType = THUAI6::PlayerType::HumanPlayer;
extern const THUAI6::PlayerType playerType = THUAI6::PlayerType::StudentPlayer;

// 选手需要将两个都定义,本份代码中不选择的阵营任意定义即可
extern const THUAI6::ButcherType butcherType = THUAI6::ButcherType::ButcherType1;
extern const THUAI6::TrickerType trickerType = THUAI6::TrickerType::TrickerType1;

extern const THUAI6::HumanType humanType = THUAI6::HumanType::HumanType1;
extern const THUAI6::StudentType studentType = THUAI6::StudentType::StudentType1;

// 选手只需写一个即可,为了调试方便写了两个的话也不会有影响

void AI::play(IHumanAPI& api)
void AI::play(IStudentAPI& api)
{
api.Move(1, 1);
}

void AI::play(IButcherAPI& api)
void AI::play(ITrickerAPI& api)
{
}

+ 66
- 66
CAPI/API/src/API.cpp View File

@@ -3,141 +3,141 @@
#include "API.h"
#define PI 3.14159265358979323846

int HumanAPI::GetFrameCount() const
int StudentAPI::GetFrameCount() const
{
return logic.GetCounter();
}

int ButcherAPI::GetFrameCount() const
int TrickerAPI::GetFrameCount() const
{
return logic.GetCounter();
}

std::future<bool> HumanAPI::Move(int64_t timeInMilliseconds, double angleInRadian)
std::future<bool> StudentAPI::Move(int64_t timeInMilliseconds, double angleInRadian)
{
return std::async(std::launch::async, [&]()
{ return logic.Move(timeInMilliseconds, angleInRadian); });
}

std::future<bool> HumanAPI::MoveDown(int64_t timeInMilliseconds)
std::future<bool> StudentAPI::MoveDown(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, 0);
}

std::future<bool> HumanAPI::MoveRight(int64_t timeInMilliseconds)
std::future<bool> StudentAPI::MoveRight(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, PI * 0.5);
}

std::future<bool> HumanAPI::MoveUp(int64_t timeInMilliseconds)
std::future<bool> StudentAPI::MoveUp(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, PI);
}

std::future<bool> HumanAPI::MoveLeft(int64_t timeInMilliseconds)
std::future<bool> StudentAPI::MoveLeft(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, PI * 1.5);
}

std::future<bool> ButcherAPI::Move(int64_t timeInMilliseconds, double angleInRadian)
std::future<bool> TrickerAPI::Move(int64_t timeInMilliseconds, double angleInRadian)
{
return std::async(std::launch::async, [&]()
{ return logic.Move(timeInMilliseconds, angleInRadian); });
}

std::future<bool> ButcherAPI::MoveDown(int64_t timeInMilliseconds)
std::future<bool> TrickerAPI::MoveDown(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, 0);
}

std::future<bool> ButcherAPI::MoveRight(int64_t timeInMilliseconds)
std::future<bool> TrickerAPI::MoveRight(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, PI * 0.5);
}

std::future<bool> ButcherAPI::MoveUp(int64_t timeInMilliseconds)
std::future<bool> TrickerAPI::MoveUp(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, PI);
}

std::future<bool> ButcherAPI::MoveLeft(int64_t timeInMilliseconds)
std::future<bool> TrickerAPI::MoveLeft(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, PI * 1.5);
}

std::future<bool> HumanAPI::PickProp(THUAI6::PropType prop)
std::future<bool> StudentAPI::PickProp(THUAI6::PropType prop)
{
return std::async(std::launch::async, [&]()
{ return logic.PickProp(prop); });
}

std::future<bool> HumanAPI::UseProp()
std::future<bool> StudentAPI::UseProp()
{
return std::async(std::launch::async, [&]()
{ return logic.UseProp(); });
}

std::future<bool> ButcherAPI::PickProp(THUAI6::PropType prop)
std::future<bool> TrickerAPI::PickProp(THUAI6::PropType prop)
{
return std::async(std::launch::async, [&]()
{ return logic.PickProp(prop); });
}

std::future<bool> ButcherAPI::UseProp()
std::future<bool> TrickerAPI::UseProp()
{
return std::async(std::launch::async, [&]()
{ return logic.UseProp(); });
}

std::future<bool> HumanAPI::UseSkill()
std::future<bool> StudentAPI::UseSkill()
{
return std::async(std::launch::async, [&]()
{ return logic.UseSkill(); });
}

std::future<bool> ButcherAPI::UseSkill()
std::future<bool> TrickerAPI::UseSkill()
{
return std::async(std::launch::async, [&]()
{ return logic.UseSkill(); });
}

std::future<bool> HumanAPI::SendMessage(int64_t toID, std::string message)
std::future<bool> StudentAPI::SendMessage(int64_t toID, std::string message)
{
return std::async(std::launch::async, [&]()
{ return logic.SendMessage(toID, message); });
}

std::future<bool> ButcherAPI::SendMessage(int64_t toID, std::string message)
std::future<bool> TrickerAPI::SendMessage(int64_t toID, std::string message)
{
return std::async(std::launch::async, [&]()
{ return logic.SendMessage(toID, message); });
}

std::future<bool> HumanAPI::HaveMessage()
std::future<bool> StudentAPI::HaveMessage()
{
return std::async(std::launch::async, [&]()
{ return logic.HaveMessage(); });
}

std::future<bool> ButcherAPI::HaveMessage()
std::future<bool> TrickerAPI::HaveMessage()
{
return std::async(std::launch::async, [&]()
{ return logic.HaveMessage(); });
}

std::future<std::optional<std::pair<int64_t, std::string>>> HumanAPI::GetMessage()
std::future<std::optional<std::pair<int64_t, std::string>>> StudentAPI::GetMessage()
{
return std::async(std::launch::async, [&]()
{ return logic.GetMessage(); });
}

std::future<std::optional<std::pair<int64_t, std::string>>> ButcherAPI::GetMessage()
std::future<std::optional<std::pair<int64_t, std::string>>> TrickerAPI::GetMessage()
{
return std::async(std::launch::async, [&]()
{ return logic.GetMessage(); });
}

std::future<bool> HumanAPI::Wait()
std::future<bool> StudentAPI::Wait()
{
if (logic.GetCounter() == -1)
return std::async(std::launch::async, [&]()
@@ -147,7 +147,7 @@ std::future<bool> HumanAPI::Wait()
{ return logic.WaitThread(); });
}

std::future<bool> ButcherAPI::Wait()
std::future<bool> TrickerAPI::Wait()
{
if (logic.GetCounter() == -1)
return std::async(std::launch::async, [&]()
@@ -157,136 +157,136 @@ std::future<bool> ButcherAPI::Wait()
{ return logic.WaitThread(); });
}

std::vector<std::shared_ptr<const THUAI6::Butcher>> HumanAPI::GetButchers() const
std::vector<std::shared_ptr<const THUAI6::Tricker>> StudentAPI::GetTrickers() const
{
return logic.GetButchers();
return logic.GetTrickers();
}

std::vector<std::shared_ptr<const THUAI6::Human>> HumanAPI::GetHumans() const
std::vector<std::shared_ptr<const THUAI6::Student>> StudentAPI::GetStudents() const
{
return logic.GetHumans();
return logic.GetStudents();
}

std::vector<std::shared_ptr<const THUAI6::Butcher>> ButcherAPI::GetButchers() const
std::vector<std::shared_ptr<const THUAI6::Tricker>> TrickerAPI::GetTrickers() const
{
return logic.GetButchers();
return logic.GetTrickers();
}

std::vector<std::shared_ptr<const THUAI6::Human>> ButcherAPI::GetHumans() const
std::vector<std::shared_ptr<const THUAI6::Student>> TrickerAPI::GetStudents() const
{
return logic.GetHumans();
return logic.GetStudents();
}

std::vector<std::shared_ptr<const THUAI6::Prop>> HumanAPI::GetProps() const
std::vector<std::shared_ptr<const THUAI6::Prop>> StudentAPI::GetProps() const
{
return logic.GetProps();
}

std::vector<std::shared_ptr<const THUAI6::Prop>> ButcherAPI::GetProps() const
std::vector<std::shared_ptr<const THUAI6::Prop>> TrickerAPI::GetProps() const
{
return logic.GetProps();
}

std::vector<std::vector<THUAI6::PlaceType>> HumanAPI::GetFullMap() const
std::vector<std::vector<THUAI6::PlaceType>> StudentAPI::GetFullMap() const
{
return logic.GetFullMap();
}

THUAI6::PlaceType HumanAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
THUAI6::PlaceType StudentAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
{
return logic.GetPlaceType(cellX, cellY);
}

THUAI6::PlaceType ButcherAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
THUAI6::PlaceType TrickerAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
{
return logic.GetPlaceType(cellX, cellY);
}

std::vector<std::vector<THUAI6::PlaceType>> ButcherAPI::GetFullMap() const
std::vector<std::vector<THUAI6::PlaceType>> TrickerAPI::GetFullMap() const
{
return logic.GetFullMap();
}

const std::vector<int64_t> HumanAPI::GetPlayerGUIDs() const
const std::vector<int64_t> StudentAPI::GetPlayerGUIDs() const
{
return logic.GetPlayerGUIDs();
}

const std::vector<int64_t> ButcherAPI::GetPlayerGUIDs() const
const std::vector<int64_t> TrickerAPI::GetPlayerGUIDs() const
{
return logic.GetPlayerGUIDs();
}

std::future<bool> HumanAPI::StartFixMachine()
std::future<bool> StudentAPI::StartLearning()
{
return std::async(std::launch::async, [&]()
{ return logic.StartFixMachine(); });
{ return logic.StartLearning(); });
}

std::future<bool> HumanAPI::EndFixMachine()
std::future<bool> StudentAPI::EndLearning()
{
return std::async(std::launch::async, [&]()
{ return logic.EndFixMachine(); });
{ return logic.EndLearning(); });
}

std::future<bool> HumanAPI::StartSaveHuman()
std::future<bool> StudentAPI::StartHelpMate()
{
return std::async(std::launch::async, [&]()
{ return logic.StartSaveHuman(); });
{ return logic.StartHelpMate(); });
}

std::future<bool> HumanAPI::EndSaveHuman()
std::future<bool> StudentAPI::EndHelpMate()
{
return std::async(std::launch::async, [&]()
{ return logic.EndSaveHuman(); });
{ return logic.EndHelpMate(); });
}

std::future<bool> HumanAPI::Escape()
std::future<bool> StudentAPI::Graduate()
{
return std::async(std::launch::async, [&]()
{ return logic.Escape(); });
{ return logic.Graduate(); });
}

std::shared_ptr<const THUAI6::Human> HumanAPI::GetSelfInfo() const
std::shared_ptr<const THUAI6::Student> StudentAPI::GetSelfInfo() const
{
return logic.HumanGetSelfInfo();
return logic.StudentGetSelfInfo();
}

std::future<bool> ButcherAPI::Attack(double angleInRadian)
std::future<bool> TrickerAPI::Trick(double angleInRadian)
{
return std::async(std::launch::async, [&]()
{ return logic.Attack(angleInRadian); });
{ return logic.Trick(angleInRadian); });
}

std::future<bool> ButcherAPI::CarryHuman()
std::future<bool> TrickerAPI::StartExam()
{
return std::async(std::launch::async, [&]()
{ return logic.CarryHuman(); });
{ return logic.StartExam(); });
}

std::future<bool> ButcherAPI::ReleaseHuman()
std::future<bool> TrickerAPI::EndExam()
{
return std::async(std::launch::async, [&]()
{ return logic.ReleaseHuman(); });
{ return logic.EndExam(); });
}

std::future<bool> ButcherAPI::HangHuman()
std::future<bool> TrickerAPI::MakeFail()
{
return std::async(std::launch::async, [&]()
{ return logic.HangHuman(); });
{ return logic.MakeFail(); });
}

std::shared_ptr<const THUAI6::Butcher> ButcherAPI::GetSelfInfo() const
std::shared_ptr<const THUAI6::Tricker> TrickerAPI::GetSelfInfo() const
{
return logic.ButcherGetSelfInfo();
return logic.TrickerGetSelfInfo();
}

void HumanAPI::Play(IAI& ai)
void StudentAPI::Play(IAI& ai)
{
ai.play(*this);
}

void ButcherAPI::Play(IAI& ai)
void TrickerAPI::Play(IAI& ai)
{
ai.play(*this);
}

+ 39
- 39
CAPI/API/src/Communication.cpp View File

@@ -75,110 +75,110 @@ bool Communication::SendMessage(int64_t toID, std::string message, int64_t playe
return false;
}

bool Communication::Escape(int64_t playerID)
bool Communication::Graduate(int64_t playerID)
{
protobuf::BoolRes escapeResult;
protobuf::BoolRes graduateResult;
ClientContext context;
auto request = THUAI62Proto::THUAI62ProtobufID(playerID);
auto status = THUAI6Stub->Escape(&context, request, &escapeResult);
auto status = THUAI6Stub->Graduate(&context, request, &graduateResult);
if (status.ok())
return escapeResult.act_success();
return graduateResult.act_success();
else
return false;
}

bool Communication::StartFixMachine(int64_t playerID)
bool Communication::StartLearning(int64_t playerID)
{
protobuf::BoolRes startFixMachineResult;
protobuf::BoolRes startLearningResult;
ClientContext context;
auto request = THUAI62Proto::THUAI62ProtobufID(playerID);
auto status = THUAI6Stub->StartFixMachine(&context, request, &startFixMachineResult);
auto status = THUAI6Stub->StartLearning(&context, request, &startLearningResult);
if (status.ok())
return startFixMachineResult.act_success();
return startLearningResult.act_success();
else
return false;
}

bool Communication::EndFixMachine(int64_t playerID)
bool Communication::EndLearning(int64_t playerID)
{
protobuf::BoolRes endFixMachineResult;
protobuf::BoolRes endLearningResult;
ClientContext context;
auto request = THUAI62Proto::THUAI62ProtobufID(playerID);
auto status = THUAI6Stub->EndFixMachine(&context, request, &endFixMachineResult);
auto status = THUAI6Stub->EndLearning(&context, request, &endLearningResult);
if (status.ok())
return endFixMachineResult.act_success();
return endLearningResult.act_success();
else
return false;
}

bool Communication::StartSaveHuman(int64_t playerID)
bool Communication::StartHelpMate(int64_t playerID)
{
protobuf::BoolRes saveHumanResult;
protobuf::BoolRes saveStudentResult;
ClientContext context;
auto request = THUAI62Proto::THUAI62ProtobufID(playerID);
auto status = THUAI6Stub->StartSaveHuman(&context, request, &saveHumanResult);
auto status = THUAI6Stub->StartHelpMate(&context, request, &saveStudentResult);
if (status.ok())
return saveHumanResult.act_success();
return saveStudentResult.act_success();
else
return false;
}

bool Communication::EndSaveHuman(int64_t playerID)
bool Communication::EndHelpMate(int64_t playerID)
{
protobuf::BoolRes saveHumanResult;
protobuf::BoolRes saveStudentResult;
ClientContext context;
auto request = THUAI62Proto::THUAI62ProtobufID(playerID);
auto status = THUAI6Stub->EndSaveHuman(&context, request, &saveHumanResult);
auto status = THUAI6Stub->EndHelpMate(&context, request, &saveStudentResult);
if (status.ok())
return saveHumanResult.act_success();
return saveStudentResult.act_success();
else
return false;
}

bool Communication::Attack(double angle, int64_t playerID)
bool Communication::Trick(double angle, int64_t playerID)
{
protobuf::BoolRes attackResult;
protobuf::BoolRes trickResult;
ClientContext context;
auto request = THUAI62Proto::THUAI62ProtobufAttack(angle, playerID);
auto status = THUAI6Stub->Attack(&context, request, &attackResult);
auto request = THUAI62Proto::THUAI62ProtobufTrick(angle, playerID);
auto status = THUAI6Stub->Trick(&context, request, &trickResult);
if (status.ok())
return attackResult.act_success();
return trickResult.act_success();
else
return false;
}

bool Communication::CarryHuman(int64_t playerID)
bool Communication::StartExam(int64_t playerID)
{
protobuf::BoolRes carryHumanResult;
protobuf::BoolRes startExamResult;
ClientContext context;
auto request = THUAI62Proto::THUAI62ProtobufID(playerID);
auto status = THUAI6Stub->CarryHuman(&context, request, &carryHumanResult);
auto status = THUAI6Stub->StartExam(&context, request, &startExamResult);
if (status.ok())
return carryHumanResult.act_success();
return startExamResult.act_success();
else
return false;
}

bool Communication::ReleaseHuman(int64_t playerID)
bool Communication::EndExam(int64_t playerID)
{
protobuf::BoolRes releaseHumanResult;
protobuf::BoolRes endExamResult;
ClientContext context;
auto request = THUAI62Proto::THUAI62ProtobufID(playerID);
auto status = THUAI6Stub->ReleaseHuman(&context, request, &releaseHumanResult);
auto status = THUAI6Stub->EndExam(&context, request, &endExamResult);
if (status.ok())
return releaseHumanResult.act_success();
return endExamResult.act_success();
else
return false;
}

bool Communication::HangHuman(int64_t playerID)
bool Communication::MakeFail(int64_t playerID)
{
protobuf::BoolRes hangHumanResult;
protobuf::BoolRes makeFailResult;
ClientContext context;
auto request = THUAI62Proto::THUAI62ProtobufID(playerID);
auto status = THUAI6Stub->HangHuman(&context, request, &hangHumanResult);
auto status = THUAI6Stub->MakeFail(&context, request, &makeFailResult);
if (status.ok())
return hangHumanResult.act_success();
return makeFailResult.act_success();
else
return false;
}
@@ -233,11 +233,11 @@ void Communication::ReadMessage(int64_t playerID)
std::thread(tRead).detach();
}

void Communication::AddPlayer(int64_t playerID, THUAI6::PlayerType playerType, THUAI6::HumanType humanType, THUAI6::ButcherType butcherType)
void Communication::AddPlayer(int64_t playerID, THUAI6::PlayerType playerType, THUAI6::StudentType studentType, THUAI6::TrickerType trickerType)
{
auto tMessage = [=]()
{
protobuf::PlayerMsg playerMsg = THUAI62Proto::THUAI62ProtobufPlayer(playerID, playerType, humanType, butcherType);
protobuf::PlayerMsg playerMsg = THUAI62Proto::THUAI62ProtobufPlayer(playerID, playerType, studentType, trickerType);
grpc::ClientContext context;
auto MessageReader = THUAI6Stub->AddPlayer(&context, playerMsg);



+ 143
- 143
CAPI/API/src/DebugAPI.cpp View File

@@ -6,7 +6,7 @@
#include "structures.h"
#define PI 3.14159265358979323846

HumanDebugAPI::HumanDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t playerID) :
StudentDebugAPI::StudentDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t playerID) :
logic(logic)
{
std::string fileName = "logs/api-" + std::to_string(playerID) + "-log.txt";
@@ -28,7 +28,7 @@ HumanDebugAPI::HumanDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly
logger = std::make_unique<spdlog::logger>("apiLogger", spdlog::sinks_init_list{fileLogger, printLogger});
}

ButcherDebugAPI::ButcherDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t playerID) :
TrickerDebugAPI::TrickerDebugAPI(ILogic& logic, bool file, bool print, bool warnOnly, int64_t playerID) :
logic(logic)
{
std::string fileName = "logs/api-" + std::to_string(playerID) + "-log.txt";
@@ -50,7 +50,7 @@ ButcherDebugAPI::ButcherDebugAPI(ILogic& logic, bool file, bool print, bool warn
logger = std::make_unique<spdlog::logger>("apiLogger", spdlog::sinks_init_list{fileLogger, printLogger});
}

void HumanDebugAPI::StartTimer()
void StudentDebugAPI::StartTimer()
{
startPoint = std::chrono::system_clock::now();
std::time_t t = std::chrono::system_clock::to_time_t(startPoint);
@@ -58,7 +58,7 @@ void HumanDebugAPI::StartTimer()
logger->info("StartTimer: {}", std::ctime(&t));
}

void ButcherDebugAPI::StartTimer()
void TrickerDebugAPI::StartTimer()
{
startPoint = std::chrono::system_clock::now();
std::time_t t = std::chrono::system_clock::to_time_t(startPoint);
@@ -66,27 +66,27 @@ void ButcherDebugAPI::StartTimer()
logger->info("StartTimer: {}", std::ctime(&t));
}

void HumanDebugAPI::EndTimer()
void StudentDebugAPI::EndTimer()
{
logger->info("Time elapsed: {}ms", Time::TimeSinceStart(startPoint));
}

void ButcherDebugAPI::EndTimer()
void TrickerDebugAPI::EndTimer()
{
logger->info("Time elapsed: {}ms", Time::TimeSinceStart(startPoint));
}

int HumanDebugAPI::GetFrameCount() const
int StudentDebugAPI::GetFrameCount() const
{
return logic.GetCounter();
}

int ButcherDebugAPI::GetFrameCount() const
int TrickerDebugAPI::GetFrameCount() const
{
return logic.GetCounter();
}

std::future<bool> HumanDebugAPI::Move(int64_t timeInMilliseconds, double angleInRadian)
std::future<bool> StudentDebugAPI::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, [=]()
@@ -96,27 +96,27 @@ std::future<bool> HumanDebugAPI::Move(int64_t timeInMilliseconds, double angleIn
return result; });
}

std::future<bool> HumanDebugAPI::MoveDown(int64_t timeInMilliseconds)
std::future<bool> StudentDebugAPI::MoveDown(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, 0);
}

std::future<bool> HumanDebugAPI::MoveRight(int64_t timeInMilliseconds)
std::future<bool> StudentDebugAPI::MoveRight(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, PI * 0.5);
}

std::future<bool> HumanDebugAPI::MoveUp(int64_t timeInMilliseconds)
std::future<bool> StudentDebugAPI::MoveUp(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, PI);
}

std::future<bool> HumanDebugAPI::MoveLeft(int64_t timeInMilliseconds)
std::future<bool> StudentDebugAPI::MoveLeft(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, PI * 1.5);
}

std::future<bool> ButcherDebugAPI::Move(int64_t timeInMilliseconds, double angleInRadian)
std::future<bool> TrickerDebugAPI::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, [=]()
@@ -126,27 +126,27 @@ std::future<bool> ButcherDebugAPI::Move(int64_t timeInMilliseconds, double angle
return result; });
}

std::future<bool> ButcherDebugAPI::MoveDown(int64_t timeInMilliseconds)
std::future<bool> TrickerDebugAPI::MoveDown(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, 0);
}

std::future<bool> ButcherDebugAPI::MoveRight(int64_t timeInMilliseconds)
std::future<bool> TrickerDebugAPI::MoveRight(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, PI * 0.5);
}

std::future<bool> ButcherDebugAPI::MoveUp(int64_t timeInMilliseconds)
std::future<bool> TrickerDebugAPI::MoveUp(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, PI);
}

std::future<bool> ButcherDebugAPI::MoveLeft(int64_t timeInMilliseconds)
std::future<bool> TrickerDebugAPI::MoveLeft(int64_t timeInMilliseconds)
{
return Move(timeInMilliseconds, PI * 1.5);
}

std::future<bool> HumanDebugAPI::PickProp(THUAI6::PropType prop)
std::future<bool> StudentDebugAPI::PickProp(THUAI6::PropType prop)
{
logger->info("PickProp: prop = {}, called at {}ms", THUAI6::propTypeDict[prop], Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [=]()
@@ -156,7 +156,7 @@ std::future<bool> HumanDebugAPI::PickProp(THUAI6::PropType prop)
return result; });
}

std::future<bool> HumanDebugAPI::UseProp()
std::future<bool> StudentDebugAPI::UseProp()
{
logger->info("UseProp: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [=]()
@@ -166,7 +166,7 @@ std::future<bool> HumanDebugAPI::UseProp()
return result; });
}

std::future<bool> ButcherDebugAPI::PickProp(THUAI6::PropType prop)
std::future<bool> TrickerDebugAPI::PickProp(THUAI6::PropType prop)
{
logger->info("PickProp: prop = {}, called at {}ms", THUAI6::propTypeDict[prop], Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [=]()
@@ -176,7 +176,7 @@ std::future<bool> ButcherDebugAPI::PickProp(THUAI6::PropType prop)
return result; });
}

std::future<bool> ButcherDebugAPI::UseProp()
std::future<bool> TrickerDebugAPI::UseProp()
{
logger->info("UseProp: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [this]()
@@ -186,7 +186,7 @@ std::future<bool> ButcherDebugAPI::UseProp()
return result; });
}

std::future<bool> HumanDebugAPI::UseSkill()
std::future<bool> StudentDebugAPI::UseSkill()
{
logger->info("UseSkill: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [this]()
@@ -196,7 +196,7 @@ std::future<bool> HumanDebugAPI::UseSkill()
return result; });
}

std::future<bool> ButcherDebugAPI::UseSkill()
std::future<bool> TrickerDebugAPI::UseSkill()
{
logger->info("UseSkill: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [this]()
@@ -206,7 +206,7 @@ std::future<bool> ButcherDebugAPI::UseSkill()
return result; });
}

std::future<bool> HumanDebugAPI::SendMessage(int64_t toID, std::string message)
std::future<bool> StudentDebugAPI::SendMessage(int64_t toID, std::string message)
{
logger->info("SendMessage: toID = {}, message = {}, called at {}ms", toID, message, Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [=]()
@@ -216,7 +216,7 @@ std::future<bool> HumanDebugAPI::SendMessage(int64_t toID, std::string message)
return result; });
}

std::future<bool> ButcherDebugAPI::SendMessage(int64_t toID, std::string message)
std::future<bool> TrickerDebugAPI::SendMessage(int64_t toID, std::string message)
{
logger->info("SendMessage: toID = {}, message = {}, called at {}ms", toID, message, Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [=]()
@@ -226,7 +226,7 @@ std::future<bool> ButcherDebugAPI::SendMessage(int64_t toID, std::string message
return result; });
}

std::future<bool> HumanDebugAPI::HaveMessage()
std::future<bool> StudentDebugAPI::HaveMessage()
{
logger->info("HaveMessage: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [this]()
@@ -236,7 +236,7 @@ std::future<bool> HumanDebugAPI::HaveMessage()
return result; });
}

std::future<bool> ButcherDebugAPI::HaveMessage()
std::future<bool> TrickerDebugAPI::HaveMessage()
{
logger->info("HaveMessage: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [this]()
@@ -246,7 +246,7 @@ std::future<bool> ButcherDebugAPI::HaveMessage()
return result; });
}

std::future<std::optional<std::pair<int64_t, std::string>>> HumanDebugAPI::GetMessage()
std::future<std::optional<std::pair<int64_t, std::string>>> StudentDebugAPI::GetMessage()
{
logger->info("GetMessage: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [this]()
@@ -256,7 +256,7 @@ std::future<std::optional<std::pair<int64_t, std::string>>> HumanDebugAPI::GetMe
return result; });
}

std::future<std::optional<std::pair<int64_t, std::string>>> ButcherDebugAPI::GetMessage()
std::future<std::optional<std::pair<int64_t, std::string>>> TrickerDebugAPI::GetMessage()
{
logger->info("GetMessage: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [this]()
@@ -266,7 +266,7 @@ std::future<std::optional<std::pair<int64_t, std::string>>> ButcherDebugAPI::Get
return result; });
}

std::future<bool> HumanDebugAPI::Wait()
std::future<bool> StudentDebugAPI::Wait()
{
logger->info("Wait: called at {}ms", Time::TimeSinceStart(startPoint));
if (logic.GetCounter() == -1)
@@ -277,7 +277,7 @@ std::future<bool> HumanDebugAPI::Wait()
{ return logic.WaitThread(); });
}

std::future<bool> ButcherDebugAPI::Wait()
std::future<bool> TrickerDebugAPI::Wait()
{
logger->info("Wait: called at {}ms", Time::TimeSinceStart(startPoint));
if (logic.GetCounter() == -1)
@@ -288,231 +288,231 @@ std::future<bool> ButcherDebugAPI::Wait()
{ return logic.WaitThread(); });
}

std::vector<std::shared_ptr<const THUAI6::Butcher>> HumanDebugAPI::GetButchers() const
std::vector<std::shared_ptr<const THUAI6::Tricker>> StudentDebugAPI::GetTrickers() const
{
return logic.GetButchers();
return logic.GetTrickers();
}

std::vector<std::shared_ptr<const THUAI6::Human>> HumanDebugAPI::GetHumans() const
std::vector<std::shared_ptr<const THUAI6::Student>> StudentDebugAPI::GetStudents() const
{
return logic.GetHumans();
return logic.GetStudents();
}

std::vector<std::shared_ptr<const THUAI6::Butcher>> ButcherDebugAPI::GetButchers() const
std::vector<std::shared_ptr<const THUAI6::Tricker>> TrickerDebugAPI::GetTrickers() const
{
return logic.GetButchers();
return logic.GetTrickers();
}

std::vector<std::shared_ptr<const THUAI6::Human>> ButcherDebugAPI::GetHumans() const
std::vector<std::shared_ptr<const THUAI6::Student>> TrickerDebugAPI::GetStudents() const
{
return logic.GetHumans();
return logic.GetStudents();
}

std::vector<std::shared_ptr<const THUAI6::Prop>> HumanDebugAPI::GetProps() const
std::vector<std::shared_ptr<const THUAI6::Prop>> StudentDebugAPI::GetProps() const
{
return logic.GetProps();
}

std::vector<std::shared_ptr<const THUAI6::Prop>> ButcherDebugAPI::GetProps() const
std::vector<std::shared_ptr<const THUAI6::Prop>> TrickerDebugAPI::GetProps() const
{
return logic.GetProps();
}

std::vector<std::vector<THUAI6::PlaceType>> HumanDebugAPI::GetFullMap() const
std::vector<std::vector<THUAI6::PlaceType>> StudentDebugAPI::GetFullMap() const
{
return logic.GetFullMap();
}

THUAI6::PlaceType HumanDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
THUAI6::PlaceType StudentDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
{
return logic.GetPlaceType(cellX, cellY);
}

THUAI6::PlaceType ButcherDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
THUAI6::PlaceType TrickerDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
{
return logic.GetPlaceType(cellX, cellY);
}

std::vector<std::vector<THUAI6::PlaceType>> ButcherDebugAPI::GetFullMap() const
std::vector<std::vector<THUAI6::PlaceType>> TrickerDebugAPI::GetFullMap() const
{
return logic.GetFullMap();
}

const std::vector<int64_t> HumanDebugAPI::GetPlayerGUIDs() const
const std::vector<int64_t> StudentDebugAPI::GetPlayerGUIDs() const
{
return logic.GetPlayerGUIDs();
}

const std::vector<int64_t> ButcherDebugAPI::GetPlayerGUIDs() const
const std::vector<int64_t> TrickerDebugAPI::GetPlayerGUIDs() const
{
return logic.GetPlayerGUIDs();
}

std::future<bool> HumanDebugAPI::StartFixMachine()
std::future<bool> StudentDebugAPI::StartLearning()
{
logger->info("StartFixMachine: called at {}ms", Time::TimeSinceStart(startPoint));
logger->info("StartLearning: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [this]()
{ auto result = logic.StartFixMachine();
{ auto result = logic.StartLearning();
if (!result)
logger->warn("StartFixMachine: failed at {}ms", Time::TimeSinceStart(startPoint));
logger->warn("StartLearning: failed at {}ms", Time::TimeSinceStart(startPoint));
return result; });
}

std::future<bool> HumanDebugAPI::EndFixMachine()
std::future<bool> StudentDebugAPI::EndLearning()
{
logger->info("EndFixMachine: called at {}ms", Time::TimeSinceStart(startPoint));
logger->info("EndLearning: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [this]()
{ auto result = logic.EndFixMachine();
{ auto result = logic.EndLearning();
if (!result)
logger->warn("EndFixMachine: failed at {}ms", Time::TimeSinceStart(startPoint));
logger->warn("EndLearning: failed at {}ms", Time::TimeSinceStart(startPoint));
return result; });
}

std::future<bool> HumanDebugAPI::StartSaveHuman()
std::future<bool> StudentDebugAPI::StartHelpMate()
{
logger->info("StartSaveHuman: called at {}ms", Time::TimeSinceStart(startPoint));
logger->info("StartHelpMate: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [this]()
{ auto result = logic.StartSaveHuman();
{ auto result = logic.StartHelpMate();
if (!result)
logger->warn("StartSaveHuman: failed at {}ms", Time::TimeSinceStart(startPoint));
logger->warn("StartHelpMate: failed at {}ms", Time::TimeSinceStart(startPoint));
return result; });
}

std::future<bool> HumanDebugAPI::EndSaveHuman()
std::future<bool> StudentDebugAPI::EndHelpMate()
{
logger->info("EndSaveHuman: called at {}ms", Time::TimeSinceStart(startPoint));
logger->info("EndHelpMate: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [this]()
{ auto result = logic.EndSaveHuman();
{ auto result = logic.EndHelpMate();
if (!result)
logger->warn("EndSaveHuman: failed at {}ms", Time::TimeSinceStart(startPoint));
logger->warn("EndHelpMate: failed at {}ms", Time::TimeSinceStart(startPoint));
return result; });
}

std::future<bool> HumanDebugAPI::Escape()
std::future<bool> StudentDebugAPI::Graduate()
{
logger->info("Escape: called at {}ms", Time::TimeSinceStart(startPoint));
logger->info("Graduate: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [this]()
{ auto result = logic.Escape();
{ auto result = logic.Graduate();
if (!result)
logger->warn("Escape: failed at {}ms", Time::TimeSinceStart(startPoint));
logger->warn("Graduate: failed at {}ms", Time::TimeSinceStart(startPoint));
return result; });
}

std::shared_ptr<const THUAI6::Human> HumanDebugAPI::GetSelfInfo() const
std::shared_ptr<const THUAI6::Student> StudentDebugAPI::GetSelfInfo() const
{
return logic.HumanGetSelfInfo();
return logic.StudentGetSelfInfo();
}

std::future<bool> ButcherDebugAPI::Attack(double angleInRadian)
std::future<bool> TrickerDebugAPI::Trick(double angleInRadian)
{
logger->info("Attack: angleInRadian = {}, called at {}ms", angleInRadian, Time::TimeSinceStart(startPoint));
logger->info("Trick: angleInRadian = {}, called at {}ms", angleInRadian, Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [=]()
{ auto result = logic.Attack(angleInRadian);
{ auto result = logic.Trick(angleInRadian);
if (!result)
logger->warn("Attack: failed at {}ms", Time::TimeSinceStart(startPoint));
logger->warn("Trick: failed at {}ms", Time::TimeSinceStart(startPoint));
return result; });
}

std::future<bool> ButcherDebugAPI::CarryHuman()
std::future<bool> TrickerDebugAPI::StartExam()
{
logger->info("CarryHuman: called at {}ms", Time::TimeSinceStart(startPoint));
logger->info("StartExam: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [this]()
{ auto result = logic.CarryHuman();
{ auto result = logic.StartExam();
if (!result)
logger->warn("CarryHuman: failed at {}ms", Time::TimeSinceStart(startPoint));
logger->warn("StartExam: failed at {}ms", Time::TimeSinceStart(startPoint));
return result; });
}

std::future<bool> ButcherDebugAPI::ReleaseHuman()
std::future<bool> TrickerDebugAPI::EndExam()
{
logger->info("ReleaseHuman: called at {}ms", Time::TimeSinceStart(startPoint));
logger->info("EndExam: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [this]()
{ auto result = logic.ReleaseHuman();
{ auto result = logic.EndExam();
if (!result)
logger->warn("ReleaseHuman: failed at {}ms", Time::TimeSinceStart(startPoint));
logger->warn("EndExam: failed at {}ms", Time::TimeSinceStart(startPoint));
return result; });
}

std::future<bool> ButcherDebugAPI::HangHuman()
std::future<bool> TrickerDebugAPI::MakeFail()
{
logger->info("HangHuman: called at {}ms", Time::TimeSinceStart(startPoint));
logger->info("MakeFail: called at {}ms", Time::TimeSinceStart(startPoint));
return std::async(std::launch::async, [this]()
{ auto result = logic.HangHuman();
{ auto result = logic.MakeFail();
if (!result)
logger->warn("HangHuman: failed at {}ms", Time::TimeSinceStart(startPoint));
logger->warn("MakeFail: failed at {}ms", Time::TimeSinceStart(startPoint));
return result; });
}

std::shared_ptr<const THUAI6::Butcher> ButcherDebugAPI::GetSelfInfo() const
std::shared_ptr<const THUAI6::Tricker> TrickerDebugAPI::GetSelfInfo() const
{
return logic.ButcherGetSelfInfo();
return logic.TrickerGetSelfInfo();
}

void HumanDebugAPI::PrintHuman() const
void StudentDebugAPI::PrintStudent() const
{
for (auto human : logic.GetHumans())
for (auto student : logic.GetStudents())
{
logger->info("******Human Info******");
logger->info("playerID={}, GUID={}, x={}, y={}", human->playerID, human->guid, human->x, human->y);
logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", human->speed, human->viewRange, human->timeUntilSkillAvailable, THUAI6::propTypeDict[human->prop], THUAI6::placeTypeDict[human->place]);
logger->info("state={}, life={}, hanged time={}", THUAI6::humanStateDict[human->state], human->life, human->hangedTime);
std::string humanBuff = "buff=";
for (auto buff : human->buff)
humanBuff += THUAI6::humanBuffDict[buff] + ", ";
logger->info(humanBuff);
logger->info("******Student Info******");
logger->info("playerID={}, GUID={}, x={}, y={}", student->playerID, student->guid, student->x, student->y);
logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", student->speed, student->viewRange, student->timeUntilSkillAvailable, THUAI6::propTypeDict[student->prop], THUAI6::placeTypeDict[student->place]);
logger->info("state={}, determination={}, fail num={}, fail time={}, emo time={}", THUAI6::studentStateDict[student->state], student->determination, student->failNum, student->failTime, student->emoTime);
std::string studentBuff = "buff=";
for (auto buff : student->buff)
studentBuff += THUAI6::studentBuffDict[buff] + ", ";
logger->info(studentBuff);
logger->info("**********************");
}
}

void ButcherDebugAPI::PrintHuman() const
void TrickerDebugAPI::PrintStudent() const
{
for (auto human : logic.GetHumans())
for (auto student : logic.GetStudents())
{
logger->info("******Human Info******");
logger->info("playerID={}, GUID={}, x={}, y={}", human->playerID, human->guid, human->x, human->y);
logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", human->speed, human->viewRange, human->timeUntilSkillAvailable, THUAI6::propTypeDict[human->prop], THUAI6::placeTypeDict[human->place]);
logger->info("state={}, life={}, hanged time={}", THUAI6::humanStateDict[human->state], human->life, human->hangedTime);
std::string humanBuff = "buff=";
for (auto buff : human->buff)
humanBuff += THUAI6::humanBuffDict[buff] + ", ";
logger->info(humanBuff);
logger->info("******Student Info******");
logger->info("playerID={}, GUID={}, x={}, y={}", student->playerID, student->guid, student->x, student->y);
logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", student->speed, student->viewRange, student->timeUntilSkillAvailable, THUAI6::propTypeDict[student->prop], THUAI6::placeTypeDict[student->place]);
logger->info("state={}, determination={}, fail num={}, fail time={}, emo time={}", THUAI6::studentStateDict[student->state], student->determination, student->failNum, student->failTime, student->emoTime);
std::string studentBuff = "buff=";
for (auto buff : student->buff)
studentBuff += THUAI6::studentBuffDict[buff] + ", ";
logger->info(studentBuff);
logger->info("**********************");
}
}

void HumanDebugAPI::PrintButcher() const
void StudentDebugAPI::PrintTricker() const
{
for (auto butcher : logic.GetButchers())
for (auto tricker : logic.GetTrickers())
{
logger->info("******Butcher Info******");
logger->info("playerID={}, GUID={}, x={}, y={}", butcher->playerID, butcher->guid, butcher->x, butcher->y);
logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", butcher->speed, butcher->viewRange, butcher->timeUntilSkillAvailable, THUAI6::propTypeDict[butcher->prop], THUAI6::placeTypeDict[butcher->place]);
logger->info("damage={}, movable={}", butcher->damage, butcher->movable);
std::string butcherBuff = "buff=";
for (auto buff : butcher->buff)
butcherBuff += THUAI6::butcherBuffDict[buff] + ", ";
logger->info(butcherBuff);
logger->info("******Tricker Info******");
logger->info("playerID={}, GUID={}, x={}, y={}", tricker->playerID, tricker->guid, tricker->x, tricker->y);
logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", tricker->speed, tricker->viewRange, tricker->timeUntilSkillAvailable, THUAI6::propTypeDict[tricker->prop], THUAI6::placeTypeDict[tricker->place]);
logger->info("damage={}, movable={}", tricker->damage, tricker->movable);
std::string trickerBuff = "buff=";
for (auto buff : tricker->buff)
trickerBuff += THUAI6::trickerBuffDict[buff] + ", ";
logger->info(trickerBuff);
logger->info("************************");
}
}

void ButcherDebugAPI::PrintButcher() const
void TrickerDebugAPI::PrintTricker() const
{
for (auto butcher : logic.GetButchers())
for (auto tricker : logic.GetTrickers())
{
logger->info("******Butcher Info******");
logger->info("playerID={}, GUID={}, x={}, y={}", butcher->playerID, butcher->guid, butcher->x, butcher->y);
logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", butcher->speed, butcher->viewRange, butcher->timeUntilSkillAvailable, THUAI6::propTypeDict[butcher->prop], THUAI6::placeTypeDict[butcher->place]);
logger->info("damage={}, movable={}", butcher->damage, butcher->movable);
std::string butcherBuff = "buff=";
for (auto buff : butcher->buff)
butcherBuff += THUAI6::butcherBuffDict[buff] + ", ";
logger->info(butcherBuff);
logger->info("******Tricker Info******");
logger->info("playerID={}, GUID={}, x={}, y={}", tricker->playerID, tricker->guid, tricker->x, tricker->y);
logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", tricker->speed, tricker->viewRange, tricker->timeUntilSkillAvailable, THUAI6::propTypeDict[tricker->prop], THUAI6::placeTypeDict[tricker->place]);
logger->info("damage={}, movable={}", tricker->damage, tricker->movable);
std::string trickerBuff = "buff=";
for (auto buff : tricker->buff)
trickerBuff += THUAI6::trickerBuffDict[buff] + ", ";
logger->info(trickerBuff);
logger->info("************************");
}
}

void HumanDebugAPI::PrintProp() const
void StudentDebugAPI::PrintProp() const
{
for (auto prop : logic.GetProps())
{
@@ -522,7 +522,7 @@ void HumanDebugAPI::PrintProp() const
}
}

void ButcherDebugAPI::PrintProp() const
void TrickerDebugAPI::PrintProp() const
{
for (auto prop : logic.GetProps())
{
@@ -532,40 +532,40 @@ void ButcherDebugAPI::PrintProp() const
}
}

void HumanDebugAPI::PrintSelfInfo() const
void StudentDebugAPI::PrintSelfInfo() const
{
auto self = logic.HumanGetSelfInfo();
auto self = logic.StudentGetSelfInfo();
logger->info("******Self Info******");
logger->info("playerID={}, GUID={}, x={}, y={}", self->playerID, self->guid, self->x, self->y);
logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", self->speed, self->viewRange, self->timeUntilSkillAvailable, THUAI6::propTypeDict[self->prop], THUAI6::placeTypeDict[self->place]);
logger->info("state={}, life={}, hanged time={}", THUAI6::humanStateDict[self->state], self->life, self->hangedTime);
std::string humanBuff = "buff=";
logger->info("state={}, determination={}, fail num={}, fail time={}, emo time={}", THUAI6::studentStateDict[self->state], self->determination, self->failNum, self->failTime, self->emoTime);
std::string studentBuff = "buff=";
for (auto buff : self->buff)
humanBuff += THUAI6::humanBuffDict[buff] + ", ";
logger->info(humanBuff);
studentBuff += THUAI6::studentBuffDict[buff] + ", ";
logger->info(studentBuff);
logger->info("*********************");
}

void ButcherDebugAPI::PrintSelfInfo() const
void TrickerDebugAPI::PrintSelfInfo() const
{
auto self = logic.ButcherGetSelfInfo();
auto self = logic.TrickerGetSelfInfo();
logger->info("******Self Info******");
logger->info("playerID={}, GUID={}, x={}, y={}", self->playerID, self->guid, self->x, self->y);
logger->info("speed={}, view range={}, skill time={}, prop={}, place={}", self->speed, self->viewRange, self->timeUntilSkillAvailable, THUAI6::propTypeDict[self->prop], THUAI6::placeTypeDict[self->place]);
logger->info("damage={}, movable={}", self->damage, self->movable);
std::string butcherBuff = "buff=";
std::string trickerBuff = "buff=";
for (auto buff : self->buff)
butcherBuff += THUAI6::butcherBuffDict[buff] + ", ";
logger->info(butcherBuff);
trickerBuff += THUAI6::trickerBuffDict[buff] + ", ";
logger->info(trickerBuff);
logger->info("*********************");
}

void HumanDebugAPI::Play(IAI& ai)
void StudentDebugAPI::Play(IAI& ai)
{
ai.play(*this);
}

void ButcherDebugAPI::Play(IAI& ai)
void TrickerDebugAPI::Play(IAI& ai)
{
ai.play(*this);
}

+ 78
- 78
CAPI/API/src/logic.cpp View File

@@ -10,31 +10,31 @@

extern const bool asynchronous;

Logic::Logic(THUAI6::PlayerType type, int64_t ID, THUAI6::ButcherType butcher, THUAI6::HumanType human) :
Logic::Logic(THUAI6::PlayerType type, int64_t ID, THUAI6::TrickerType tricker, THUAI6::StudentType student) :
playerType(type),
playerID(ID),
butcherType(butcher),
humanType(human)
trickerType(tricker),
studentType(student)
{
currentState = &state[0];
bufferState = &state[1];
}

std::vector<std::shared_ptr<const THUAI6::Butcher>> Logic::GetButchers() const
std::vector<std::shared_ptr<const THUAI6::Tricker>> Logic::GetTrickers() const
{
std::lock_guard<std::mutex> lock(mtxState);
std::vector<std::shared_ptr<const THUAI6::Butcher>> temp;
temp.assign(currentState->butchers.begin(), currentState->butchers.end());
logger->debug("Called GetButchers");
std::vector<std::shared_ptr<const THUAI6::Tricker>> temp;
temp.assign(currentState->trickers.begin(), currentState->trickers.end());
logger->debug("Called GetTrickers");
return temp;
}

std::vector<std::shared_ptr<const THUAI6::Human>> Logic::GetHumans() const
std::vector<std::shared_ptr<const THUAI6::Student>> Logic::GetStudents() const
{
std::unique_lock<std::mutex> lock(mtxState);
std::vector<std::shared_ptr<const THUAI6::Human>> temp;
temp.assign(currentState->humans.begin(), currentState->humans.end());
logger->debug("Called GetHumans");
std::vector<std::shared_ptr<const THUAI6::Student>> temp;
temp.assign(currentState->students.begin(), currentState->students.end());
logger->debug("Called GetStudents");
return temp;
}

@@ -47,18 +47,18 @@ std::vector<std::shared_ptr<const THUAI6::Prop>> Logic::GetProps() const
return temp;
}

std::shared_ptr<const THUAI6::Human> Logic::HumanGetSelfInfo() const
std::shared_ptr<const THUAI6::Student> Logic::StudentGetSelfInfo() const
{
std::unique_lock<std::mutex> lock(mtxState);
logger->debug("Called HumanGetSelfInfo");
return currentState->humanSelf;
logger->debug("Called StudentGetSelfInfo");
return currentState->studentSelf;
}

std::shared_ptr<const THUAI6::Butcher> Logic::ButcherGetSelfInfo() const
std::shared_ptr<const THUAI6::Tricker> Logic::TrickerGetSelfInfo() const
{
std::unique_lock<std::mutex> lock(mtxState);
logger->debug("Called ButcherGetSelfInfo");
return currentState->butcherSelf;
logger->debug("Called TrickerGetSelfInfo");
return currentState->trickerSelf;
}

std::vector<std::vector<THUAI6::PlaceType>> Logic::GetFullMap() const
@@ -117,58 +117,58 @@ std::optional<std::pair<int64_t, std::string>> Logic::GetMessage()
return pComm->GetMessage();
}

bool Logic::Escape()
bool Logic::Graduate()
{
logger->debug("Called Escape");
return pComm->Escape(playerID);
logger->debug("Called Graduate");
return pComm->Graduate(playerID);
}

bool Logic::StartFixMachine()
bool Logic::StartLearning()
{
logger->debug("Called StartFixMachine");
return pComm->StartFixMachine(playerID);
logger->debug("Called StartLearning");
return pComm->StartLearning(playerID);
}

bool Logic::EndFixMachine()
bool Logic::EndLearning()
{
logger->debug("Called EndFixMachine");
return pComm->EndFixMachine(playerID);
logger->debug("Called EndLearning");
return pComm->EndLearning(playerID);
}

bool Logic::StartSaveHuman()
bool Logic::StartHelpMate()
{
logger->debug("Called StartSaveHuman");
return pComm->StartSaveHuman(playerID);
logger->debug("Called StartHelpMate");
return pComm->StartHelpMate(playerID);
}

bool Logic::EndSaveHuman()
bool Logic::EndHelpMate()
{
logger->debug("Called EndSaveHuman");
return pComm->EndSaveHuman(playerID);
logger->debug("Called EndHelpMate");
return pComm->EndHelpMate(playerID);
}

bool Logic::Attack(double angle)
bool Logic::Trick(double angle)
{
logger->debug("Called Attack");
return pComm->Attack(angle, playerID);
logger->debug("Called Trick");
return pComm->Trick(angle, playerID);
}

bool Logic::CarryHuman()
bool Logic::StartExam()
{
logger->debug("Called CarryHuman");
return pComm->CarryHuman(playerID);
logger->debug("Called StartExam");
return pComm->StartExam(playerID);
}

bool Logic::ReleaseHuman()
bool Logic::EndExam()
{
logger->debug("Called ReleaseHuman");
return pComm->ReleaseHuman(playerID);
logger->debug("Called EndExam");
return pComm->EndExam(playerID);
}

bool Logic::HangHuman()
bool Logic::MakeFail()
{
logger->debug("Called HangHuman");
return pComm->HangHuman(playerID);
logger->debug("Called MakeFail");
return pComm->MakeFail(playerID);
}

bool Logic::WaitThread()
@@ -182,7 +182,7 @@ void Logic::ProcessMessage()
auto messageThread = [&]()
{
logger->info("Message thread start!");
pComm->AddPlayer(playerID, playerType, humanType, butcherType);
pComm->AddPlayer(playerID, playerType, studentType, trickerType);
logger->info("Join the player!");
pComm->ReadMessage(playerID);
while (gameState != THUAI6::GameState::GameEnd)
@@ -197,10 +197,10 @@ void Logic::ProcessMessage()

// 重新读取玩家的guid,guid确保人类在前屠夫在后
playerGUIDs.clear();
for (auto human : clientMsg.human_message())
playerGUIDs.push_back(human.guid());
for (auto butcher : clientMsg.butcher_message())
playerGUIDs.push_back(butcher.guid());
for (auto student : clientMsg.student_message())
playerGUIDs.push_back(student.guid());
for (auto tricker : clientMsg.tricker_message())
playerGUIDs.push_back(tricker.guid());
currentState->guids = playerGUIDs;
bufferState->guids = playerGUIDs;

@@ -213,10 +213,10 @@ void Logic::ProcessMessage()
case THUAI6::GameState::GameRunning:
// 重新读取玩家的guid,guid确保人类在前屠夫在后
playerGUIDs.clear();
for (auto human : clientMsg.human_message())
playerGUIDs.push_back(human.guid());
for (auto butcher : clientMsg.butcher_message())
playerGUIDs.push_back(butcher.guid());
for (auto student : clientMsg.student_message())
playerGUIDs.push_back(student.guid());
for (auto tricker : clientMsg.tricker_message())
playerGUIDs.push_back(tricker.guid());
currentState->guids = playerGUIDs;
bufferState->guids = playerGUIDs;

@@ -246,49 +246,49 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message)
std::lock_guard<std::mutex> lock(mtxBuffer);

// 清空原有信息
bufferState->humans.clear();
bufferState->butchers.clear();
bufferState->students.clear();
bufferState->trickers.clear();
bufferState->props.clear();

logger->debug("Buffer cleared!");
// 读取新的信息
bufferState->gamemap = Proto2THUAI6::Protobuf2THUAI6Map(message.map_message());
if (playerType == THUAI6::PlayerType::HumanPlayer)
if (playerType == THUAI6::PlayerType::StudentPlayer)
{
for (const auto& item : message.human_message())
for (const auto& item : message.student_message())
{
if (item.player_id() == playerID)
{
bufferState->humanSelf = Proto2THUAI6::Protobuf2THUAI6Human(item);
bufferState->studentSelf = Proto2THUAI6::Protobuf2THUAI6Student(item);
}
bufferState->humans.push_back(Proto2THUAI6::Protobuf2THUAI6Human(item));
logger->debug("Add Human!");
bufferState->students.push_back(Proto2THUAI6::Protobuf2THUAI6Student(item));
logger->debug("Add Student!");
}
for (const auto& item : message.butcher_message())
for (const auto& item : message.tricker_message())
{
if (AssistFunction::HaveView(bufferState->humanSelf->viewRange, bufferState->humanSelf->x, bufferState->humanSelf->y, item.x(), item.y(), bufferState->gamemap))
if (AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.x(), item.y(), bufferState->gamemap))
{
bufferState->butchers.push_back(Proto2THUAI6::Protobuf2THUAI6Butcher(item));
logger->debug("Add Butcher!");
bufferState->trickers.push_back(Proto2THUAI6::Protobuf2THUAI6Tricker(item));
logger->debug("Add Tricker!");
}
}
}
else
{
for (const auto& item : message.butcher_message())
for (const auto& item : message.tricker_message())
{
if (item.player_id() == playerID)
{
bufferState->butcherSelf = Proto2THUAI6::Protobuf2THUAI6Butcher(item);
bufferState->trickerSelf = Proto2THUAI6::Protobuf2THUAI6Tricker(item);
}
bufferState->butchers.push_back(Proto2THUAI6::Protobuf2THUAI6Butcher(item));
logger->debug("Add Butcher!");
bufferState->trickers.push_back(Proto2THUAI6::Protobuf2THUAI6Tricker(item));
logger->debug("Add Tricker!");
}
for (const auto& item : message.human_message())
if (AssistFunction::HaveView(bufferState->butcherSelf->viewRange, bufferState->butcherSelf->x, bufferState->butcherSelf->y, item.x(), item.y(), bufferState->gamemap))
for (const auto& item : message.student_message())
if (AssistFunction::HaveView(bufferState->trickerSelf->viewRange, bufferState->trickerSelf->x, bufferState->trickerSelf->y, item.x(), item.y(), bufferState->gamemap))
{
bufferState->humans.push_back(Proto2THUAI6::Protobuf2THUAI6Human(item));
logger->debug("Add Human!");
bufferState->students.push_back(Proto2THUAI6::Protobuf2THUAI6Student(item));
logger->debug("Add Student!");
}
}
for (const auto& item : message.prop_message())
@@ -399,19 +399,19 @@ void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port, bool f
pComm = std::make_unique<Communication>(IP, port);

// 构造timer
if (playerType == THUAI6::PlayerType::HumanPlayer)
if (playerType == THUAI6::PlayerType::StudentPlayer)
{
if (!file && !print)
timer = std::make_unique<HumanAPI>(*this);
timer = std::make_unique<StudentAPI>(*this);
else
timer = std::make_unique<HumanDebugAPI>(*this, file, print, warnOnly, playerID);
timer = std::make_unique<StudentDebugAPI>(*this, file, print, warnOnly, playerID);
}
else if (playerType == THUAI6::PlayerType::ButcherPlayer)
else if (playerType == THUAI6::PlayerType::TrickerPlayer)
{
if (!file && !print)
timer = std::make_unique<ButcherAPI>(*this);
timer = std::make_unique<TrickerAPI>(*this);
else
timer = std::make_unique<ButcherDebugAPI>(*this, file, print, warnOnly, playerID);
timer = std::make_unique<TrickerDebugAPI>(*this, file, print, warnOnly, playerID);
}

// 构造AI线程


+ 4
- 4
CAPI/API/src/main.cpp View File

@@ -16,13 +16,13 @@ int THUAI6Main(int argc, char** argv, CreateAIFunc AIBuilder)
bool print = false;
bool warnOnly = false;
extern const THUAI6::PlayerType playerType;
extern const THUAI6::ButcherType butcherType;
extern const THUAI6::HumanType humanType;
extern const THUAI6::TrickerType trickerType;
extern const THUAI6::StudentType studentType;
// 仅供早期调试使用
{
file = false;
print = true;
Logic logic(playerType, pID, butcherType, humanType);
Logic logic(playerType, pID, trickerType, studentType);
logic.Main(AIBuilder, sIP, sPort, file, print, warnOnly);
return 0;
}
@@ -70,7 +70,7 @@ int THUAI6Main(int argc, char** argv, CreateAIFunc AIBuilder)
std::cerr << "Parsing error: " << e.error() << " for arg " << e.argId() << std::endl;
return 1;
}
Logic logic(playerType, pID, butcherType, humanType);
Logic logic(playerType, pID, trickerType, studentType);
logic.Main(AIBuilder, sIP, sPort, file, print, warnOnly);
return 0;
}


Loading…
Cancel
Save