opt.优化自动战斗任务

This commit is contained in:
MistEO
2022-01-21 22:54:59 +08:00
parent 9e7209c283
commit c5fbd4bb93
2 changed files with 12 additions and 8 deletions

View File

@@ -55,8 +55,8 @@ bool asst::BattlePerspectiveImageAnalyzer::placed_analyze()
int h = stats.at<int>(i, cv::CC_STAT_HEIGHT);
m_available_placed.emplace_back(Rect(x, y, w, h));
int center_x = centroids.at<double>(i, 0);
int center_y = centroids.at<double>(i, 1);
int center_x = static_cast<int>(centroids.at<double>(i, 0));
int center_y = static_cast<int>(centroids.at<double>(i, 1));
placed_centers.emplace_back(Point(center_x, center_y));
#ifdef ASST_DEBUG
@@ -76,8 +76,8 @@ bool asst::BattlePerspectiveImageAnalyzer::placed_analyze()
auto nearest_iter = std::min_element(placed_centers.cbegin(), placed_centers.cend(),
[&home](const Point& lhs, const Point& rhs) -> bool {
int lhs_dist = std::pow((home.x - lhs.x), 2) + std::pow((home.y - lhs.y), 2);
int rhs_dist = std::pow((home.x - rhs.x), 2) + std::pow((home.y - rhs.y), 2);
double lhs_dist = std::pow((home.x - lhs.x), 2) + std::pow((home.y - lhs.y), 2);
double rhs_dist = std::pow((home.x - rhs.x), 2) + std::pow((home.y - rhs.y), 2);
return lhs_dist < rhs_dist;
});
if (nearest_iter == placed_centers.cend()) {

View File

@@ -33,11 +33,11 @@ bool asst::BattleTask::auto_battle()
}
static const std::array<Role, 9> RoleOrder = {
Role::Medic,
Role::Pioneer,
Role::Sniper,
Role::Warrior,
Role::Support,
Role::Medic,
Role::Caster,
Role::Special,
Role::Tank,
@@ -84,13 +84,18 @@ bool asst::BattleTask::auto_battle()
int dx = nearest_point.x - home_center.x;
int dy = nearest_point.y - home_center.y;
if ((dx * 7) < (dy * 11)) {
dx = 0;
}
else {
dy = 0;
}
constexpr int coeff = 5;
Point end_point;
switch (opt_oper.role) {
case Role::Medic:
case Role::Support:
{
constexpr int coeff = 5;
end_point.x = nearest_point.x - coeff * dx;
end_point.y = nearest_point.y - coeff * dy;
}
@@ -104,7 +109,6 @@ bool asst::BattleTask::auto_battle()
case Role::Drone:
default:
{
constexpr int coeff = 5;
end_point.x = nearest_point.x + coeff * dx;
end_point.y = nearest_point.y + coeff * dy;
}