Skip to content

Commit

Permalink
Merge branch 'dev' of ssh://ssh.github.com:443/hhzzff/THUAI7 into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
hhzzff committed Mar 30, 2024
2 parents b9af838 + cdfee3f commit a73908c
Show file tree
Hide file tree
Showing 108 changed files with 4,926 additions and 2,097 deletions.
22 changes: 11 additions & 11 deletions CAPI/cpp/API/include/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ class ILogic
virtual bool Rebuild(THUAI7::ConstructionType constructionType) = 0;
virtual bool Construct(THUAI7::ConstructionType constructionType) = 0;
virtual bool Attack(double angle) = 0;
[[nodiscard]] virtual bool HaveView(int32_t gridX, int32_t gridY, int32_t selfX, int32_t selfY, int32_t viewRange) const = 0;
[[nodiscard]] virtual bool HaveView(int32_t selfX, int32_t selfY, int32_t targetX, int32_t targetY, int32_t viewRange) const = 0;

// Team使用的部分
virtual bool Recycle(int64_t playerID) = 0;
virtual bool InstallModule(int64_t playerID, THUAI7::ModuleType moduleType) = 0;
virtual bool BuildSweeper(THUAI7::SweeperType SweeperType, int32_t cellX, int32_t cellY) = 0;
virtual bool BuildSweeper(THUAI7::SweeperType SweeperType) = 0;
};

class IAPI
Expand Down Expand Up @@ -142,7 +142,7 @@ class ISweeperAPI : public IAPI
virtual std::future<bool> Rebuild(THUAI7::ConstructionType constructionType) = 0;
virtual std::future<bool> Construct(THUAI7::ConstructionType constructionType) = 0;
virtual std::shared_ptr<const THUAI7::Sweeper> GetSelfInfo() const = 0;
virtual bool HaveView(int32_t gridX, int32_t gridY) const = 0;
virtual bool HaveView(int32_t targetX, int32_t targetY) const = 0;
};

class ITeamAPI : public IAPI
Expand All @@ -151,7 +151,7 @@ class ITeamAPI : public IAPI
[[nodiscard]] virtual std::shared_ptr<const THUAI7::Team> GetSelfInfo() const = 0;
virtual std::future<bool> InstallModule(int64_t playerID, THUAI7::ModuleType moduletype) = 0;
virtual std::future<bool> Recycle(int64_t playerID) = 0;
virtual std::future<bool> BuildSweeper(THUAI7::SweeperType SweeperType, int32_t cellX, int32_t cellY) = 0;
virtual std::future<bool> BuildSweeper(THUAI7::SweeperType SweeperType) = 0;
};

class IGameTimer
Expand Down Expand Up @@ -206,13 +206,13 @@ class SweeperAPI : public ISweeperAPI, public IGameTimer
[[nodiscard]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetBridgeHp(int32_t x, int32_t y) const override;
[[nodiscard]] int32_t GetGarbageState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetHomeHp() const override;
[[nodiscard]] std::shared_ptr<const THUAI7::GameInfo> GetGameInfo() const override;
[[nodiscard]] std::vector<int64_t> GetPlayerGUIDs() const override;
[[nodiscard]] std::shared_ptr<const THUAI7::Sweeper> GetSelfInfo() const override;
[[nodiscard]] bool HaveView(int32_t gridX, int32_t gridY) const override;
[[nodiscard]] int32_t GetHomeHp() const override;
[[nodiscard]] int32_t GetEnergy() const override;
[[nodiscard]] int32_t GetScore() const override;
[[nodiscard]] std::vector<int64_t> GetPlayerGUIDs() const override;
[[nodiscard]] std::shared_ptr<const THUAI7::Sweeper> GetSelfInfo() const override;
[[nodiscard]] bool HaveView(int32_t targetX, int32_t targetY) const override;
void Print(std::string str) const
{
}
Expand Down Expand Up @@ -271,7 +271,7 @@ class TeamAPI : public ITeamAPI, public IGameTimer
[[nodiscard]] int32_t GetEnergy() const override;
std::future<bool> InstallModule(int64_t playerID, THUAI7::ModuleType moduleType) override;
std::future<bool> Recycle(int64_t playerID) override;
std::future<bool> BuildSweeper(THUAI7::SweeperType SweeperType, int32_t cellX, int32_t cellY) override;
std::future<bool> BuildSweeper(THUAI7::SweeperType SweeperType) override;
void Print(std::string str) const
{
}
Expand Down Expand Up @@ -327,7 +327,7 @@ class SweeperDebugAPI : public ISweeperAPI, public IGameTimer
[[nodiscard]] std::shared_ptr<const THUAI7::GameInfo> GetGameInfo() const override;
[[nodiscard]] std::vector<int64_t> GetPlayerGUIDs() const override;
[[nodiscard]] std::shared_ptr<const THUAI7::Sweeper> GetSelfInfo() const override;
[[nodiscard]] bool HaveView(int32_t gridX, int32_t gridY) const override;
[[nodiscard]] bool HaveView(int32_t targetX, int32_t targetY) const override;
[[nodiscard]] int32_t GetEnergy() const override;
[[nodiscard]] int32_t GetScore() const override;

Expand Down Expand Up @@ -378,7 +378,7 @@ class TeamDebugAPI : public ITeamAPI, public IGameTimer
[[nodiscard]] int32_t GetEnergy() const override;
std::future<bool> InstallModule(int64_t playerID, THUAI7::ModuleType moduleType) override;
std::future<bool> Recycle(int64_t playerID) override;
std::future<bool> BuildSweeper(THUAI7::SweeperType SweeperType, int32_t cellX, int32_t cellY) override;
std::future<bool> BuildSweeper(THUAI7::SweeperType SweeperType) override;
void Print(std::string str) const override;
void PrintSelfInfo() const override;
// TODO
Expand Down
2 changes: 1 addition & 1 deletion CAPI/cpp/API/include/Communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Communication
bool Send(int64_t playerID, int64_t toPlayerID, int64_t teamID, std::string message, bool binary);
// Team
bool InstallModule(int64_t playerID, int64_t teamID, THUAI7::ModuleType moduleType);
bool BuildSweeper(int64_t teamID, THUAI7::SweeperType SweeperType, int32_t x, int32_t y);
bool BuildSweeper(int64_t teamID, THUAI7::SweeperType SweeperType);
bool Recycle(int64_t playerID, int64_t teamID);

private:
Expand Down
4 changes: 2 additions & 2 deletions CAPI/cpp/API/include/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ class Logic : public ILogic
bool Rebuild(THUAI7::ConstructionType constructionType);
bool Construct(THUAI7::ConstructionType constructionType);
bool Attack(double angle);
[[nodiscard]] bool HaveView(int32_t gridX, int32_t gridY, int32_t selfX, int32_t selfY, int32_t viewRange) const;
[[nodiscard]] bool HaveView(int32_t selfX, int32_t selfY, int32_t targetX, int32_t targetY, int32_t viewRange) const;

// ITeamAPI
bool Recycle(int64_t playerID);
bool InstallModule(int64_t playerID, THUAI7::ModuleType moduleType);
bool BuildSweeper(THUAI7::SweeperType SweeperType, int32_t cellX, int32_t cellY);
bool BuildSweeper(THUAI7::SweeperType SweeperType);

bool TryConnection();
void ProcessMessage();
Expand Down
1 change: 0 additions & 1 deletion CAPI/cpp/API/include/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ struct State
std::shared_ptr<THUAI7::Team> teamSelf;
std::vector<std::shared_ptr<THUAI7::Sweeper>> sweepers;
std::vector<std::shared_ptr<THUAI7::Sweeper>> enemySweepers;
std::shared_ptr<THUAI7::Team> enemyTeam;
std::vector<std::shared_ptr<THUAI7::Bullet>> bullets;
std::vector<std::vector<THUAI7::PlaceType>> gameMap;
std::shared_ptr<THUAI7::GameMap> mapInfo;
Expand Down
2 changes: 1 addition & 1 deletion CAPI/cpp/API/include/structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ namespace THUAI7
std::map<std::pair<int32_t, int32_t>, std::pair<int64_t, int32_t>> recycleBankState;
std::map<std::pair<int32_t, int32_t>, std::pair<int64_t, int32_t>> chargeStationState;
std::map<std::pair<int32_t, int32_t>, std::pair<int64_t, int32_t>> signalTowerState;
std::map<std::pair<int32_t, int32_t>, std::pair<int64_t, int32_t>> HomeState;
std::map<std::pair<int32_t, int32_t>, std::pair<int64_t, int32_t>> homeState;
std::map<std::pair<int32_t, int32_t>, int32_t> bridgeState;
std::map<std::pair<int32_t, int32_t>, int32_t> garbageState;
};
Expand Down
4 changes: 1 addition & 3 deletions CAPI/cpp/API/include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,10 @@ namespace THUAI72Proto
return installMsg;
}

inline protobuf::BuildSweeperMsg THUAI72ProtobufBuildSweeperMsg(int64_t teamID, THUAI7::SweeperType SweeperType, int32_t x, int32_t y)
inline protobuf::BuildSweeperMsg THUAI72ProtobufBuildSweeperMsg(int64_t teamID, THUAI7::SweeperType SweeperType)
{
protobuf::BuildSweeperMsg buildSweeperMsg;
buildSweeperMsg.set_team_id(teamID);
buildSweeperMsg.set_x(x);
buildSweeperMsg.set_y(y);
buildSweeperMsg.set_sweeper_type(THUAI72Proto::sweeperTypeDict[SweeperType]);
return buildSweeperMsg;
}
Expand Down
15 changes: 10 additions & 5 deletions CAPI/cpp/API/src/AI.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <vector>
#include <thread>
#include <array>
#include <map>
#include "AI.h"
#include "constants.h"
// 注意不要使用conio.h,Windows.h等非标准库
Expand All @@ -21,25 +22,29 @@ void AI::play(ISweeperAPI& api)
{
if (this->playerID == 1)
{
// 玩家1执行操作
api.Move(10, 2.1);
api.PrintSelfInfo();
api.Attack(1.1);
}
else if (this->playerID == 2)
{
// 玩家2执行操作
api.Move(10, 2.1);
api.PrintSelfInfo();
}

else if (this->playerID == 3)
{
// 玩家3执行操作
api.Move(10, 2.1);
api.PrintSelfInfo();
}
else if (this->playerID == 4)
{
// 玩家4执行操作
api.Move(10, 2.1);
api.PrintSelfInfo();
}
}

void AI::play(ITeamAPI& api) // 默认team playerID 为0
{
auto self = api.GetSelfInfo();
api.PrintSelfInfo();
}
8 changes: 4 additions & 4 deletions CAPI/cpp/API/src/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ std::future<bool> SweeperAPI::Construct(THUAI7::ConstructionType constructionTyp
{ return logic.Construct(constructionType); });
}

bool SweeperAPI::HaveView(int32_t gridX, int32_t gridY) const
bool SweeperAPI::HaveView(int32_t targetX, int32_t targetY) const
{
auto selfInfo = GetSelfInfo();
return logic.HaveView(gridX, gridY, selfInfo->x, selfInfo->y, selfInfo->viewRange);
return logic.HaveView(targetX, targetY, selfInfo->x, selfInfo->y, selfInfo->viewRange);
}

// Team独有
Expand All @@ -306,10 +306,10 @@ std::future<bool> TeamAPI::Recycle(int64_t playerID)
{ return logic.Recycle(playerID); });
}

std::future<bool> TeamAPI::BuildSweeper(THUAI7::SweeperType SweeperType, int32_t x, int32_t y)
std::future<bool> TeamAPI::BuildSweeper(THUAI7::SweeperType SweeperType)
{
return std::async(std::launch::async, [=]()
{ return logic.BuildSweeper(SweeperType, x, y); });
{ return logic.BuildSweeper(SweeperType); });
}

void SweeperAPI::Play(IAI& ai)
Expand Down
4 changes: 2 additions & 2 deletions CAPI/cpp/API/src/Communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ bool Communication::Attack(int64_t playerID, int64_t teamID, double angle)
return false;
}

bool Communication::BuildSweeper(int64_t teamID, THUAI7::SweeperType SweeperType, int32_t x, int32_t y)
bool Communication::BuildSweeper(int64_t teamID, THUAI7::SweeperType SweeperType)
{
protobuf::BoolRes reply;
ClientContext context;
auto request = THUAI72Proto::THUAI72ProtobufBuildSweeperMsg(teamID, SweeperType, x, y);
auto request = THUAI72Proto::THUAI72ProtobufBuildSweeperMsg(teamID, SweeperType);
auto status = THUAI7Stub->BuildSweeper(&context, request, &reply);
if (status.ok())
return true;
Expand Down
8 changes: 4 additions & 4 deletions CAPI/cpp/API/src/DebugAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ std::shared_ptr<const THUAI7::Sweeper> SweeperDebugAPI::GetSelfInfo() const
return logic.SweeperGetSelfInfo();
}

bool SweeperDebugAPI::HaveView(int32_t gridX, int32_t gridY) const
bool SweeperDebugAPI::HaveView(int32_t targetX, int32_t targetY) const
{
auto selfInfo = GetSelfInfo();
return logic.HaveView(gridX, gridY, selfInfo->x, selfInfo->y, selfInfo->viewRange);
return logic.HaveView(targetX, targetY, selfInfo->x, selfInfo->y, selfInfo->viewRange);
}

int32_t SweeperDebugAPI::GetEnergy() const
Expand Down Expand Up @@ -436,10 +436,10 @@ std::future<bool> TeamDebugAPI::Recycle(int64_t playerID)
{ return logic.Recycle(playerID); });
}

std::future<bool> TeamDebugAPI::BuildSweeper(THUAI7::SweeperType SweeperType, int32_t x, int32_t y)
std::future<bool> TeamDebugAPI::BuildSweeper(THUAI7::SweeperType SweeperType)
{
return std::async(std::launch::async, [=]()
{ return logic.BuildSweeper(SweeperType, x, y); });
{ return logic.BuildSweeper(SweeperType); });
}

void TeamDebugAPI::PrintSelfInfo() const
Expand Down
Loading

0 comments on commit a73908c

Please sign in to comment.