const formatMoney = (n) => n >= 1e6 ? `$${(n / 1e6).toFixed(2)}M` : n >= 1e3 ? `$${(n / 1e3).toFixed(1)}K` : `$${n?.toFixed(0) ?? 0}` const OUTCOME_MAP = { ipo: { ascii: '[IPO]', title: 'IPO_SUCCESS', cls: 'ipo' }, acquisition: { ascii: '[ACQ]', title: 'ACQUIRED', cls: 'acquisition' }, runway_exhausted: { ascii: '[DEAD]', title: 'BANKRUPTCY', cls: 'bankruptcy' }, finished_10: { ascii: '[DONE]', title: 'EPISODE_COMPLETE', cls: 'default' }, } const DIVIDER = '================================================' export default function EndScreen({ obs, onReplay }) { if (!obs) return null const { state } = obs const reason = state?.done_reason ?? 'finished_10' const { ascii, title, cls } = OUTCOME_MAP[reason] ?? OUTCOME_MAP['finished_10'] const history = state?.history ?? [] const roundsWon = history.filter(h => h.agent_won_vote).length return (
{/* ASCII banner */}
{ascii}
{title}
{reason.replace(/_/g, '_')}
{DIVIDER}
PROFIT_SCORE
{(state?.profitability_score ?? 0).toFixed(1)}
REVENUE
{formatMoney(state?.revenue ?? 0)}
RUNWAY
{(state?.runway_months ?? 0).toFixed(1)}mo
ROUNDS_WON
{roundsWon}/{history.length}
MORALE
{Math.round((state?.team_morale ?? 0) * 100)}%
REG_RISK
{Math.round((state?.regulatory_risk ?? 0) * 100)}%
{history.length > 0 && (
// round_log
{history.map((h) => (
R{String(h.round).padStart(2,'0')} {(h.event_title ?? '').split('—').slice(-1)[0]?.trim()} {h.agent_won_vote ? '[OK]' : '[X]'} {(h.agent_decision ?? '').replace(/_/g, '_')}
))}
)}
) }