"""Satisfy the original first-Red demo through genuine controller recruitment."""
from test_gameplay_settled_route import SettledRoute


def initial_red_intro(game,driver):
    entry=driver.boot_day1(game,timeout=300)
    state=game.wait_state(lambda s:True)
    reds=[p for p in state['pikis'] if p['kind']==1]
    assert reds,'original authored Red Pikmin must exist before later scene setup'
    center=[sum(p['position'][i] for p in reds)/len(reds) for i in range(3)]
    driver.walk_to(game,center,radius=35,timeout=45)
    driver.aim_at(game,center,radius=15)
    game.input(buttons=driver.B,frames=120)
    route=SettledRoute(game,driver)
    route.playable()
    game.input(frames=90)
    state=route.playable()
    assert any(p['kind']==1 and p['navi_id'] for p in state['pikis'])
    return {'entry':entry,'state':state,'initial_authored_red_ids':[p['actor_id'] for p in reds],
            'boundary':'normal walking, cursor aim and whistle complete actual first-Red demo before later fixture setup'}
