48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#include <fuc2/testing.hpp>
|
|
#include <fmt/core.h>
|
|
#include "game/systems.hpp"
|
|
#include <cmath>
|
|
#include <numbers>
|
|
|
|
using namespace fuc2;
|
|
|
|
namespace systems_tests {
|
|
|
|
void test_figure_out_best_rotation_direction() {
|
|
Matrix map = matrix::make(3, 3);
|
|
|
|
Point player_at{1, 1};
|
|
map[player_at.y][player_at.x] = 2;
|
|
|
|
|
|
for(matrix::box target{map, player_at.x, player_at.y, 1}; target.next();) {
|
|
for(matrix::box aiming_at{map, player_at.x, player_at.y, 1}; aiming_at.next();) {
|
|
map[aiming_at.y][aiming_at.x] = 10;
|
|
|
|
float target_dx = float(player_at.x) - float(target.x);
|
|
float target_dy = float(player_at.y) - float(target.y);
|
|
float aiming_dx = float(player_at.x) - float(aiming_at.x);
|
|
float aiming_dy = float(player_at.y) - float(aiming_at.y);
|
|
|
|
float target_angle = atan2(-target_dy, target_dx) * (180.0 / std::numbers::pi);
|
|
float aiming_angle = atan2(-aiming_dy, aiming_dx) * (180.0 / std::numbers::pi);
|
|
|
|
float diff = target_angle - aiming_angle;
|
|
double normalized = fmod(diff + 360.0, 360.0);
|
|
|
|
CHECK(normalized >= 0);
|
|
CHECK(normalized <= 360);
|
|
|
|
map[aiming_at.y][aiming_at.x] = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
fuc2::Set TESTS{
|
|
.name="systems",
|
|
.tests={
|
|
TEST(test_figure_out_best_rotation_direction),
|
|
}
|
|
};
|
|
|
|
}
|