Skip to content

Commit

Permalink
Merge pull request #390 from eesast/dev
Browse files Browse the repository at this point in the history
v1.2.0
  • Loading branch information
DragonAura authored May 20, 2024
2 parents e56ecb7 + 58cd2e5 commit e942d2c
Show file tree
Hide file tree
Showing 31 changed files with 232 additions and 149 deletions.
8 changes: 3 additions & 5 deletions CAPI/cpp/API/include/Communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class Communication
{
public:
Communication(std::string sIP, std::string sPort);
~Communication()
{
}
~Communication() = default;
bool TryConnection(int32_t playerID, int32_t teamID);
protobuf::MessageToClient GetMessage2Client();
void AddPlayer(int32_t playerID, int32_t teamID, THUAI7::ShipType ShipType);
Expand All @@ -52,8 +50,8 @@ class Communication
protobuf::MessageToClient message2Client;
std::mutex mtxMessage;
std::mutex mtxLimit;
int32_t counter;
int32_t counterMove;
int32_t counter{};
int32_t counterMove{};
static constexpr const int32_t limit = 50;
static constexpr const int32_t moveLimit = 10;
std::condition_variable cvMessage;
Expand Down
2 changes: 1 addition & 1 deletion CAPI/cpp/API/include/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Logic : public ILogic
std::condition_variable cvAI;

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

// 存储状态,分别是现在的状态和缓冲区的状态。
State state[2];
Expand Down
43 changes: 22 additions & 21 deletions CAPI/cpp/API/include/structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

namespace THUAI7
{

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

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

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

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

struct ConstructionState
{
int32_t teamID;
int64_t teamID;
int32_t hp;
ConstructionType constructionType;
ConstructionState(std::pair<int32_t, int32_t> teamHP, ConstructionType type) :
ConstructionState(std::pair<int64_t, int32_t> teamHP, ConstructionType type) :
teamID(teamHP.first),
hp(teamHP.second),
constructionType(type)
Expand All @@ -266,15 +264,17 @@ namespace THUAI7
// double bombRange,
// };

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

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

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

inline std::map<MessageOfObj, std::string> messageOfObjDict{
{MessageOfObj::NullMessageOfObj, "NullMessageOfObj"},
Expand Down
21 changes: 10 additions & 11 deletions CAPI/cpp/API/include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#undef SendMessage
#undef PeekMessage

// 用于将THUAI7的类转换为Protobuf的类
namespace AssistFunction
{

constexpr int32_t numOfGridPerCell = 1000;

[[nodiscard]] constexpr inline int32_t GridToCell(int32_t grid) noexcept
Expand All @@ -29,21 +29,21 @@ namespace AssistFunction

[[nodiscard]] constexpr inline int32_t GridToCell(double grid) noexcept
{
return int(grid) / numOfGridPerCell;
return int32_t(grid) / numOfGridPerCell;
}

inline bool HaveView(int32_t x, int32_t y, int32_t newX, int32_t newY, int32_t viewRange, std::vector<std::vector<THUAI7::PlaceType>>& map)
{
int32_t deltaX = newX - x;
int32_t deltaY = newY - y;
double distance = double(deltaX * deltaX) + double(deltaY * deltaY);
double deltaX = newX - x;
double deltaY = newY - y;
double distance = std::pow(deltaX, 2) + std::pow(deltaY, 2);
THUAI7::PlaceType myPlace = map[GridToCell(x)][GridToCell(y)];
THUAI7::PlaceType newPlace = map[GridToCell(newX)][GridToCell(newY)];
if (newPlace == THUAI7::PlaceType::Shadow && myPlace != THUAI7::PlaceType::Shadow)
return false;
if (distance > viewRange * viewRange)
if (distance > std::pow(viewRange, 2))
return false;
int32_t divide = std::max(std::abs(deltaX), std::abs(deltaY)) / 100;
int32_t divide = int32_t(std::max(std::abs(deltaX), std::abs(deltaY)) / 100);
if (divide == 0)
return true;
double dx = deltaX / divide;
Expand Down Expand Up @@ -539,15 +539,14 @@ namespace THUAI72Proto
playerMsg.set_ship_type(THUAI72Proto::shipTypeDict[ShipType]);
return playerMsg;
}

// 用于将THUAI7的类转换为Protobuf的类
} // namespace THUAI72Proto

namespace Time
{
inline double TimeSinceStart(const std::chrono::system_clock::time_point& sp)
{
std::chrono::system_clock::time_point tp = std::chrono::system_clock::now();
std::chrono::duration<double, std::milli> time_span = std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(tp - sp);
auto tp = std::chrono::system_clock::now();
auto time_span = std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(tp - sp);
return time_span.count();
}
} // namespace Time
Expand Down
Loading

0 comments on commit e942d2c

Please sign in to comment.