using System; using System.Diagnostics; using System.Numerics; using RustToDust.Core; using RustToDust.Ymir; using Xunit; using Xunit.Abstractions; using Ymir.Box3D; namespace RustToDust.Tests { public sealed class HybridBWalkerTests { private readonly ITestOutputHelper _output; public HybridBWalkerTests(ITestOutputHelper output) { _output = output; } private static ChassisSpec MakeExemplarSpec() => Catalog.Raptor with { Id = "exemplar_frame", Name = "Exemplar Frame", BaseCellArmor = 22f, MassKg = 1150f, BaseThrust = 26000f, BaseTurnRate = 6.2f, MaxSpeed = 40f, HalfWidth = 0.8f, HalfHeight = 1.55f, HalfLength = 0.8f }; [Fact] public void HybridB_All7Mechs_WalkTurnSlopes_SmoothLiftoff_ZeroTeleports() { var specs = new[] { Catalog.Breaker, Catalog.Paladin, Catalog.Raptor, Catalog.Spectre, Catalog.Kestrel, Catalog.Manticore, Catalog.Bastion, MakeExemplarSpec() }; // 1. Walk, turn, and climb slopes across all 7 mechs + exemplar_frame foreach (var spec in specs) { using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true); for (int i = 1; i < session.State.Contenders.Count; i++) { session.SetContenderPose(i, 500f + i * 16f, 500f); } // Phase A: start on flat/gentle ground near origin (60 ticks) to verify honest walk slip < 8cm session.SetContenderPose(0, 0f, 0f, 0f); session.State.SpawnChassisDrop(0f, 0f, spec); Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}"); var player = session.State.Contenders[0]; Assert.Equal(spec.Id, player.Grid.Spec.Id); var ws = session.GetWalkerState(true, player.Id); Assert.NotNull(ws); int nLegs = ws!.Geom.LegCount; float geomScale = ws.GeomScale; for (int t = 0; t < 60; t++) { session.SetHumanInput(0, new PlayerInput( Throttle: 0.45f, Steer: 0f, AimWorldX: player.X, AimWorldZ: player.Z + 60f, Fire: false, InteractPickup: false, Brake: false)); session.Step(); } Assert.True(ws.MaxFootSlipM < 0.08f, $"{spec.Id}: normal walk foot slip {ws.MaxFootSlipM:F4}m >= 0.08m (maxSpd={spec.MaxSpeed:F1})"); // Phase B: move to dune slope approach, turn & climb (180 ticks) checking liftoff teleport, C1 touchdown, omega continuity float duneApproachX = 0f; float duneApproachZ = 0f; float bestScore = -1f; foreach (var b in session.State.Terrain.Brushes) { if (b.Kind == TerrainBrushKind.DuneRidge && b.HeightDelta > 4f) { float d = MathF.Sqrt(b.X * b.X + b.Z * b.Z); if (d > 40f && d < 280f && b.HeightDelta > bestScore) { bestScore = b.HeightDelta; float dirX = -b.X / d; float dirZ = -b.Z / d; duneApproachX = b.X + dirX * MathF.Min(36f, b.RadiusX * 0.85f); duneApproachZ = b.Z + dirZ * MathF.Min(36f, b.RadiusZ * 0.85f); } } } session.SetContenderPose(0, duneApproachX, duneApproachZ, MathF.Atan2(-duneApproachX, -duneApproachZ) + MathF.PI); ws = session.GetWalkerState(true, player.Id)!; var prevFoot = new Vector3[nLegs]; var prevPlanted = new bool[nLegs]; var prevOmegaHip = new float[nLegs]; for (int i = 0; i < nLegs; i++) { prevFoot[i] = ws.FootSole[i]; prevPlanted[i] = ws.Planted[i]; prevOmegaHip[i] = ws.Actuators[i].Omega.HipPitch; } float maxDeltaFootPerTick = 0f; float maxLiftoffDelta = 0f; float maxOmegaJumpAtSwap = 0f; float maxTouchdownGroundErr = 0f; float minUpDot = 1f; int swapCount = 0; for (int t = 0; t < 180; t++) { float steer = MathF.Sin(t * 0.06f) * 0.65f; session.SetHumanInput(0, new PlayerInput( Throttle: 0.85f, Steer: steer, AimWorldX: player.X + 40f * MathF.Sin(player.Yaw), AimWorldZ: player.Z + 40f * MathF.Cos(player.Yaw), Fire: false, InteractPickup: false, Brake: false)); session.Step(); Assert.True(float.IsFinite(player.X) && float.IsFinite(player.Y) && float.IsFinite(player.Z), $"{spec.Id}: non-finite pose at tick {t}"); var q = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW); var up = Vector3.Transform(Vector3.UnitY, q); minUpDot = MathF.Min(minUpDot, up.Y); for (int i = 0; i < nLegs; i++) { Vector3 curFoot = ws.FootSole[i]; float delta = (curFoot - prevFoot[i]).Length(); if (delta > maxDeltaFootPerTick) { maxDeltaFootPerTick = delta; } bool curPlanted = ws.Planted[i]; if (prevPlanted[i] && !curPlanted && !ws.IsAirborne) { if (delta > maxLiftoffDelta) { maxLiftoffDelta = delta; } } if (!prevPlanted[i] && curPlanted) { swapCount++; float groundY = session.State.Terrain.SampleHeight(curFoot.X, curFoot.Z); float gErr = MathF.Abs(curFoot.Y - groundY); if (gErr > maxTouchdownGroundErr) { maxTouchdownGroundErr = gErr; } float omegaDelta = MathF.Abs(ws.Actuators[i].Omega.HipPitch - prevOmegaHip[i]); if (omegaDelta > maxOmegaJumpAtSwap) { maxOmegaJumpAtSwap = omegaDelta; } } prevFoot[i] = curFoot; prevPlanted[i] = curPlanted; prevOmegaHip[i] = ws.Actuators[i].Omega.HipPitch; } } float maxFootGroundSpeed = spec.MaxSpeed + MathF.Max(spec.HalfWidth, spec.HalfLength) * spec.BaseTurnRate * 0.5f; float maxAllowedTickDelta = MathF.Max(0.55f, maxFootGroundSpeed * ArenaSession.FixedDt * 3.5f); _output.WriteLine( $"{spec.Id,-15} minUp={minUpDot:F3} slip={ws.MaxFootSlipM:F4}m maxFootDelta/tick={maxDeltaFootPerTick:F4}m " + $"liftoffDelta={maxLiftoffDelta:F4}m tdGroundErr={maxTouchdownGroundErr:F5}m swapOmegaJump={maxOmegaJumpAtSwap:F3} swaps={swapCount}"); Assert.True(minUpDot >= 0.90f, $"{spec.Id}: unstable tilt minUpDot={minUpDot:F3}"); Assert.True(swapCount >= 4, $"{spec.Id}: expected >= 4 gait transitions, got {swapCount}"); Assert.True(maxLiftoffDelta <= 0.35f * MathF.Max(1f, geomScale), $"{spec.Id}: Bug 1 liftoff teleport detected: liftoffDelta={maxLiftoffDelta:F4}m"); Assert.True(maxDeltaFootPerTick <= maxAllowedTickDelta, $"{spec.Id}: 1-tick foot teleport detected: maxDelta={maxDeltaFootPerTick:F4}m > {maxAllowedTickDelta:F4}m"); Assert.True(maxTouchdownGroundErr <= 0.06f * MathF.Max(1f, geomScale), $"{spec.Id}: non-C1 liftoff/touchdown height gap {maxTouchdownGroundErr:F4}m"); Assert.True(maxOmegaJumpAtSwap < 12.0f, $"{spec.Id}: discontinuous joint omega jump across swap: {maxOmegaJumpAtSwap:F3} rad/s"); } // 2. Benchmark 12 simultaneous mechs CPU < 1.5 ms/tick { using var benchSession = new ArenaSession(seed: 99, mapKind: ArenaMapKind.Desert, slot0Human: true); for (int i = 0; i < benchSession.State.Contenders.Count; i++) { var spec = specs[i % 7]; float x = (i - 5.5f) * 28f; float z = -80f + (i % 3) * 35f; benchSession.SetContenderPose(i, x, z, 0f); if (benchSession.State.Contenders[i].Grid.Spec.Id != spec.Id) { benchSession.State.Contenders[i].Grid.SwapChassis(spec); benchSession.SetContenderPose(i, x, z, 0f); } } var walkers = new (ContenderState C, WalkerState Ws, int Lane)[12]; for (int i = 0; i < 12; i++) { var c = benchSession.State.Contenders[i]; c.ThrottleCmd = 0.8f; c.SteerCmd = (i % 2 == 0 ? 0.2f : -0.2f); walkers[i] = (c, benchSession.GetWalkerState(true, c.Id)!, benchSession.GetContenderBody(c.Id)!.Value.Lane); } // Warmup JIT for (int w = 0; w < 20; w++) { benchSession.SetHumanInput(0, new PlayerInput(0.8f, 0.2f, 0f, 100f, false, false, false)); benchSession.Step(); } var view = benchSession.World.View; const int benchTicks = 300; long t0 = Stopwatch.GetTimestamp(); for (int t = 0; t < benchTicks; t++) { for (int i = 0; i < 12; i++) { var (c, ws, lane) = walkers[i]; var pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]); var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]); var vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]); var angVel = new Vector3(view.AngularVelocityX[lane], view.AngularVelocityY[lane], view.AngularVelocityZ[lane]); var fwd = Vector3.Transform(Vector3.UnitZ, q); fwd.Y = 0f; fwd = fwd.LengthSquared() < 1e-4f ? Vector3.UnitZ : Vector3.Normalize(fwd); WalkerLocomotion.StepWalker( ws, c.Grid, benchSession.State.Terrain, view, lane, view.Mass[lane], pos, q, vel, angVel, fwd * (c.ThrottleCmd * c.Grid.Spec.MaxSpeed), 0.3f, false, ArenaSession.FixedDt); } } long t1 = Stopwatch.GetTimestamp(); double msPerTick = (t1 - t0) * 1000.0 / Stopwatch.Frequency / benchTicks; _output.WriteLine($"12-mech simultaneous WalkerLocomotion CPU: {msPerTick:F4} ms/tick"); Assert.True(msPerTick < 1.5, $"12 simultaneous mechs CPU {msPerTick:F4} ms/tick exceeded 1.5 ms/tick budget"); } } [Fact] public void HybridB_CrippledLeg_ReducesGrfAndTorque_InducesLimp() { Span legIntegrities = stackalloc float[4]; foreach (var spec in new[] { Catalog.Breaker, Catalog.Bastion }) { using var session = new ArenaSession(seed: 17, mapKind: ArenaMapKind.Desert, slot0Human: true); for (int i = 1; i < session.State.Contenders.Count; i++) { session.SetContenderPose(i, 450f + i * 16f, 450f); } session.SetContenderPose(0, 0f, 0f, 0f); session.State.SpawnChassisDrop(0f, 0f, spec); Assert.True(session.TrySwapNearbyChassis(0)); var player = session.State.Contenders[0]; var grid = player.Grid; // Strip all left-leg cells (Breaker Coronal L: y>=H-2, x 0.002f, $"{spec.Id}: expected crippled leg asymmetry to induce measurable limp roll"); } } [Fact] public void HybridB_AirborneMech_ZeroGrfForce() { foreach (var spec in new[] { Catalog.Breaker, Catalog.Manticore }) { using var session = new ArenaSession(seed: 7, mapKind: ArenaMapKind.Desert, slot0Human: true); session.SetContenderPose(0, 0f, 0f, 0f); session.State.SpawnChassisDrop(0f, 0f, spec); Assert.True(session.TrySwapNearbyChassis(0)); var player = session.State.Contenders[0]; var body = session.GetContenderBody(player.Id)!.Value; var view = session.World.View; int lane = body.Lane; // 1. Direct StepWalker check with COM lifted 18m above terrain float groundY = session.State.Terrain.SampleHeight(0f, 0f); Vector3 liftedPos = new(view.PositionX[lane], groundY + spec.HalfHeight + 18f, view.PositionZ[lane]); var ws = session.GetWalkerState(true, player.Id)!; WalkerLocomotion.StepWalker( ws, player.Grid, session.State.Terrain, view, lane, view.Mass[lane], liftedPos, new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]), Vector3.Zero, Vector3.Zero, new Vector3(0f, 0f, 10f), 0f, false, ArenaSession.FixedDt); Assert.True(ws.IsAirborne, $"{spec.Id}: expected IsAirborne == true when lifted 18m above terrain"); Assert.Equal(Vector3.Zero, ws.LastTotalForce); Assert.Equal(Vector3.Zero, ws.LastTotalTorque); Assert.Equal(0f, view.ForceX[lane]); Assert.Equal(0f, view.ForceY[lane]); Assert.Equal(0f, view.ForceZ[lane]); Assert.Equal(0f, view.TorqueX[lane]); Assert.Equal(0f, view.TorqueY[lane]); Assert.Equal(0f, view.TorqueZ[lane]); // 2. End-to-end ArenaSession launch into air: confirm zero GRF while airborne in real Step() session.World.ApplyImpulse( lane, (0f, view.Mass[lane] * 28f, 0f), (view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane])); bool sawAirborneTick = false; for (int t = 0; t < 20; t++) { session.SetHumanInput(0, new PlayerInput(1f, 0f, 0f, 50f, false, false, false)); session.Step(); if (ws.IsAirborne) { sawAirborneTick = true; Assert.Equal(Vector3.Zero, ws.LastTotalForce); Assert.Equal(Vector3.Zero, ws.LastTotalTorque); } } Assert.True(sawAirborneTick, $"{spec.Id}: expected vertical launch to trigger airborne zero-GRF ticks"); } } [Fact] public void HybridB_All7Mechs_ObeyDirectionalInputAtMultipleYaws_NoGooseStepNoDrift() { var specs = new[] { Catalog.Breaker, Catalog.Paladin, Catalog.Raptor, Catalog.Spectre, Catalog.Kestrel, Catalog.Manticore, Catalog.Bastion }; float[] yawsDeg = { 0f, 45f, 90f, 135f }; foreach (var spec in specs) { foreach (float yawDeg in yawsDeg) { float yawRad = yawDeg * MathF.PI / 180f; using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true); for (int i = 1; i < session.State.Contenders.Count; i++) { session.SetContenderPose(i, 500f + i * 16f, 500f); } session.SetContenderPose(0, 0f, 0f, yawRad); session.State.SpawnChassisDrop(0f, 0f, spec); Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}"); session.SetContenderPose(0, 0f, 0f, yawRad); var player = session.State.Contenders[0]; // Lettle -> Wait 5 idle ticks to verify zero rest creep from dead stop for (int t = 0; t < 5; t++) { session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 50f, false, false, false)); session.Step(); } Vector2 cmdFwd = new(MathF.Sin(yawRad), MathF.Cos(yawRad)); Vector2 cmdRight = new(-cmdFwd.Y, cmdFwd.X); // 1. Hold W (Throttle = +1) for 2.0s (120 ticks) from rest Vector2 wStart = new(player.X, player.Z); for (int t = 0; t < 120; t++) { session.SetHumanInput(0, new PlayerInput( Throttle: 1f, Steer: 0f, AimWorldX: player.X + cmdFwd.X * 50f, AimWorldZ: player.Z + cmdFwd.Y * 50f, Fire: false, InteractPickup: false, Brake: false)); session.Step(); } float endWSpeed = player.Speed; Vector2 wDelta = new Vector2(player.X, player.Z) - wStart; float fwdDisp = Vector2.Dot(wDelta, cmdFwd); float latDrift = MathF.Abs(Vector2.Dot(wDelta, cmdRight)); Assert.True(fwdDisp >= 6.0f, $"{spec.Id} @ {yawDeg}deg W 2.0s: fwdDisp={fwdDisp:F2}m < 6.0m (lat={latDrift:F2}m)"); Assert.True(latDrift < 2.0f, $"{spec.Id} @ {yawDeg}deg W 2.0s: latDrift={latDrift:F2}m >= 2.0m (fwd={fwdDisp:F2}m)"); // 2. Release W (Throttle = 0) for 3.0s (180 ticks): stop < 0.30 m/s within physical Coulomb limit, final 1.0s (60 ticks) drift < 0.15m float speedAt1_2s = 0f; float speedAt2_0s = 0f; float timeToStop = -1f; Vector2 finalWindowStart = Vector2.Zero; for (int t = 0; t < 180; t++) { session.SetHumanInput(0, new PlayerInput( Throttle: 0f, Steer: 0f, AimWorldX: player.X + cmdFwd.X * 50f, AimWorldZ: player.Z + cmdFwd.Y * 50f, Fire: false, InteractPickup: false, Brake: false)); session.Step(); if (timeToStop < 0f && player.Speed < 0.30f) { timeToStop = (t + 1) * ArenaSession.FixedDt; } if (t == 71) speedAt1_2s = player.Speed; if (t == 119) { speedAt2_0s = player.Speed; finalWindowStart = new Vector2(player.X, player.Z); } } float finalDrift = (new Vector2(player.X, player.Z) - finalWindowStart).Length(); float maxPhysStopSec = MathF.Max(1.2f, endWSpeed / 16.0f + 0.35f); if (yawDeg == 0f) { _output.WriteLine( $"{spec.Id,-10} maxSpd={spec.MaxSpeed:F1} endWSpd={endWSpeed:F2} " + $"tStop={timeToStop:F2}s (limit={maxPhysStopSec:F2}s) spd@1.2s={speedAt1_2s:F3} spd@2.0s={speedAt2_0s:F3} finalDrift={finalDrift:F4}m"); } Assert.True(timeToStop > 0f && timeToStop <= maxPhysStopSec, $"{spec.Id} @ {yawDeg}deg release W: tStop={timeToStop:F2}s > {maxPhysStopSec:F2}s (endWSpd={endWSpeed:F2}, @2.0s={speedAt2_0s:F3})"); Assert.True(finalDrift < 0.15f, $"{spec.Id} @ {yawDeg}deg release W: final 1.0s drift={finalDrift:F4}m >= 0.15m"); // 3. Hold S (Throttle = -1) for 1.5s (90 ticks) Vector2 sStart = new(player.X, player.Z); Vector2 revDir = new(MathF.Sin(player.Yaw), MathF.Cos(player.Yaw)); for (int t = 0; t < 90; t++) { session.SetHumanInput(0, new PlayerInput( Throttle: -1f, Steer: 0f, AimWorldX: player.X + revDir.X * 50f, AimWorldZ: player.Z + revDir.Y * 50f, Fire: false, InteractPickup: false, Brake: false)); session.Step(); } float revDisp = Vector2.Dot(new Vector2(player.X, player.Z) - sStart, -revDir); Assert.True(revDisp >= 3.0f, $"{spec.Id} @ {yawDeg}deg S 1.5s: revDisp={revDisp:F2}m < 3.0m"); // Settle until stopped before turning test for (int t = 0; t < 180 && (t < 20 || player.Speed > 0.05f); t++) { session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 50f, false, false, false)); session.Step(); } // 4. Hold D (Steer = +1, Throttle = 0) for 1.5s (90 ticks) Vector2 dStart = new(player.X, player.Z); float prevYaw = player.Yaw; float accumYaw = 0f; for (int t = 0; t < 90; t++) { session.SetHumanInput(0, new PlayerInput( Throttle: 0f, Steer: 1f, AimWorldX: player.X, AimWorldZ: player.Z + 50f, Fire: false, InteractPickup: false, Brake: false)); session.Step(); accumYaw += MatchRules.NormalizeAngle(player.Yaw - prevYaw); prevYaw = player.Yaw; } float dTrans = (new Vector2(player.X, player.Z) - dStart).Length(); // Steer = +1 turns right -> negative yaw change (-accumYaw >= 0.5 rad) Assert.True(-accumYaw >= 0.5f, $"{spec.Id} @ {yawDeg}deg D 1.5s: yawChange={accumYaw:F3} rad (expected <= -0.50 rad)"); Assert.True(dTrans < 1.0f, $"{spec.Id} @ {yawDeg}deg D 1.5s: spurious translation={dTrans:F3}m >= 1.0m"); if (yawDeg == 0f || yawDeg == 135f) { _output.WriteLine( $"{spec.Id,-10} yaw={yawDeg,3:F0}deg: fwd={fwdDisp:F2}m lat={latDrift:F2}m " + $"stopSpd={speedAt1_2s:F3}m/s drift={finalDrift:F4}m rev={revDisp:F2}m turn={-accumYaw:F2}rad dTrans={dTrans:F3}m"); } } } } [Fact] public void HybridB_BreakerAndBastion_SionSlopeControl_ObeysInput() { foreach (var spec in new[] { Catalog.Breaker, Catalog.Bastion }) { using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true); for (int i = 1; i < session.State.Contenders.Count; i++) { session.SetContenderPose(i, 900f + i * 16f, 900f); } var sion = session.State.SionMap!; // Find a clear sloped hillside on Sion (slope ~7-18 deg, free of buildings and low wall meshes along a +/-7m corridor) float slopeX = session.State.Contenders[0].X; float slopeZ = session.State.Contenders[0].Z; float slopeYaw = 0f; bool foundSlope = false; for (float r = 40f; r <= 560f && !foundSlope; r += 20f) { for (int a = 0; a < 36 && !foundSlope; a++) { float ang = a * (MathF.Tau / 36f); float x = MathF.Cos(ang) * r; float z = MathF.Sin(ang) * r; if (sion.IsInsideAnyBuildingXz(x, z, 14f)) continue; var (nx, ny, nz) = session.State.Terrain.SampleNormal(x, z); if (ny <= 0.992f && ny >= 0.950f) { float yaw = MathF.Atan2(-nx, -nz); // uphill heading float fx = MathF.Sin(yaw); float fz = MathF.Cos(yaw); float rx = -fz; float rz = fx; bool clear = true; foreach (float lat in new[] { -7f, 0f, 7f }) { float sx = x + rx * lat; float sz = z + rz * lat; for (float d = 0f; d < 28f; d += 4f) { float ax = sx + fx * d; float az = sz + fz * d; float bx = sx + fx * (d + 4f); float bz = sz + fz * (d + 4f); if (sion.IsInsideAnyBuildingXz(ax, az, 4f) || session.State.Terrain.SampleNormal(ax, az).Ny < 0.90f) { clear = false; break; } float gyA = session.State.Terrain.SampleHeight(ax, az); float gyB = session.State.Terrain.SampleHeight(bx, bz); if (!session.HasLineOfSight(ax, gyA + 2.5f, az, bx, gyB + 2.5f, bz)) { clear = false; break; } } if (!clear) break; } if (clear) { slopeX = x; slopeZ = z; slopeYaw = yaw; foundSlope = true; } } } } Assert.True(foundSlope, $"{spec.Id}: failed to locate clear Sion slope test site"); session.SetContenderPose(0, slopeX, slopeZ, slopeYaw); session.State.SpawnChassisDrop(slopeX, slopeZ, spec); Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id} on Sion"); session.SetContenderPose(0, slopeX, slopeZ, slopeYaw); var player = session.State.Contenders[0]; // 1. Drive forward up/along slope (2.0s) Vector2 startPos = new(player.X, player.Z); Vector2 fwdDir = new(MathF.Sin(slopeYaw), MathF.Cos(slopeYaw)); var ws = session.GetWalkerState(true, player.Id)!; float gStart = session.State.Terrain.SampleHeight(player.X, player.Z); float startY = player.Y; for (int t = 0; t < 120; t++) { session.SetHumanInput(0, new PlayerInput( Throttle: 1f, Steer: 0f, AimWorldX: player.X + fwdDir.X * 50f, AimWorldZ: player.Z + fwdDir.Y * 50f, Fire: false, InteractPickup: false, Brake: false)); session.Step(); } float gEnd = session.State.Terrain.SampleHeight(player.X, player.Z); float fwdDisp = Vector2.Dot(new Vector2(player.X, player.Z) - startPos, fwdDir); int pLane = session.GetContenderBody(player.Id)!.Value.Lane; string touchesStr = ""; foreach (var tc in session.World.Facts.Touching) { if (tc.LaneA == pLane || tc.LaneB == pLane) { ulong other = tc.LaneA == pLane ? tc.StableIdB : tc.StableIdA; touchesStr += $"{other},"; } } _output.WriteLine( $"{spec.Id} Sion slope ({slopeX:F1},{slopeZ:F1}) gStart={gStart:F2} startY={startY:F2} (H={spec.HalfHeight:F2}) -> " + $"({player.X:F1},{player.Y:F2},{player.Z:F1}) gEnd={gEnd:F2} pYaw={player.Yaw:F2} fwdDisp={fwdDisp:F2}m air={ws.IsAirborne} force={ws.LastTotalForce} touching=[{touchesStr}]"); Assert.True(fwdDisp >= 5.0f, $"{spec.Id} Sion slope W 2.0s: fwdDisp={fwdDisp:F2}m < 5.0m"); // 2. Turn cleanly on Sion slope (D for 1.5s) float prevYaw = player.Yaw; float accumYaw = 0f; for (int t = 0; t < 90; t++) { session.SetHumanInput(0, new PlayerInput(0f, 1f, player.X, player.Z + 50f, false, false, false)); session.Step(); accumYaw += MatchRules.NormalizeAngle(player.Yaw - prevYaw); prevYaw = player.Yaw; } Assert.True(-accumYaw >= 0.35f, $"{spec.Id} Sion slope D 1.5s: yawChange={accumYaw:F3} rad"); // 3. Release controls on slope (3.0s): must stop cleanly and NOT slide away float speedAt1_2s = 0f; float timeToStop = -1f; Vector2 finalWinStart = Vector2.Zero; for (int t = 0; t < 180; t++) { session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 50f, false, false, false)); session.Step(); if (timeToStop < 0f && player.Speed < 0.35f) timeToStop = (t + 1) * ArenaSession.FixedDt; if (t == 71) speedAt1_2s = player.Speed; if (t == 119) finalWinStart = new Vector2(player.X, player.Z); } float finalSlide = (new Vector2(player.X, player.Z) - finalWinStart).Length(); _output.WriteLine( $"{spec.Id,-10} Sion slope ({slopeX:F1},{slopeZ:F1}): fwd={fwdDisp:F2}m turn={-accumYaw:F2}rad " + $"tStop={timeToStop:F2}s spd@1.2s={speedAt1_2s:F3}m/s slopeSlide={finalSlide:F4}m"); Assert.True(timeToStop > 0f && timeToStop <= 2.0f, $"{spec.Id} Sion slope release: tStop={timeToStop:F2}s > 2.0s (spd@1.2s={speedAt1_2s:F3}m/s)"); Assert.True(finalSlide < 0.18f, $"{spec.Id} Sion slope release: 1.0s slide={finalSlide:F4}m >= 0.18m"); } } [Fact] public void HybridB_Bastion_SteepSionHills_15To22Deg_ClimbsWithoutBeaching() { using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true); for (int i = 1; i < session.State.Contenders.Count; i++) { session.SetContenderPose(i, 900f + i * 16f, 900f); } var sion = session.State.SionMap!; var sites = new System.Collections.Generic.List<(float X, float Z, float Yaw, float Ny)>(); for (float r = 60f; r <= 720f && sites.Count < 3; r += 25f) { for (int a = 0; a < 48 && sites.Count < 3; a++) { float ang = a * (MathF.Tau / 48f); float x = MathF.Cos(ang) * r; float z = MathF.Sin(ang) * r; if (sion.IsInsideAnyBuildingXz(x, z, 14f)) continue; var (nx, ny, nz) = session.State.Terrain.SampleNormal(x, z); if (ny < 0.925f || ny > 0.966f) continue; float yaw = MathF.Atan2(-nx, -nz); float fx = MathF.Sin(yaw); float fz = MathF.Cos(yaw); float rx = -fz; float rz = fx; bool clear = true; foreach (float lat in new[] { -7.5f, 0f, 7.5f }) { float sx = x + rx * lat; float sz = z + rz * lat; for (float d = 0f; d < 28f; d += 4f) { float ax = sx + fx * d; float az = sz + fz * d; float bx = sx + fx * (d + 4f); float bz = sz + fz * (d + 4f); if (sion.IsInsideAnyBuildingXz(ax, az, 4f) || session.State.Terrain.SampleNormal(ax, az).Ny < 0.88f) { clear = false; break; } float gyA = session.State.Terrain.SampleHeight(ax, az); float gyB = session.State.Terrain.SampleHeight(bx, bz); if (!session.HasLineOfSight(ax, gyA + 2.5f, az, bx, gyB + 2.5f, bz)) { clear = false; break; } } if (!clear) break; } if (clear && sites.TrueForAll(s => (s.X - x) * (s.X - x) + (s.Z - z) * (s.Z - z) > 60f * 60f)) { sites.Add((x, z, yaw, ny)); } } } Assert.NotEmpty(sites); session.SetContenderPose(0, sites[0].X, sites[0].Z, sites[0].Yaw); session.State.SpawnChassisDrop(sites[0].X, sites[0].Z, Catalog.Bastion); Assert.True(session.TrySwapNearbyChassis(0), "Failed swap to Bastion on Sion"); var player = session.State.Contenders[0]; foreach (var site in sites) { session.SetContenderPose(0, site.X, site.Z, site.Yaw); Vector2 startPos = new(player.X, player.Z); Vector2 fwdDir = new(MathF.Sin(site.Yaw), MathF.Cos(site.Yaw)); float gStart = session.State.Terrain.SampleHeight(player.X, player.Z); for (int t = 0; t < 120; t++) { session.SetHumanInput(0, new PlayerInput( Throttle: 1f, Steer: 0f, AimWorldX: player.X + fwdDir.X * 50f, AimWorldZ: player.Z + fwdDir.Y * 50f, Fire: false, InteractPickup: false, Brake: false)); session.Step(); } float disp2s = Vector2.Dot(new Vector2(player.X, player.Z) - startPos, fwdDir); float endSpd = player.Speed; float gEnd = session.State.Terrain.SampleHeight(player.X, player.Z); var ws = session.GetWalkerState(true, player.Id)!; _output.WriteLine( $"Bastion Sion 15-22deg site ({site.X:F1},{site.Z:F1}) ny={site.Ny:F3}: " + $"disp2s={disp2s:F2}m endSpd={endSpd:F2}m/s climb={(gEnd - gStart):F2}m force={ws.LastTotalForce}"); Assert.True(disp2s >= 10.0f, $"Bastion beached on Sion hill ny={site.Ny:F3}: disp2s={disp2s:F2}m < 10.0m"); Assert.True(endSpd >= 6.0f, $"Bastion stalled on Sion hill ny={site.Ny:F3}: endSpd={endSpd:F2}m/s < 6.0m/s"); } } [Fact] public void Kestrel_5x5Coronal_ArmAndEngineDamage_DoesNotCrippleLegs() { var grid = new ChassisGrid(Catalog.Kestrel); Span legs = stackalloc float[4]; // Destroy right weapon arm (4,2),(4,3) and engine core (2,2),(2,3) grid.Armor[4, 2] = 0f; grid.Armor[4, 3] = 0f; grid.Armor[2, 2] = 0f; grid.Armor[2, 3] = 0f; grid.GetLegIntegrities(legs); Assert.Equal(1.0f, legs[0], precision: 3); Assert.Equal(1.0f, legs[1], precision: 3); Assert.Equal(1.0f, grid.LegIntegrity, precision: 3); // Destroy left leg (1,4) -> only legs[0] drops grid.Armor[1, 4] = 0f; grid.GetLegIntegrities(legs); Assert.True(legs[0] < 1.0f, $"Expected left leg integrity < 1.0 after (1,4) destroyed, got {legs[0]:F3}"); Assert.Equal(1.0f, legs[1], precision: 3); Assert.True(grid.LegIntegrity < 1.0f); // Destroy right leg (3,4) -> legs[1] also drops grid.Armor[3, 4] = 0f; grid.GetLegIntegrities(legs); Assert.True(legs[1] < 1.0f, $"Expected right leg integrity < 1.0 after (3,4) destroyed, got {legs[1]:F3}"); } [Fact] public void DorsalWalkers_AimedShotsWithSpreadAt80m_DoNotSailOverTop() { foreach (var spec in new[] { Catalog.Bastion, Catalog.Manticore }) { using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true); for (int i = 2; i < session.State.Contenders.Count; i++) { session.SetContenderPose(i, 900f + i * 16f, 900f); } // Target contender 1 on flat ground facing perpendicular so silhouette is clean session.SetContenderPose(1, 0f, 80f, MathF.PI * 0.5f); session.State.Contenders[1].Grid.SwapChassis(spec); session.SetContenderPose(1, 0f, 80f, MathF.PI * 0.5f); // Shooter contender 0 at 80m away session.SetContenderPose(0, 0f, 0f, 0f); for (int t = 0; t < 45; t++) { session.SetHumanInput(0, new PlayerInput(0f, 0f, 0f, 80f, false, false, false)); session.Step(); } var target = session.State.Contenders[1]; var shooter = session.State.Contenders[0]; ulong targetStableId = ArenaSession.ContenderStableIdBase + (ulong)target.Id; float aimY = MatchRules.GetTargetAimY(target.Y, target.Grid.Spec.HalfHeight); Vector3 muzzle = new(shooter.X, shooter.Y + shooter.Grid.Spec.HalfHeight * 0.25f, shooter.Z + shooter.Grid.Spec.HalfLength + 0.35f); Vector3 baseDir = Vector3.Normalize(new Vector3(target.X - muzzle.X, aimY - muzzle.Y, target.Z - muzzle.Z)); var rng = new Random(12345); const int shotCount = 250; const float totalSpread = 0.015f; int overTopMisses = 0; int hits = 0; for (int s = 0; s < shotCount; s++) { float yawJitter = ((float)rng.NextDouble() * 2f - 1f) * totalSpread; float pitchJitter = ((float)rng.NextDouble() * 2f - 1f) * (totalSpread * 0.35f); var yawQ = Quaternion.CreateFromAxisAngle(Vector3.UnitY, yawJitter); var rotated = Vector3.Transform(baseDir, yawQ); var right = Vector3.Cross(rotated, Vector3.UnitY); if (right.LengthSquared() > 1e-4f) { rotated = Vector3.Transform(rotated, Quaternion.CreateFromAxisAngle(Vector3.Normalize(right), pitchJitter)); } var dir = Vector3.Normalize(rotated); var hit = session.World.CastRayClosest((muzzle.X, muzzle.Y, muzzle.Z), (dir.X * 160f, dir.Y * 160f, dir.Z * 160f)); if (hit.Hit && hit.StableId == targetStableId) { hits++; } else { float tPlane = (target.Z - muzzle.Z) / MathF.Max(1e-4f, dir.Z); float yAtTarget = muzzle.Y + dir.Y * tPlane; if (yAtTarget > target.Y) { overTopMisses++; } } } float overTopRate = (float)overTopMisses / shotCount; _output.WriteLine($"{spec.Id}: 80m hits={hits}/{shotCount}, overTopMisses={overTopMisses} ({overTopRate * 100f:F2}%)"); Assert.True(overTopRate < 0.02f, $"{spec.Id}: over-top miss rate {overTopRate * 100f:F2}% >= 2%"); } } [Fact] public void HybridB_BastionAndManticore_ExactSionSteepHills_ClimbWithoutBeaching() { var failingSites = new (string Name, float X, float Z)[] { ("Site#9", 459.6f, -385.7f), ("Site#12", 413.0f, 589.8f), ("Site#7", 0.0f, -580.0f), ("Site#2", 360.4f, -252.4f), }; foreach (var spec in new[] { Catalog.Bastion, Catalog.Manticore }) { using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true); for (int i = 1; i < session.State.Contenders.Count; i++) { session.SetContenderPose(i, 900f + i * 16f, 900f); } session.SetContenderPose(0, failingSites[0].X, failingSites[0].Z, 0f); session.State.SpawnChassisDrop(failingSites[0].X, failingSites[0].Z, spec); Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}"); var player = session.State.Contenders[0]; foreach (var site in failingSites) { var (nx, ny, nz) = session.State.Terrain.SampleNormal(site.X, site.Z); float uphillYaw = MathF.Atan2(-nx, -nz); session.SetContenderPose(0, site.X, site.Z, uphillYaw); Vector2 startPos = new(player.X, player.Z); Vector2 fwdDir = new(MathF.Sin(uphillYaw), MathF.Cos(uphillYaw)); float gStart = session.State.Terrain.SampleHeight(player.X, player.Z); for (int t = 0; t < 120; t++) { session.SetHumanInput(0, new PlayerInput( Throttle: 1f, Steer: 0f, AimWorldX: player.X + fwdDir.X * 50f, AimWorldZ: player.Z + fwdDir.Y * 50f, Fire: false, InteractPickup: false, Brake: false)); session.Step(); } float disp2s = Vector2.Dot(new Vector2(player.X, player.Z) - startPos, fwdDir); float endSpd = player.Speed; float gEnd = session.State.Terrain.SampleHeight(player.X, player.Z); _output.WriteLine( $"{spec.Id} {site.Name} ({site.X:F1},{site.Z:F1}) ny={ny:F3}: disp2s={disp2s:F2}m endSpd={endSpd:F2}m/s climb={(gEnd - gStart):F2}m"); Assert.True(disp2s >= 8.0f, $"{spec.Id} beached at {site.Name} ({site.X:F1},{site.Z:F1}) ny={ny:F3}: disp2s={disp2s:F2}m < 8.0m"); Assert.True(endSpd >= 4.0f, $"{spec.Id} stalled at {site.Name} ({site.X:F1},{site.Z:F1}) ny={ny:F3}: endSpd={endSpd:F2}m/s < 4.0m/s"); } } } [Fact] public void HybridB_Bastion_StationaryFacingHill_DoesNotHyperExtendLegs() { using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true); for (int i = 1; i < session.State.Contenders.Count; i++) { session.SetContenderPose(i, 900f + i * 16f, 900f); } const float siteX = 0f; const float siteZ = -180f; var (nx, _, nz) = session.State.Terrain.SampleNormal(siteX, siteZ); float uphillYaw = (nx * nx + nz * nz) > 1e-5f ? MathF.Atan2(-nx, -nz) : 0f; session.SetContenderPose(0, siteX, siteZ, uphillYaw); session.State.SpawnChassisDrop(siteX, siteZ, Catalog.Bastion); Assert.True(session.TrySwapNearbyChassis(0), "Failed swap to Bastion at Site#0"); session.SetContenderPose(0, siteX, siteZ, uphillYaw); var player = session.State.Contenders[0]; var ws = session.GetWalkerState(true, player.Id)!; float modelRide = WalkerLocomotion.GetRideHeight(Catalog.Bastion); float maxRelCom = 0f; float maxReachOverflow = 0f; for (int t = 0; t < 120; t++) { session.SetHumanInput(0, new PlayerInput( Throttle: 0f, Steer: 0f, AimWorldX: player.X + MathF.Sin(uphillYaw) * 50f, AimWorldZ: player.Z + MathF.Cos(uphillYaw) * 50f, Fire: false, InteractPickup: false, Brake: false)); session.Step(); float groundY = session.State.Terrain.SampleHeight(player.X, player.Z); float relCom = player.Y - groundY; if (relCom > maxRelCom) { maxRelCom = relCom; } Vector3 comPos = new(player.X, player.Y, player.Z); Quaternion qBody = new(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW); for (int leg = 0; leg < ws.Geom.LegCount; leg++) { Vector3 hipW = comPos + Vector3.Transform(ws.Geom.Legs[leg].HipInCom * ws.GeomScale, qBody); Vector3 ankleW = ws.FootSole[leg] + ws.FootNormal[leg] * (ws.Geom.Legs[leg].AnkleH * ws.GeomScale); float dist = Vector3.Distance(hipW, ankleW); float maxReach = ws.Geom.Legs[leg].MaxLegReach * ws.GeomScale; float overflow = dist - maxReach; if (overflow > maxReachOverflow) { maxReachOverflow = overflow; } } } _output.WriteLine($"Bastion idle Site#0: maxRelCom={maxRelCom:F3}m (ride={modelRide:F3}m) maxReachOverflow={maxReachOverflow:F4}m"); Assert.True(maxRelCom <= modelRide + 0.25f, $"Bastion idle COM floated too high: {maxRelCom:F3}m > {modelRide + 0.25f:F3}m"); Assert.True(maxReachOverflow <= 0.05f, $"Bastion idle leg hyper-extended past MaxLegReach by {maxReachOverflow:F4}m > 0.05m"); } private static (TerrainField Terrain, float[] Heights, int GridRes, float CellSize, float MinY, float MaxY) MakeSyntheticSlope(float slopeDeg) { const float sizeMeters = 400f; const int gridRes = 201; const float cellSize = sizeMeters / (gridRes - 1); float half = sizeMeters * 0.5f; float tan = MathF.Tan(slopeDeg * MathF.PI / 180f); var heights = new float[gridRes * gridRes]; for (int iz = 0; iz < gridRes; iz++) { float z = -half + iz * cellSize; float h = (z + half) * tan; int row = iz * gridRes; for (int ix = 0; ix < gridRes; ix++) { heights[row + ix] = h; } } float minY = -10f; float maxY = sizeMeters * tan + 10f; var terrain = TerrainField.LoadHeightmap(sizeMeters, gridRes, heights, minY, maxY, seed: 1UL); return (terrain, heights, gridRes, cellSize, minY, maxY); } private static (Box3DSoaWorld World, Box3DSoaBodyHandle Body, WalkerState Walker, ChassisGrid Grid) SpawnWalkerOnSyntheticTerrain( ChassisSpec spec, in (TerrainField Terrain, float[] Heights, int GridRes, float CellSize, float MinY, float MaxY) syn, float startX, float startZ) { var world = new Box3DSoaWorld(capacity: 8, gravityX: 0f, gravityY: -20f, gravityZ: 0f); float half = syn.Terrain.MapHalfExtent; world.AddStaticHeightField( 1UL, (-half, 0f, -half), syn.Heights, syn.GridRes, syn.GridRes, (syn.CellSize, 1.0f, syn.CellSize), syn.MinY, syn.MaxY, friction: 0.15f, restitution: 0.0f); float physHalfH = ArenaSession.GetPhysicsHalfHeight(spec); float volume = 8f * spec.HalfWidth * physHalfH * spec.HalfLength; float density = spec.MassKg / MathF.Max(0.1f, volume); Quaternion q0 = Quaternion.Identity; if (spec.Plane == GridPlane.Dorsal) { var (nx, ny, nz) = syn.Terrain.SampleNormal(startX, startZ); Vector3 desUp = Vector3.Normalize(Vector3.Lerp(Vector3.UnitY, new Vector3(nx, ny, nz), 0.90f)); Vector3 axis = Vector3.Cross(Vector3.UnitY, desUp); if (axis.LengthSquared() > 1e-8f) { float ang = MathF.Min(0.295f, MathF.Acos(Math.Clamp(desUp.Y, -1f, 1f))); q0 = Quaternion.Normalize(Quaternion.CreateFromAxisAngle(Vector3.Normalize(axis), ang)); } } float spawnY = syn.Terrain.SampleHeight(startX, startZ) + WalkerLocomotion.GetRideHeight(spec); var body = world.AddBox( 1000UL, (startX, spawnY, startZ), (spec.HalfWidth, physHalfH, spec.HalfLength), density, (q0.X, q0.Y, q0.Z, q0.W), friction: 0.2f, restitution: 0.1f); var grid = new ChassisGrid(spec); var ws = new WalkerState(spec); ws.InitializePose(new Vector3(startX, spawnY, startZ), q0, world.View.Mass[body.Lane], syn.Terrain); return (world, body, ws, grid); } [Fact] public void HybridB_All7Mechs_BoldWeightedStrides_NoTinyBabySteps() { var specs = new[] { Catalog.Breaker, Catalog.Paladin, Catalog.Raptor, Catalog.Spectre, Catalog.Kestrel, Catalog.Manticore, Catalog.Bastion }; var flat = MakeSyntheticSlope(0f); foreach (var spec in specs) { var (world, body, ws, grid) = SpawnWalkerOnSyntheticTerrain(spec, flat, 0f, -140f); using (world) { int lane = body.Lane; var view = world.View; int nLegs = ws.Geom.LegCount; var prevPlanted = new bool[nLegs]; var lastPlantTime = new float[nLegs]; for (int i = 0; i < nLegs; i++) { prevPlanted[i] = ws.Planted[i]; lastPlantTime[i] = -1f; } var minHipPitch = new float[nLegs]; var maxHipPitch = new float[nLegs]; Array.Fill(minHipPitch, float.PositiveInfinity); Array.Fill(maxHipPitch, float.NegativeInfinity); double stepDurSum = 0.0; int stepDurCount = 0; double footSepSum = 0.0; double swingTravelSum = 0.0; int strideCount = 0; for (int t = 0; t < 180; t++) { var pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]); var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]); var vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]); var angVel = new Vector3(view.AngularVelocityX[lane], view.AngularVelocityY[lane], view.AngularVelocityZ[lane]); WalkerLocomotion.StepWalker( ws, grid, flat.Terrain, view, lane, view.Mass[lane], pos, q, vel, angVel, new Vector3(0f, 0f, grid.Spec.MaxSpeed), 0f, false, ArenaSession.FixedDt); world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount); if (t >= 60) { for (int i = 0; i < nLegs; i++) { float hp = ws.Actuators[i].Theta.HipPitch; if (hp < minHipPitch[i]) minHipPitch[i] = hp; if (hp > maxHipPitch[i]) maxHipPitch[i] = hp; bool curPlanted = ws.Planted[i]; if (!prevPlanted[i] && curPlanted) { if (lastPlantTime[i] >= 0f) { float cycleSec = ws.SimTime - lastPlantTime[i]; stepDurSum += cycleSec * 0.5f; stepDurCount++; } lastPlantTime[i] = ws.SimTime; int partner = i ^ 1; float foreAftSep = MathF.Abs(ws.FootSole[i].Z - ws.FootSole[partner].Z); float swingTravel = Vector2.Distance( new Vector2(ws.SwingTargetSole[i].X, ws.SwingTargetSole[i].Z), new Vector2(ws.SwingStartSole[i].X, ws.SwingStartSole[i].Z)); footSepSum += foreAftSep; swingTravelSum += swingTravel; strideCount++; } prevPlanted[i] = curPlanted; } } else { for (int i = 0; i < nLegs; i++) { prevPlanted[i] = ws.Planted[i]; } } } Assert.True(stepDurCount >= 2, $"{spec.Id}: expected >= 2 measured step intervals, got {stepDurCount}"); Assert.True(strideCount >= 2, $"{spec.Id}: expected >= 2 measured strides, got {strideCount}"); float avgStepDur = (float)(stepDurSum / stepDurCount); float avgFootSep = (float)(footSepSum / strideCount); float avgSwingTravel = (float)(swingTravelSum / strideCount); float maxHipSwingRad = 0f; for (int i = 0; i < nLegs; i++) { maxHipSwingRad = MathF.Max(maxHipSwingRad, maxHipPitch[i] - minHipPitch[i]); } bool isCompact = spec.Id == "breaker" || spec.Id == "manticore"; float minFootSep = isCompact ? 1.25f : 1.80f; _output.WriteLine( $"{spec.Id,-10} stepDur={avgStepDur:F3}s ({1f / avgStepDur:F2} Hz) footToFoot={avgFootSep:F2}m " + $"swingTravel={avgSwingTravel:F2}m hipPitchP2P={maxHipSwingRad:F3}rad ({maxHipSwingRad * 180f / MathF.PI:F1}deg)"); Assert.True(avgStepDur >= 0.21f, $"{spec.Id}: tiny baby-step cadence {avgStepDur:F3}s < 0.21s"); Assert.True(avgFootSep >= minFootSep, $"{spec.Id}: foot-to-foot stride {avgFootSep:F2}m < {minFootSep:F2}m"); Assert.True(maxHipSwingRad >= 0.45f, $"{spec.Id}: insufficient hip-pitch actuator swing {maxHipSwingRad:F3} rad < 0.45 rad"); } } } [Fact] public void HybridB_All7Mechs_ClimbSmallAndMediumSlopes_6To22Deg_NeverDefeated() { var specs = new[] { Catalog.Breaker, Catalog.Paladin, Catalog.Raptor, Catalog.Spectre, Catalog.Kestrel, Catalog.Manticore, Catalog.Bastion }; float[] slopesDeg = { 6f, 12f, 18f, 22f }; var flat = MakeSyntheticSlope(0f); var slopeTerrains = new (float Deg, (TerrainField Terrain, float[] Heights, int GridRes, float CellSize, float MinY, float MaxY) Syn)[slopesDeg.Length]; for (int s = 0; s < slopesDeg.Length; s++) { slopeTerrains[s] = (slopesDeg[s], MakeSyntheticSlope(slopesDeg[s])); } foreach (var spec in specs) { float flatSpeed; { var (world, body, ws, grid) = SpawnWalkerOnSyntheticTerrain(spec, flat, 0f, -140f); using (world) { int lane = body.Lane; var view = world.View; for (int t = 0; t < 150; t++) { var pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]); var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]); var vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]); var angVel = new Vector3(view.AngularVelocityX[lane], view.AngularVelocityY[lane], view.AngularVelocityZ[lane]); WalkerLocomotion.StepWalker( ws, grid, flat.Terrain, view, lane, view.Mass[lane], pos, q, vel, angVel, new Vector3(0f, 0f, grid.Spec.MaxSpeed), 0f, false, ArenaSession.FixedDt); world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount); } flatSpeed = MathF.Sqrt(view.VelocityX[lane] * view.VelocityX[lane] + view.VelocityZ[lane] * view.VelocityZ[lane]); } } var summary = $"{spec.Id,-10} flat={flatSpeed:F2}m/s"; foreach (var (deg, syn) in slopeTerrains) { var (world, body, ws, grid) = SpawnWalkerOnSyntheticTerrain(spec, syn, 0f, -140f); using (world) { int lane = body.Lane; var view = world.View; float gStart = syn.Terrain.SampleHeight(0f, -140f); float minSpeedAfterAccel = float.PositiveInfinity; for (int t = 0; t < 150; t++) { var pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]); var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]); var vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]); var angVel = new Vector3(view.AngularVelocityX[lane], view.AngularVelocityY[lane], view.AngularVelocityZ[lane]); WalkerLocomotion.StepWalker( ws, grid, syn.Terrain, view, lane, view.Mass[lane], pos, q, vel, angVel, new Vector3(0f, 0f, grid.Spec.MaxSpeed), 0f, false, ArenaSession.FixedDt); world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount); if (t >= 30) { float fwdSpd = view.VelocityZ[lane]; if (fwdSpd < minSpeedAfterAccel) minSpeedAfterAccel = fwdSpd; } } float endZ = view.PositionZ[lane]; float endHorizSpeed = MathF.Sqrt(view.VelocityX[lane] * view.VelocityX[lane] + view.VelocityZ[lane] * view.VelocityZ[lane]); float gEnd = syn.Terrain.SampleHeight(view.PositionX[lane], endZ); float climbM = gEnd - gStart; float dispM = endZ - (-140f); float ratio = endHorizSpeed / MathF.Max(1f, flatSpeed); float reqRatio = deg <= 12f ? 0.60f : 0.45f; summary += $" | {deg:F0}deg:{endHorizSpeed:F1}m/s({ratio * 100f:F0}%,+{climbM:F1}m,min={minSpeedAfterAccel:F1})"; Assert.True(dispM > 12f && climbM > 1.2f, $"{spec.Id} @ {deg}deg: failed climb (disp={dispM:F2}m, climb={climbM:F2}m)"); Assert.True(minSpeedAfterAccel > 4.0f, $"{spec.Id} @ {deg}deg: stalled or kicked back (minFwdSpd={minSpeedAfterAccel:F2}m/s)"); Assert.True(ratio >= reqRatio, $"{spec.Id} @ {deg}deg: speed {endHorizSpeed:F2}m/s ({ratio * 100f:F1}% of flat {flatSpeed:F2}) < {reqRatio * 100f:F0}%"); } } _output.WriteLine(summary); } } [Fact] public void HybridB_All7Mechs_YawRelease_StopsCrisplyWithMinimalCoast() { var specs = new[] { Catalog.Breaker, Catalog.Paladin, Catalog.Raptor, Catalog.Spectre, Catalog.Kestrel, Catalog.Manticore, Catalog.Bastion }; foreach (var spec in specs) { using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true); for (int i = 1; i < session.State.Contenders.Count; i++) { session.SetContenderPose(i, 500f + i * 16f, 500f); } session.SetContenderPose(0, 0f, 0f, 0f); session.State.SpawnChassisDrop(0f, 0f, spec); Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}"); session.SetContenderPose(0, 0f, 0f, 0f); var player = session.State.Contenders[0]; int lane = session.GetContenderBody(player.Id)!.Value.Lane; // Spin 1.0s at full steer for (int t = 0; t < 60; t++) { session.SetHumanInput(0, new PlayerInput( Throttle: 0f, Steer: 1.0f, AimWorldX: 0f, AimWorldZ: 50f, Fire: false, InteractPickup: false, Brake: false)); session.Step(); } float yawAtRelease = player.Yaw; float spinAngVelY = session.World.View.AngularVelocityY[lane]; float maxOvershootRad = 0f; float angVelAt020s = 0f; // Release for 0.5s (30 ticks) for (int t = 0; t < 30; t++) { session.SetHumanInput(0, new PlayerInput( Throttle: 0f, Steer: 0f, AimWorldX: 0f, AimWorldZ: 50f, Fire: false, InteractPickup: false, Brake: false)); session.Step(); float overshoot = MathF.Abs(MatchRules.NormalizeAngle(player.Yaw - yawAtRelease)); if (overshoot > maxOvershootRad) { maxOvershootRad = overshoot; } if (t == 11) { angVelAt020s = session.World.View.AngularVelocityY[lane]; } } _output.WriteLine( $"{spec.Id,-10} spinOmegaY={spinAngVelY:F2}rad/s overshoot={maxOvershootRad:F4}rad ({maxOvershootRad * 180f / MathF.PI:F2}deg) " + $"omegaY@0.20s={angVelAt020s:F4}rad/s"); Assert.True(MathF.Abs(spinAngVelY) > 1.0f, $"{spec.Id}: failed to spin up before release (omegaY={spinAngVelY:F2})"); Assert.True(maxOvershootRad <= 0.08f, $"{spec.Id}: yaw coast overshoot {maxOvershootRad:F4} rad ({maxOvershootRad * 180f / MathF.PI:F2} deg) > 0.08 rad"); Assert.True(MathF.Abs(angVelAt020s) <= 0.05f, $"{spec.Id}: residual yaw angVel@0.20s={angVelAt020s:F4} rad/s > 0.05 rad/s"); } } } }