# watch.py - replay the champion in a 3D window  (macOS: run with mjpython)
import time, numpy as np, mujoco, mujoco.viewer
from walker import model, N          # reuses the robot (guarded below)

genes = np.load("champion.npy")
amp, phase, offset = genes[:N], genes[N:2*N], genes[2*N:3*N]
freq = np.clip(1.5 + genes[-1], 0.5, 3.0)
d = mujoco.MjData(model)
with mujoco.viewer.launch_passive(model, d) as v:
    while v.is_running():
        d.ctrl[:] = amp * np.sin(2 * np.pi * freq * d.time + phase) + offset
        mujoco.mj_step(model, d)
        v.sync()
        time.sleep(model.opt.timestep)
