diff --git a/src/game/60-features/92-puzzles.js b/src/game/60-features/92-puzzles.js index 3fa9fa5..91f156b 100644 --- a/src/game/60-features/92-puzzles.js +++ b/src/game/60-features/92-puzzles.js @@ -101,8 +101,11 @@ const pzNewPop=()=>({day:0,bb:null,boost:0,down:0,routers:1,gen:false}); function pzAfter(){if(UI.sel&&((UI.sel.type==='link'&&!S.links.some(l=>l.id===UI.sel.id))||(UI.sel.type==='city'&&!pzKind(UI.sel.id))))UI.sel=null; compute();renderAll();pzCheck();} // Stars count the moment they are earned: a better result than this attempt has had opens the results card. -function pzCheck(){const e=pzEval();if(e.stars<=(UI.pzTop||0))return e;const prev=UI.pzTop||0;UI.pzTop=e.stars;pzRecord(e);pzResults(e,prev);return e;} +// Every solved state is recorded, so a cheaper build at the same stars counts too. +function pzCheck(){const e=pzEval();if(e.stars)pzRecord(e);if(e.stars<=(UI.pzTop||0))return e;const prev=UI.pzTop||0;UI.pzTop=e.stars;pzResults(e,prev);return e;} +// The best spend belongs to the best star count: more stars start it again, the same stars keep the lower spend. function pzRecord(e){const p=pzLoad(),P=S.pz,bag=P.id==='weekly'?p.wk:p.s,k=P.id==='weekly'?P.key:P.id,r=bag[k]||{st:0,sp:null}; - r.st=Math.max(r.st,e.stars);r.sp=r.sp==null?e.spend:Math.min(r.sp,e.spend);bag[k]=r;if(P.id==='weekly')pzStreak(p,P.key);pzStore(p);} + if(e.starsx.id===S.pz.id);for(let j=i+1;j { + const { ev, errors } = load(); + ev("localStorage.removeItem('sot-puzzles');pzBegin(pzDef('braces'))"); + const rec = () => JSON.parse(ev("JSON.stringify(pzLoad().s.braces||null)")); + build(ev, REF.braces.one); + const two = evalP(ev).spend; + assert.deepEqual(rec(), { st: 2, sp: two }); + // A gold-plated third link: N-1 but over budget is still two stars, and dearer, so the best stays. + ev("ACT.pzLinkTo({a:'dub',b:'nyc'});ACT.pzVia({v:'havf'});ACT.pzLink({tier:2});closeModal()"); + assert.equal(evalP(ev).stars, 2); + assert.deepEqual(rec(), { st: 2, sp: two }); + // Shrinking it to 10G earns the third star: the best spend starts again at the 3-star build. + ev('ACT.pzTier({id:S.links[2].id,tier:0})'); + const three = evalP(ev); + assert.equal(three.stars, 3); + assert.deepEqual(rec(), { st: 3, sp: three.spend }); + // With a looser budget, a dearer 3-star build does not replace it; going back to the cheaper one keeps it. + ev('S.pz.budget=1e7;ACT.pzTier({id:S.links[0].id,tier:1})'); + assert.equal(evalP(ev).stars, 3); + assert.deepEqual(rec(), { st: 3, sp: three.spend }); + // A cheaper 3-star build after a dearer first one is recorded (the old code only recorded star rises). + ev("localStorage.removeItem('sot-puzzles')"); + ev('ACT.pzTier({id:S.links[1].id,tier:1})'); + const dear = evalP(ev).spend; + assert.deepEqual(rec(), { st: 3, sp: dear }); + ev('ACT.pzTier({id:S.links[1].id,tier:0});ACT.pzTier({id:S.links[0].id,tier:0})'); + assert.deepEqual(rec(), { st: 3, sp: three.spend }); + // Fewer stars never overwrite more. + ev('ACT.pzRmLink({id:S.links[2].id})'); + assert.deepEqual(rec(), { st: 3, sp: three.spend }); + ev('ACT.puzzleMenu({})'); + assert.ok(ev("document.getElementById('modalCard').textContent").includes('best ' + ev(`fmt$(${three.spend})`))); + assert.deepEqual(errors, []); +});