Fix up the spatialmap to have an occupied_by method which checks if a square is occupied and returns what is there.

This commit is contained in:
Zed A. Shaw 2025-09-02 12:46:05 -04:00
parent 759f93cae0
commit a11e7de14e
7 changed files with 24 additions and 43 deletions

View file

@ -4,19 +4,6 @@
#include <cmath>
#include <numbers>
/*
face_x := rand.Float64() * 100
face_y := rand.Float64() * 100
target_x := rand.Float64() * 100
target_y := rand.Float64() * 100
rad_angle1 := atan2(target_y, target_x)
rad_angle2 := atan2(face_y, face_x)
diff := rad_angle1 - rad_angle2
if diff < 0 { fmt.Printf("\nTurn Right") }
else { fmt.Printf("\nTurn Left") }
*/
TEST_CASE("figure out best rotation direction", "[systems-rotate]") {
Matrix map = matrix::make(3, 3);
@ -34,26 +21,14 @@ TEST_CASE("figure out best rotation direction", "[systems-rotate]") {
float aiming_dx = float(player_at.x) - float(aiming_at.x);
float aiming_dy = float(player_at.y) - float(aiming_at.y);
fmt::println("target_d={},{}; aiming_d={},{}",
target_dx, target_dy, aiming_dx, aiming_dy);
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);
fmt::println("\n\n>>>>>>>>> BEGIN");
if(normalized != diff) fmt::println("YOU NEED NORMALIZED");
fmt::println("aming_angle={}, target_angle={}, delta={}, norm={}",
aiming_angle, target_angle, diff, normalized);
fmt::println("TURN {}", normalized < 180.0 ? "LEFT" : "RIGHT");
matrix::dump("< is target, a is aim", map, target.x, target.y);
fmt::println("-----------------END");
REQUIRE(normalized >= 0);
REQUIRE(normalized <= 360);
map[aiming_at.y][aiming_at.x] = 0;
}