yes
Prompt
Write a complete, single-file, zero-dependency Python 3 simulation (using only the standard library: math, random, time, dataclasses, typing) of a deterministic, authoritative multiplayer server tick loop for a 3D physics-based space combat game. Requirements: 1. Custom 3D Math & Spatial Hashing: - Implement a Vector3 class and a Quaternion class (including quaternion multiplication, vector rotation, SLERP, and integration of angular velocity over a fixed timestep dt). Do not use Euler angles for orientation updates. - Implement a 3D Spatial Hash Grid with dynamic cell sizing to broad-phase detect potential collisions among 500+ moving entities without O(n^2) checks. 2. Deterministic Rigid-Body Physics & Sub-Stepping: - Use a fixed timestep (60 Hz) with an accumulator pattern and 4 physics sub-steps per tick. - Implement 3D sphere-to-sphere and oriented-bounding-box (OBB) to sphere narrow-phase collision detection using the Separating Axis Theorem (SAT) or closest-point projection. - Resolve collisions with conservation of linear and angular momentum (impulse-based resolution applying both linear velocity changes and torque/angular velocity changes based on contact offset and moment of inertia). 3. Client-Side Prediction & Server Reconciliation (Rollback): - Simulate a latency-affected client (150ms round-trip time with Β±20ms jitter) sending timestamped input packets (thrust, pitch, yaw, roll, fire). - Implement a circular state history buffer on the server (storing the last 120 ticks). - When a delayed "fire" command arrives from the client, perform lag compensation: rewind the world state to the client's perceived timestamp, perform a 3D ray-vs-OBB intersection test for hitscan weapons, apply damage/impulse if hit, and fast-forward/re-simulate the affected physics state to the current tick. 4. Output & Verification: - Run a headless 10-second simulated match (600 ticks) with 1 player ship, 10 AI ships executing basic predictive lead-target steering, and 500 drifting asteroid OBBs. - Print a deterministic SHA-256 hash of the final world state (all positions, orientations, velocities, and health values rounded to 6 decimal places) at Tick 600, along with average tick execution time in milliseconds. - Ensure the code runs cleanly without syntax errors, NaN propagation, or gimbal lock.
Response not available
Response not available