feat: 将方向改为静态成员函数

This commit is contained in:
zzyyyl
2022-07-18 18:22:02 +08:00
parent f78c05f36f
commit 0bfe3330eb
2 changed files with 8 additions and 9 deletions

View File

@@ -38,6 +38,10 @@ namespace asst
{
return "[ " + std::to_string(x) + ", " + std::to_string(y) + " ]";
}
static constexpr Point RightDirection() { return Point(1, 0); }
static constexpr Point DownDirection() { return Point(0, 1); }
static constexpr Point LeftDirection() { return Point(-1, 0); }
static constexpr Point UpDirection() { return Point(0, -1); }
int x = 0;
int y = 0;
};

View File

@@ -727,17 +727,12 @@ std::pair<asst::Point, int> asst::RoguelikeBattleTaskPlugin::calc_best_direction
left_attack_range.emplace_back(-x, -y);
up_attack_range.emplace_back(y, -x);
}
static const constexpr Point RightDirection(1, 0);
static const constexpr Point DownDirection(0, 1);
static const constexpr Point LeftDirection(-1, 0);
static const constexpr Point UpDirection(0, -1);
std::vector<std::pair<const Point&, std::vector<Point>>> DirectionAttackRangeMap;
DirectionAttackRangeMap.reserve(4);
DirectionAttackRangeMap.emplace_back(RightDirection, std::move(right_attack_range));
DirectionAttackRangeMap.emplace_back(DownDirection, std::move(down_attack_range));
DirectionAttackRangeMap.emplace_back(LeftDirection, std::move(left_attack_range));
DirectionAttackRangeMap.emplace_back(UpDirection, std::move(up_attack_range));
DirectionAttackRangeMap.emplace_back(Point::RightDirection(), std::move(right_attack_range));
DirectionAttackRangeMap.emplace_back(Point::DownDirection(), std::move(down_attack_range));
DirectionAttackRangeMap.emplace_back(Point::LeftDirection(), std::move(left_attack_range));
DirectionAttackRangeMap.emplace_back(Point::UpDirection(), std::move(up_attack_range));
int max_score = 0;
Point opt_direction;