mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 18:13:42 +00:00
fix(ai): map team-relative rotation actions
This commit is contained in:
@@ -17,6 +17,7 @@ Usage:
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import gymnasium as gym
|
||||
import numpy as np
|
||||
@@ -30,6 +31,7 @@ from export_policy import ACTION_HEADS
|
||||
# out of order too, not just catch nothing because both sides changed
|
||||
# together.
|
||||
EXPECTED_ORDER = ["rot_x", "rot_y", "rot_z", "thrust_x", "thrust_y", "thrust_z", "turbo"]
|
||||
GAME_SCRIPTS = Path(__file__).resolve().parents[1] / "Game" / "scripts"
|
||||
|
||||
|
||||
def check_action_heads_match_expected_order() -> None:
|
||||
@@ -87,12 +89,23 @@ def check_round_trip_preserves_per_head_values() -> None:
|
||||
np.testing.assert_array_equal(np.asarray(original[head_index]), expected_column)
|
||||
|
||||
|
||||
def check_team_frame_mapping_is_shared() -> None:
|
||||
codec = (GAME_SCRIPTS / "ship_action_codec.gd").read_text()
|
||||
training = (GAME_SCRIPTS / "ship_ai_controller.gd").read_text()
|
||||
inference = (GAME_SCRIPTS / "ai_ship_controller.gd").read_text()
|
||||
assert "action.rotation.x = -action.rotation.x" in codec
|
||||
assert "action.rotation.z = -action.rotation.z" in codec
|
||||
assert "ShipActionCodec.apply_team_frame(" in training
|
||||
assert "ShipActionCodec.apply_team_frame(" in inference
|
||||
|
||||
|
||||
def main() -> int:
|
||||
checks = [
|
||||
check_action_heads_match_expected_order,
|
||||
check_gymnasium_sorts_to_expected_order,
|
||||
check_action_space_processor_produces_expected_multi_discrete,
|
||||
check_round_trip_preserves_per_head_values,
|
||||
check_team_frame_mapping_is_shared,
|
||||
]
|
||||
for check in checks:
|
||||
check()
|
||||
|
||||
Reference in New Issue
Block a user