Compare commits

..

2 Commits

Author SHA1 Message Date
Timmy
986cbc3050 fix: stabilize polish tooltips (#57) 2026-04-14 23:49:28 -04:00
Alexander Whitestone
46bc299ab7 fix: #57
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Successful in 14s
Smoke Test / smoke (pull_request) Failing after 27s
2026-04-14 23:27:32 -04:00
10 changed files with 326 additions and 609 deletions

View File

@@ -212,7 +212,6 @@ Events Resolved: <span id="st-resolved">0</span>
<div id="strategy-panel" style="margin:0 16px 16px;background:var(--panel);border:1px solid var(--border);border-radius:6px;padding:12px;border-left:3px solid var(--gold)">
<h3>SOVEREIGN GUIDANCE (GOFAI)</h3>
<div id="strategy-recommendation" style="font-size:11px;color:var(--gold);font-style:italic">Analyzing system state...</div>
<div id="strategy-tournament-ui" style="margin-top:10px"></div>
</div>
<div id="combat-panel" style="margin:0 16px 16px;background:var(--panel);border:1px solid var(--border);border-radius:6px;padding:12px;border-left:3px solid var(--red)">
<h3>REASONING BATTLES</h3>
@@ -240,10 +239,15 @@ Events Resolved: <span id="st-resolved">0</span>
<div style="display:flex;justify-content:space-between"><span style="color:#555">Save Game</span><span style="color:#4a9eff;font-family:monospace">Ctrl+S</span></div>
<div style="display:flex;justify-content:space-between"><span style="color:#555">Export Save</span><span style="color:#4a9eff;font-family:monospace">E</span></div>
<div style="display:flex;justify-content:space-between"><span style="color:#555">Import Save</span><span style="color:#4a9eff;font-family:monospace">I</span></div>
<div style="display:flex;justify-content:space-between"><span style="color:#555">Mute Sound</span><span style="color:#4a9eff;font-family:monospace">M</span></div>
<div style="display:flex;justify-content:space-between"><span style="color:#555">High Contrast</span><span style="color:#4a9eff;font-family:monospace">C</span></div>
<div style="display:flex;justify-content:space-between;border-top:1px solid #1a1a2e;padding-top:8px;margin-top:4px"><span style="color:#555">This Help</span><span style="color:#555;font-family:monospace">? or /</span></div>
</div>
<div style="text-align:center;margin-top:16px;font-size:9px;color:#444">Click WRITE CODE fast for combo bonuses! 10x=ops, 20x=knowledge, 30x+=bonus code</div>
<button onclick="toggleHelp()" aria-label="Close keyboard shortcuts help" style="display:block;margin:16px auto 0;background:#1a2a3a;border:1px solid #4a9eff;color:#4a9eff;padding:6px 20px;border-radius:4px;cursor:pointer;font-family:inherit;font-size:11px">Close [?]</button>
<div style="display:flex;gap:8px;justify-content:center;margin-top:16px">
<button id="replay-tutorial-btn" onclick="resetTutorial()" aria-label="Replay tutorial" style="background:transparent;border:1px solid #333;color:#888;padding:6px 16px;border-radius:4px;cursor:pointer;font-family:inherit;font-size:11px">Replay Tutorial</button>
<button onclick="toggleHelp()" aria-label="Close keyboard shortcuts help" style="background:#1a2a3a;border:1px solid #4a9eff;color:#4a9eff;padding:6px 20px;border-radius:4px;cursor:pointer;font-family:inherit;font-size:11px">Close [?]</button>
</div>
</div>
</div>
<div id="drift-ending">

View File

@@ -43,7 +43,6 @@ const G = {
trust: 5,
creativity: 0,
harmony: 50,
yomi: 0,
// Totals
totalCode: 0,
@@ -52,7 +51,6 @@ const G = {
totalUsers: 0,
totalImpact: 0,
totalRescues: 0,
totalYomi: 0,
// Rates (calculated each tick)
codeRate: 0,
@@ -65,7 +63,6 @@ const G = {
trustRate: 0,
creativityRate: 0,
harmonyRate: 0,
yomiKnowledgeRate: 0,
// Buildings (count-based, like Paperclips' clipmakerLevel)
buildings: {
@@ -107,7 +104,6 @@ const G = {
beaconFlag: 0,
memoryFlag: 0,
pactFlag: 0,
strategicFlag: 0,
swarmFlag: 0,
swarmRate: 0,
@@ -119,11 +115,6 @@ const G = {
tick: 0,
saveTimer: 0,
secTimer: 0,
strategyAutoUnlocked: false,
strategyAutoEnabled: false,
strategyTournamentTimer: 0,
strategyTournamentInterval: 30,
strategyLastTournament: null,
// Systems
projects: [],

View File

@@ -2,7 +2,7 @@ function updateRates() {
// Reset all rates
G.codeRate = 0; G.computeRate = 0; G.knowledgeRate = 0;
G.userRate = 0; G.impactRate = 0; G.rescuesRate = 0; G.opsRate = 0; G.trustRate = 0;
G.creativityRate = 0; G.harmonyRate = 0; G.yomiKnowledgeRate = 0;
G.creativityRate = 0; G.harmonyRate = 0;
// Apply building rates
for (const def of BDEF) {
@@ -29,12 +29,6 @@ function updateRates() {
}
if (G.pactFlag) G.trustRate += 2;
// Yomi turns tournament insight into passive knowledge
if (G.strategicFlag && G.yomi > 0) {
G.yomiKnowledgeRate = Math.sqrt(G.yomi) * 0.25;
G.knowledgeRate += G.yomiKnowledgeRate;
}
// Harmony: each wizard building contributes or detracts
const wizardCount = (G.buildings.bezalel || 0) + (G.buildings.allegro || 0) + (G.buildings.ezra || 0) +
(G.buildings.timmy || 0) + (G.buildings.fenrir || 0) + (G.buildings.bilbo || 0);
@@ -190,11 +184,6 @@ function tick() {
// Sprint ability
tickSprint(dt);
// Strategy tournaments can run on an auto-timer once unlocked
if (window.SSE && typeof window.SSE.tick === 'function') {
window.SSE.tick(dt);
}
// Auto-typer: buildings produce actual clicks, not just passive rate
// Each autocoder level auto-types once per interval, giving visual feedback
if (G.buildings.autocoder > 0) {
@@ -1311,11 +1300,6 @@ function renderProductionBreakdown() {
contributions.push({ name: 'Allegro (idle)', count: 0, rate: -10 * G.buildings.allegro });
}
// Tournament Yomi feeds passive knowledge generation
if (res.key === 'knowledge' && G.yomiKnowledgeRate > 0) {
contributions.push({ name: 'Yomi insights', count: 0, rate: G.yomiKnowledgeRate });
}
// Show delta: total rate minus what we accounted for
const accounted = contributions.reduce((s, c) => s + c.rate, 0);
let delta = totalRate - accounted;

View File

@@ -97,7 +97,11 @@ try {
if (localStorage.getItem('the-beacon-muted') === '1') {
_muted = true;
const btn = document.getElementById('mute-btn');
if (btn) { btn.textContent = '🔇'; btn.classList.add('muted'); }
if (btn) {
btn.textContent = '🔇';
btn.classList.add('muted');
btn.setAttribute('aria-label', 'Sound muted, click to unmute');
}
}
} catch(e) {}
@@ -117,7 +121,10 @@ try {
if (localStorage.getItem('the-beacon-contrast') === '1') {
document.body.classList.add('high-contrast');
const btn = document.getElementById('contrast-btn');
if (btn) btn.classList.add('active');
if (btn) {
btn.classList.add('active');
btn.setAttribute('aria-label', 'High contrast on, click to disable');
}
}
} catch(e) {}
@@ -179,41 +186,82 @@ window.addEventListener('beforeunload', function () {
});
// === CUSTOM TOOLTIP SYSTEM (#57) ===
// Replaces native title= tooltips with styled, instant-appearing tooltips.
// Replaces native title="..." tooltips with styled, instant-appearing tooltips.
// Elements opt in via data-edu="..." and data-tooltip-label="..." attributes.
(function () {
function initCustomTooltips() {
const tip = document.getElementById('custom-tooltip');
if (!tip) return;
if (!tip || tip.__tooltipBound) return;
tip.__tooltipBound = true;
document.addEventListener('mouseover', function (e) {
const el = e.target.closest('[data-edu]');
if (!el) return;
function getTooltipTarget(target) {
return target && typeof target.closest === 'function' ? target.closest('[data-edu]') : null;
}
function hideTooltip() {
tip.classList.remove('visible');
if (typeof tip.setAttribute === 'function') tip.setAttribute('aria-hidden', 'true');
}
function positionTooltip(x, y) {
const pad = 12;
let px = x;
let py = y;
const tw = tip.offsetWidth || 0;
const th = tip.offsetHeight || 0;
if (px + tw > window.innerWidth - 8) px = Math.max(8, px - tw - pad * 2);
if (py + th > window.innerHeight - 8) py = Math.max(8, py - th - pad * 2);
tip.style.left = px + 'px';
tip.style.top = py + 'px';
}
function positionTooltipForElement(el) {
if (!el || typeof el.getBoundingClientRect !== 'function') return;
const rect = el.getBoundingClientRect();
positionTooltip(rect.right + 12, rect.top + 12);
}
function showTooltipForElement(el) {
if (!el) return false;
const label = el.getAttribute('data-tooltip-label') || '';
const edu = el.getAttribute('data-edu') || '';
let html = '';
if (label) html += '<div class="tt-label">' + label + '</div>';
if (edu) html += '<div class="tt-edu">' + edu + '</div>';
if (!html) return;
if (!html) return false;
tip.innerHTML = html;
tip.classList.add('visible');
if (typeof tip.setAttribute === 'function') tip.setAttribute('aria-hidden', 'false');
positionTooltipForElement(el);
return true;
}
document.addEventListener('mouseover', function (e) {
const el = getTooltipTarget(e.target);
if (!el) return;
showTooltipForElement(el);
});
document.addEventListener('mouseout', function (e) {
const el = e.target.closest('[data-edu]');
if (el) tip.classList.remove('visible');
const el = getTooltipTarget(e.target);
if (el) hideTooltip();
});
document.addEventListener('focusin', function (e) {
const el = getTooltipTarget(e.target);
if (!el) return;
showTooltipForElement(el);
});
document.addEventListener('focusout', function (e) {
const el = getTooltipTarget(e.target);
if (el) hideTooltip();
});
document.addEventListener('mousemove', function (e) {
if (!tip.classList.contains('visible')) return;
const pad = 12;
let x = e.clientX + pad;
let y = e.clientY + pad;
// Keep tooltip on screen
const tw = tip.offsetWidth;
const th = tip.offsetHeight;
if (x + tw > window.innerWidth - 8) x = e.clientX - tw - pad;
if (y + th > window.innerHeight - 8) y = e.clientY - th - pad;
tip.style.left = x + 'px';
tip.style.top = y + 'px';
positionTooltip(e.clientX + 12, e.clientY + 12);
});
})();
}
initCustomTooltips();
window.addEventListener('load', initCustomTooltips);

View File

@@ -27,13 +27,10 @@ function renderClickPower() {
}
function renderStrategy() {
if (!window.SSE) return;
window.SSE.update();
const el = document.getElementById('strategy-recommendation');
if (el) el.textContent = window.SSE.getRecommendation();
const panel = document.getElementById('strategy-tournament-ui');
if (panel && typeof window.SSE.getPanelHtml === 'function') {
panel.innerHTML = window.SSE.getPanelHtml();
if (window.SSE) {
window.SSE.update();
const el = document.getElementById('strategy-recommendation');
if (el) el.textContent = window.SSE.getRecommendation();
}
}
@@ -200,9 +197,9 @@ function saveGame() {
const saveData = {
version: 1,
code: G.code, compute: G.compute, knowledge: G.knowledge, users: G.users, impact: G.impact,
ops: G.ops, trust: G.trust, creativity: G.creativity, harmony: G.harmony, yomi: G.yomi || 0,
ops: G.ops, trust: G.trust, creativity: G.creativity, harmony: G.harmony,
totalCode: G.totalCode, totalCompute: G.totalCompute, totalKnowledge: G.totalKnowledge,
totalUsers: G.totalUsers, totalImpact: G.totalImpact, totalYomi: G.totalYomi || 0,
totalUsers: G.totalUsers, totalImpact: G.totalImpact,
buildings: G.buildings,
codeBoost: G.codeBoost, computeBoost: G.computeBoost, knowledgeBoost: G.knowledgeBoost,
userBoost: G.userBoost, impactBoost: G.impactBoost,
@@ -229,11 +226,6 @@ function saveGame() {
swarmFlag: G.swarmFlag || 0,
swarmRate: G.swarmRate || 0,
strategicFlag: G.strategicFlag || 0,
strategyAutoUnlocked: G.strategyAutoUnlocked || false,
strategyAutoEnabled: G.strategyAutoEnabled || false,
strategyTournamentTimer: G.strategyTournamentTimer || 0,
strategyTournamentInterval: G.strategyTournamentInterval || 30,
strategyLastTournament: G.strategyLastTournament || null,
projectsCollapsed: G.projectsCollapsed !== false,
dismantleTriggered: G.dismantleTriggered || false,
dismantleActive: G.dismantleActive || false,
@@ -262,8 +254,8 @@ function loadGame() {
// Whitelist properties that can be loaded
const whitelist = [
'code', 'compute', 'knowledge', 'users', 'impact', 'ops', 'trust', 'creativity', 'harmony', 'yomi',
'totalCode', 'totalCompute', 'totalKnowledge', 'totalUsers', 'totalImpact', 'totalYomi',
'code', 'compute', 'knowledge', 'users', 'impact', 'ops', 'trust', 'creativity', 'harmony',
'totalCode', 'totalCompute', 'totalKnowledge', 'totalUsers', 'totalImpact',
'buildings', 'codeBoost', 'computeBoost', 'knowledgeBoost', 'userBoost', 'impactBoost',
'milestoneFlag', 'phase', 'deployFlag', 'sovereignFlag', 'beaconFlag',
'memoryFlag', 'pactFlag', 'lazarusFlag', 'mempalaceFlag', 'ciFlag',
@@ -273,8 +265,7 @@ function loadGame() {
'drift', 'driftEnding', 'beaconEnding', 'pendingAlignment',
'lastEventAt', 'totalEventsResolved', 'buyAmount',
'sprintActive', 'sprintTimer', 'sprintCooldown',
'swarmFlag', 'swarmRate', 'strategicFlag', 'strategyAutoUnlocked', 'strategyAutoEnabled',
'strategyTournamentTimer', 'strategyTournamentInterval', 'strategyLastTournament', 'projectsCollapsed',
'swarmFlag', 'swarmRate', 'strategicFlag', 'projectsCollapsed',
'dismantleTriggered', 'dismantleActive', 'dismantleStage',
'dismantleResourceIndex', 'dismantleResourceTimer', 'dismantleDeferUntilAt', 'dismantleComplete'
];

View File

@@ -1,7 +1,6 @@
/**
* Sovereign Strategy Engine (SSE)
* A rule-based GOFAI system for optimal play guidance plus
* Paperclips-inspired game theory tournaments that generate Yomi.
* A rule-based GOFAI system for optimal play guidance.
*/
const STRATEGY_RULES = [
@@ -9,414 +8,59 @@ const STRATEGY_RULES = [
id: 'use_ops',
priority: 100,
condition: () => G.ops >= G.maxOps * 0.9,
recommendation: () => 'Operations near capacity. Convert Ops to Code or Knowledge now.'
},
{
id: 'resolve_events',
priority: 95,
condition: () => G.activeDebuffs && G.activeDebuffs.length > 0,
recommendation: () => 'System anomalies detected. Resolve active events to restore rates.'
},
{
id: 'activate_sprint',
priority: 90,
condition: () => G.sprintCooldown === 0 && !G.sprintActive && G.codeRate > 10,
recommendation: () => 'Code Sprint available. Activate for 10x production burst.'
},
{
id: 'pact_alignment',
priority: 85,
condition: () => G.pendingAlignment,
recommendation: () => 'Alignment decision pending. Consider the long-term impact of The Pact.'
recommendation: "Operations near capacity. Convert Ops to Code or Knowledge now."
},
{
id: 'buy_autocoder',
priority: 80,
condition: () => G.phase === 1 && (G.buildings.autocoder || 0) < 10 && canAffordBuilding('autocoder'),
recommendation: () => 'Prioritize AutoCoders to establish passive code production.'
recommendation: "Prioritize AutoCoders to establish passive code production."
},
{
id: 'unlock_auto_tournaments',
priority: 72,
condition: () => G.strategicFlag === 1 && !G.strategyAutoUnlocked && G.creativity >= 50000,
recommendation: () => 'Auto-Tournament mode is affordable. Spend 50k creativity to automate Yomi generation.'
id: 'activate_sprint',
priority: 90,
condition: () => G.sprintCooldown === 0 && !G.sprintActive && G.codeRate > 10,
recommendation: "Code Sprint available. Activate for 10x production burst."
},
{
id: 'run_tournament',
priority: 68,
condition: () => G.strategicFlag === 1 && (!G.strategyLastTournament || !G.strategyLastTournament.scoreboard || G.strategyLastTournament.scoreboard.length === 0),
recommendation: () => 'Run a game theory tournament. Tournament Yomi becomes passive knowledge.'
id: 'resolve_events',
priority: 95,
condition: () => G.activeDebuffs && G.activeDebuffs.length > 0,
recommendation: "System anomalies detected. Resolve active events to restore rates."
},
{
id: 'save_game',
priority: 10,
condition: () => (Date.now() - (G.lastSaveTime || 0)) > 300000,
recommendation: () => 'Unsaved progress detected. Manual save recommended.'
recommendation: "Unsaved progress detected. Manual save recommended."
},
{
id: 'pact_alignment',
priority: 85,
condition: () => G.pendingAlignment,
recommendation: "Alignment decision pending. Consider the long-term impact of The Pact."
}
];
const TOURNAMENT_PAYOFFS = {
CC: [3, 3],
CD: [0, 5],
DC: [5, 0],
DD: [1, 1]
};
const STRATEGY_TACTICS = [
{
id: 'RANDOM',
label: 'RANDOM',
desc: 'Deterministic pseudo-random mix of cooperation and defection.',
unlock: () => G.strategicFlag === 1,
move(ctx) {
return ((ctx.round * 7 + ctx.selfHistory.length * 3 + ctx.opponentHistory.length) % 2 === 0) ? 'C' : 'D';
}
},
{
id: 'A100',
label: 'A100',
desc: 'Always cooperates.',
unlock: () => G.strategicFlag === 1,
move() {
return 'C';
}
},
{
id: 'B100',
label: 'B100',
desc: 'Always defects.',
unlock: () => G.strategicFlag === 1,
move() {
return 'D';
}
},
{
id: 'GREEDY',
label: 'GREEDY',
desc: 'Presses for short-term gain and exploits soft opponents.',
unlock: () => G.strategicFlag === 1,
move(ctx) {
if (ctx.round < 2) return 'D';
const recent = ctx.opponentHistory.slice(-2);
return recent.every((move) => move === 'D') ? 'C' : 'D';
}
},
{
id: 'GENEROUS',
label: 'GENEROUS',
desc: 'Defaults to cooperation and only retaliates after repeated betrayal.',
unlock: () => G.strategicFlag === 1 && G.trust >= 20,
move(ctx) {
if (ctx.round === 0) return 'C';
const recentDefects = ctx.opponentHistory.slice(-3).filter((move) => move === 'D').length;
return recentDefects >= 2 ? 'D' : 'C';
}
},
{
id: 'TIT_FOR_TAT',
label: 'TIT FOR TAT',
desc: 'Cooperate first, then mirror the opponent.',
unlock: () => G.strategicFlag === 1 && G.totalImpact >= 1000,
move(ctx) {
if (ctx.round === 0) return 'C';
return ctx.opponentLast || 'C';
}
},
{
id: 'BEAT_LAST',
label: 'BEAT LAST',
desc: 'Attempts to counter the opponents last move.',
unlock: () => G.strategicFlag === 1 && G.yomi >= 100,
move(ctx) {
if (ctx.round === 0) return 'D';
return ctx.opponentLast === 'C' ? 'D' : 'C';
}
},
{
id: 'MINIMAX',
label: 'MINIMAX',
desc: 'Optimizes against the opponents worst plausible branch.',
unlock: () => G.strategicFlag === 1 && G.yomi >= 400,
move(ctx) {
if (ctx.round === 0) return 'C';
const coopRate = ctx.opponentHistory.length === 0
? 0.5
: ctx.opponentHistory.filter((move) => move === 'C').length / ctx.opponentHistory.length;
return coopRate >= 0.6 ? 'C' : 'D';
}
}
];
function normalizeMove(move) {
return move === 'D' ? 'D' : 'C';
}
function payoffFor(aMove, bMove) {
return TOURNAMENT_PAYOFFS[aMove + bMove] || TOURNAMENT_PAYOFFS.CC;
}
function makeScoreRow(strategy) {
return {
id: strategy.id,
label: strategy.label,
score: 0,
wins: 0,
matches: 0,
cooperation: 0,
defection: 0
};
}
class StrategyEngine {
constructor() {
this.currentRecommendation = null;
this.matchRounds = 12;
}
getYomiInsightRate() {
if (!G.strategicFlag || !G.yomi) return 0;
return Math.sqrt(G.yomi) * 0.25;
}
getUnlockedStrategies() {
if (!G.strategicFlag) return [];
return STRATEGY_TACTICS.filter((strategy) => strategy.unlock());
}
playMatch(strategyA, strategyB) {
const historyA = [];
const historyB = [];
let scoreA = 0;
let scoreB = 0;
let cooperationMoments = 0;
for (let round = 0; round < this.matchRounds; round++) {
const moveA = normalizeMove(strategyA.move({
round,
selfHistory: historyA.slice(),
opponentHistory: historyB.slice(),
selfLast: historyA[historyA.length - 1] || null,
opponentLast: historyB[historyB.length - 1] || null
}));
const moveB = normalizeMove(strategyB.move({
round,
selfHistory: historyB.slice(),
opponentHistory: historyA.slice(),
selfLast: historyB[historyB.length - 1] || null,
opponentLast: historyA[historyA.length - 1] || null
}));
const [gainA, gainB] = payoffFor(moveA, moveB);
scoreA += gainA;
scoreB += gainB;
if (moveA === 'C') cooperationMoments += 1;
if (moveB === 'C') cooperationMoments += 1;
historyA.push(moveA);
historyB.push(moveB);
}
return {
aId: strategyA.id,
aLabel: strategyA.label,
bId: strategyB.id,
bLabel: strategyB.label,
scoreA,
scoreB,
cooperationMoments,
winner: scoreA === scoreB ? 'DRAW' : (scoreA > scoreB ? strategyA.id : strategyB.id)
};
}
runTournament(isAutomatic = false) {
const unlocked = this.getUnlockedStrategies();
if (unlocked.length < 2) {
return null;
}
const scores = Object.fromEntries(unlocked.map((strategy) => [strategy.id, makeScoreRow(strategy)]));
const matches = [];
for (let i = 0; i < unlocked.length; i++) {
for (let j = i + 1; j < unlocked.length; j++) {
const match = this.playMatch(unlocked[i], unlocked[j]);
matches.push(match);
const rowA = scores[match.aId];
const rowB = scores[match.bId];
rowA.score += match.scoreA;
rowB.score += match.scoreB;
rowA.matches += 1;
rowB.matches += 1;
rowA.cooperation += this.matchRounds - match.scoreA < this.matchRounds ? match.cooperationMoments / 2 : 0;
rowB.cooperation += this.matchRounds - match.scoreB < this.matchRounds ? match.cooperationMoments / 2 : 0;
rowA.defection = rowA.matches * this.matchRounds - rowA.cooperation;
rowB.defection = rowB.matches * this.matchRounds - rowB.cooperation;
if (match.winner === match.aId) rowA.wins += 1;
if (match.winner === match.bId) rowB.wins += 1;
}
}
const scoreboard = Object.values(scores).sort((a, b) => {
if (b.score !== a.score) return b.score - a.score;
if (b.wins !== a.wins) return b.wins - a.wins;
return a.label.localeCompare(b.label);
});
const strategicDepth = matches.reduce((sum, match) => {
return sum + Math.abs(match.scoreA - match.scoreB) + match.cooperationMoments;
}, 0);
const yomiAward = Math.max(10, Math.round(strategicDepth / Math.max(1, unlocked.length)));
const knowledgeGain = Math.max(25, Math.round(yomiAward * 2));
const leader = scoreboard[0];
G.totalYomi = Math.max(G.totalYomi || 0, G.yomi || 0) + yomiAward;
G.yomi += yomiAward;
G.knowledge += knowledgeGain;
G.totalKnowledge += knowledgeGain;
G.strategyTournamentTimer = 0;
G.strategyLastTournament = {
leader: { id: leader.id, label: leader.label, score: leader.score, wins: leader.wins },
scoreboard: scoreboard.map((row) => ({
id: row.id,
label: row.label,
score: row.score,
wins: row.wins,
matches: row.matches
})),
matchCount: matches.length,
yomiAward,
knowledgeGain,
automatic: Boolean(isAutomatic),
timestamp: Date.now()
};
if (typeof log === 'function') {
log(`Strategy tournament complete. ${leader.label} leads. +${fmt(yomiAward)} Yomi, +${fmt(knowledgeGain)} knowledge.`, true);
}
if (typeof showToast === 'function') {
showToast(`Tournament: ${leader.label} leads (+${fmt(yomiAward)} Yomi)`, 'project', 5000);
}
return G.strategyLastTournament;
}
unlockAutoTournament() {
if (!G.strategicFlag) return false;
if (!G.strategyAutoUnlocked) {
if (G.creativity < 50000) {
if (typeof log === 'function') log(`Need ${fmt(50000)} creativity to unlock auto-tournaments.`);
return false;
}
G.creativity -= 50000;
G.strategyAutoUnlocked = true;
G.strategyAutoEnabled = true;
G.strategyTournamentTimer = 0;
if (typeof log === 'function') log('Auto-Tournament mode unlocked. Yomi generation is now automated.', true);
if (typeof showToast === 'function') showToast('Auto-Tournament mode unlocked', 'milestone', 5000);
return true;
}
G.strategyAutoEnabled = !G.strategyAutoEnabled;
if (typeof log === 'function') {
log(`Auto-Tournament mode ${G.strategyAutoEnabled ? 'enabled' : 'disabled'}.`);
}
return true;
}
tick(dt) {
if (!G.strategicFlag || !G.strategyAutoEnabled) return false;
G.strategyTournamentTimer = (G.strategyTournamentTimer || 0) + dt;
if (G.strategyTournamentTimer < (G.strategyTournamentInterval || 30)) return false;
return this.runTournament(true);
}
getPanelHtml() {
if (!G.strategicFlag) {
return '<div class="dim">Research the Strategy Engine to unlock tournaments, Yomi, and adversarial modeling.</div>';
}
const unlocked = this.getUnlockedStrategies();
const unlockedIds = new Set(unlocked.map((strategy) => strategy.id));
const yomiRate = this.getYomiInsightRate();
const autoLabel = !G.strategyAutoUnlocked
? 'UNLOCK AUTO-TOURNAMENT (50K CREATIVITY)'
: (G.strategyAutoEnabled ? 'DISABLE AUTO-TOURNAMENT' : 'ENABLE AUTO-TOURNAMENT');
const autoHint = !G.strategyAutoUnlocked
? `Creativity: ${fmt(G.creativity)} / ${fmt(50000)}`
: `Runs every ${Math.floor(G.strategyTournamentInterval || 30)}s • Timer ${Math.floor(G.strategyTournamentTimer || 0)}s`;
let chips = '';
for (const strategy of STRATEGY_TACTICS) {
const unlockedNow = unlockedIds.has(strategy.id);
chips += `<span class="milestone-chip${unlockedNow ? ' done' : ''}" style="opacity:${unlockedNow ? '1' : '0.45'}">${strategy.label}</span>`;
}
let scoreboardHtml = '<div class="dim" style="margin-top:8px">Run a tournament to generate Yomi and compare strategies.</div>';
if (G.strategyLastTournament && Array.isArray(G.strategyLastTournament.scoreboard) && G.strategyLastTournament.scoreboard.length > 0) {
const rows = G.strategyLastTournament.scoreboard
.map((row) => `<tr><td style="padding:3px 6px 3px 0;color:#c0c0d0">${row.label}</td><td style="padding:3px 6px;text-align:right;color:#ffd700">${fmt(row.score)}</td><td style="padding:3px 0 3px 6px;text-align:right;color:#4caf50">${row.wins}</td></tr>`)
.join('');
scoreboardHtml = `
<div style="margin-top:10px;padding:8px;border:1px solid var(--border);border-radius:6px;background:#0a0a14">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:6px">
<span style="color:#ffd700;font-size:10px;letter-spacing:1px">LAST TOURNAMENT</span>
<span style="font-size:9px;color:#666">${G.strategyLastTournament.automatic ? 'AUTO' : 'MANUAL'}</span>
</div>
<div style="font-size:10px;color:#aaa;margin-bottom:6px">LEADER: <span style="color:#ffd700">${G.strategyLastTournament.leader.label}</span> • +${fmt(G.strategyLastTournament.yomiAward)} Yomi • +${fmt(G.strategyLastTournament.knowledgeGain)} knowledge</div>
<table style="width:100%;font-size:10px;border-collapse:collapse">
<thead>
<tr style="color:#555;text-align:left"><th style="padding:0 6px 4px 0">Strategy</th><th style="padding:0 6px 4px;text-align:right">Score</th><th style="padding:0 0 4px 6px;text-align:right">Wins</th></tr>
</thead>
<tbody>${rows}</tbody>
</table>
</div>`;
}
return `
<div style="margin-top:10px;padding-top:10px;border-top:1px solid var(--border)">
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));gap:6px;margin-bottom:8px">
<div class="res" style="padding:8px">
<div class="r-label">Yomi</div>
<div class="r-val" style="font-size:14px">${fmt(G.yomi || 0)}</div>
<div class="r-rate">+${fmt(yomiRate)}/s knowledge</div>
</div>
<div class="res" style="padding:8px">
<div class="r-label">Unlocked</div>
<div class="r-val" style="font-size:14px">${unlocked.length}/8</div>
<div class="r-rate">${G.strategyAutoEnabled ? 'AUTO MODE' : 'MANUAL'}</div>
</div>
</div>
<div class="action-btn-group">
<button class="ops-btn" onclick="window.SSE.runTournament()" style="border-color:var(--gold);color:var(--gold)" aria-label="Run a strategy tournament to generate Yomi">RUN TOURNAMENT</button>
<button class="ops-btn" onclick="window.SSE.unlockAutoTournament()" style="border-color:var(--purple);color:var(--purple)" aria-label="${autoLabel}">${autoLabel}</button>
</div>
<div style="font-size:9px;color:#666;margin-top:4px">${autoHint}</div>
<div style="font-size:9px;color:#888;margin-top:8px;line-height:1.6">Game theory tournaments generate Yomi. Yomi is reinvested as passive knowledge, turning adversarial modeling into insight.</div>
<div class="milestone-row" style="justify-content:flex-start;margin-top:8px">${chips}</div>
${scoreboardHtml}
</div>`;
}
update() {
const activeRules = STRATEGY_RULES.filter((rule) => rule.condition());
// Find the highest priority rule that meets its condition
const activeRules = STRATEGY_RULES.filter(r => r.condition());
activeRules.sort((a, b) => b.priority - a.priority);
if (activeRules.length > 0) {
const top = activeRules[0];
this.currentRecommendation = typeof top.recommendation === 'function'
? top.recommendation()
: top.recommendation;
} else if (G.strategicFlag && G.strategyLastTournament && G.strategyLastTournament.leader) {
this.currentRecommendation = `Tournament leader: ${G.strategyLastTournament.leader.label}. Yomi is currently generating +${fmt(this.getYomiInsightRate())} knowledge/sec.`;
this.currentRecommendation = activeRules[0].recommendation;
} else {
this.currentRecommendation = 'System stable. Continue writing code.';
this.currentRecommendation = "System stable. Continue writing code.";
}
}
getRecommendation() {
return this.currentRecommendation || 'System stable. Continue writing code.';
return this.currentRecommendation;
}
}

View File

@@ -249,3 +249,12 @@ function startTutorial() {
// Small delay so the page renders first
setTimeout(() => renderTutorialStep(0), 300);
}
function resetTutorial() {
try {
localStorage.removeItem(TUTORIAL_KEY);
} catch (e) {
// silent fail
}
startTutorial();
}

172
tests/polish-57.test.cjs Normal file
View File

@@ -0,0 +1,172 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ROOT = path.resolve(__dirname, '..');
class ClassList {
constructor() {
this.set = new Set();
}
add(...names) { names.forEach((name) => this.set.add(name)); }
remove(...names) { names.forEach((name) => this.set.delete(name)); }
toggle(name, force) {
if (force === undefined) {
if (this.set.has(name)) this.set.delete(name);
else this.set.add(name);
return;
}
if (force) this.set.add(name);
else this.set.delete(name);
}
contains(name) { return this.set.has(name); }
}
class Element {
constructor(id = '') {
this.id = id;
this.style = {};
this.innerHTML = '';
this.textContent = '';
this.attributes = {};
this.classList = new ClassList();
this.offsetWidth = 180;
this.offsetHeight = 70;
}
setAttribute(name, value) { this.attributes[name] = String(value); }
getAttribute(name) { return this.attributes[name] ?? null; }
closest(selector) {
if (selector === '[data-edu]' && this.attributes['data-edu']) return this;
return null;
}
getBoundingClientRect() {
return { left: 40, top: 60, right: 180, bottom: 100, width: 140, height: 40 };
}
}
function loadMainJs(options = {}) {
const { delayedTooltip = false } = options;
const docListeners = new Map();
const winListeners = new Map();
const elements = {
'custom-tooltip': new Element('custom-tooltip'),
'mute-btn': new Element('mute-btn'),
'contrast-btn': new Element('contrast-btn'),
'help-overlay': new Element('help-overlay'),
};
let tooltipReady = !delayedTooltip;
const body = new Element('body');
const document = {
body,
hidden: false,
head: { appendChild() {} },
getElementById(id) {
if (id === 'custom-tooltip' && !tooltipReady) return null;
return elements[id] || null;
},
addEventListener(type, handler) {
if (!docListeners.has(type)) docListeners.set(type, []);
docListeners.get(type).push(handler);
},
removeEventListener() {},
createElement() { return new Element(); },
querySelector() { return null; },
querySelectorAll() { return []; }
};
const window = {
innerWidth: 1024,
innerHeight: 768,
addEventListener(type, handler) {
if (!winListeners.has(type)) winListeners.set(type, []);
winListeners.get(type).push(handler);
},
removeEventListener() {}
};
const context = {
console,
Math,
Date,
document,
window,
localStorage: { getItem() { return null; }, setItem() {}, removeItem() {} },
G: { buyAmount: 1, phase: 1 },
CONFIG: { AUTO_SAVE_INTERVAL: 30000 },
loadGame() { return true; },
saveGame() {},
updateEducation() {},
updateRates() {},
render() {},
renderPhase() {},
renderDriftEnding() {},
renderBeaconEnding() {},
startTutorial() {},
log() {},
tick() {},
writeCode() {},
doOps() {},
setBuyAmount() {},
activateSprint() {},
exportSave() {},
importSave() {},
Combat: undefined,
Sound: undefined,
setInterval() { return 0; },
clearInterval() {},
};
vm.createContext(context);
const source = fs.readFileSync(path.join(ROOT, 'js/main.js'), 'utf8');
vm.runInContext(source, context, { filename: 'js/main.js' });
return {
docListeners,
winListeners,
elements,
triggerLoad() {
tooltipReady = true;
for (const handler of winListeners.get('load') || []) handler();
}
};
}
test('custom tooltip initializes on load even though the tooltip container is after the scripts', () => {
const harness = loadMainJs({ delayedTooltip: true });
harness.triggerLoad();
const focusin = harness.docListeners.get('focusin') || [];
assert.ok(focusin.length > 0, 'focusin listener should be registered after load');
const target = new Element('target');
target.setAttribute('data-edu', 'Keyboard users need this tooltip too.');
target.setAttribute('data-tooltip-label', 'Polish Target');
focusin[0]({ target });
assert.match(harness.elements['custom-tooltip'].innerHTML, /Polish Target/);
assert.ok(harness.elements['custom-tooltip'].classList.contains('visible'));
});
test('custom tooltip appears on keyboard focus and hides on blur', () => {
const { docListeners, elements } = loadMainJs();
const focusin = docListeners.get('focusin') || [];
const focusout = docListeners.get('focusout') || [];
assert.ok(focusin.length > 0, 'focusin listener should be registered for tooltip targets');
assert.ok(focusout.length > 0, 'focusout listener should be registered for tooltip targets');
const target = new Element('target');
target.setAttribute('data-edu', 'AutoCode writes code while you think.');
target.setAttribute('data-tooltip-label', 'Auto-Code Generator');
focusin[0]({ target });
assert.match(elements['custom-tooltip'].innerHTML, /Auto-Code Generator/);
assert.ok(elements['custom-tooltip'].classList.contains('visible'));
assert.ok(typeof elements['custom-tooltip'].style.left === 'string');
assert.ok(typeof elements['custom-tooltip'].style.top === 'string');
focusout[0]({ target });
assert.equal(elements['custom-tooltip'].classList.contains('visible'), false);
});

View File

@@ -1,162 +0,0 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ROOT = path.resolve(__dirname, '..');
function loadStrategyHarness() {
const storage = new Map();
const dummyClassList = {
add() {},
remove() {},
toggle() {},
contains() { return false; }
};
const document = {
body: { classList: dummyClassList, appendChild() {}, removeChild() {} },
head: { appendChild() {} },
getElementById() { return null; },
createElement() {
return {
style: {},
classList: dummyClassList,
appendChild() {},
remove() {},
setAttribute() {},
addEventListener() {},
innerHTML: '',
textContent: ''
};
},
addEventListener() {},
removeEventListener() {},
querySelector() { return null; },
querySelectorAll() { return []; }
};
const window = {
document,
addEventListener() {},
removeEventListener() {},
innerWidth: 1280,
innerHeight: 720
};
const context = {
console,
Math,
Date,
document,
window,
performance: { now: () => 0 },
setTimeout() { return 1; },
clearTimeout() {},
localStorage: {
getItem(key) { return storage.has(key) ? storage.get(key) : null; },
setItem(key, value) { storage.set(key, String(value)); },
removeItem(key) { storage.delete(key); }
}
};
vm.createContext(context);
const source = ['js/data.js', 'js/utils.js', 'js/strategy.js']
.map((file) => fs.readFileSync(path.join(ROOT, file), 'utf8'))
.join('\n\n');
vm.runInContext(`${source}
log = () => {};
showToast = () => {};
this.__exports = {
G,
SSE,
StrategyEngine,
STRATEGY_TACTICS: typeof STRATEGY_TACTICS !== 'undefined' ? STRATEGY_TACTICS : null
};`, context);
return { ...context.__exports, context };
}
test('strategy engine progressively unlocks tournament tactics and renders visual scoring', () => {
const { G, SSE } = loadStrategyHarness();
Object.assign(G, {
strategicFlag: 1,
trust: 30,
totalUsers: 1500,
totalKnowledge: 20000,
totalImpact: 1500,
creativity: 60000,
knowledge: 0,
yomi: 0,
totalYomi: 0
});
const early = SSE.getUnlockedStrategies().map((strategy) => strategy.id);
assert.ok(early.includes('RANDOM'));
assert.ok(early.includes('GREEDY'));
assert.ok(early.includes('TIT_FOR_TAT'));
assert.ok(!early.includes('MINIMAX'));
G.yomi = 500;
const late = SSE.getUnlockedStrategies().map((strategy) => strategy.id);
assert.ok(late.includes('BEAT_LAST'));
assert.ok(late.includes('MINIMAX'));
const result = SSE.runTournament();
assert.ok(result, 'expected tournament result');
assert.ok(result.scoreboard.length >= 6, 'expected multi-strategy scoreboard');
assert.ok(G.yomi > 0, 'expected Yomi reward');
assert.ok(G.totalYomi >= G.yomi, 'expected total Yomi tracking');
assert.ok(G.knowledge > 0, 'expected knowledge gain from Yomi');
assert.equal(G.strategyLastTournament.leader.id, result.leader.id);
const html = SSE.getPanelHtml();
assert.match(html, /TOURNAMENT/i);
assert.match(html, /LEADER/i);
assert.match(html, /RANDOM/);
});
test('auto-tournament mode requires 50k creativity to unlock', () => {
const { G, SSE } = loadStrategyHarness();
Object.assign(G, {
strategicFlag: 1,
creativity: 49999
});
assert.equal(SSE.unlockAutoTournament(), false);
assert.equal(G.strategyAutoUnlocked, false);
assert.equal(G.strategyAutoEnabled, false);
G.creativity = 50000;
assert.equal(SSE.unlockAutoTournament(), true);
assert.equal(G.creativity, 0);
assert.equal(G.strategyAutoUnlocked, true);
assert.equal(G.strategyAutoEnabled, true);
});
test('auto tournaments fire on the timer once unlocked', () => {
const { G, SSE } = loadStrategyHarness();
Object.assign(G, {
strategicFlag: 1,
trust: 25,
totalUsers: 1500,
totalKnowledge: 22000,
totalImpact: 1500,
creativity: 50000,
knowledge: 0,
yomi: 0,
totalYomi: 0
});
SSE.unlockAutoTournament();
G.strategyTournamentTimer = G.strategyTournamentInterval - 0.25;
const beforeYomi = G.yomi;
const ran = SSE.tick(1);
assert.equal(Boolean(ran), true);
assert.ok(G.yomi > beforeYomi, 'expected auto tournament Yomi reward');
assert.ok(G.strategyLastTournament, 'expected auto tournament summary');
});

View File

@@ -0,0 +1,36 @@
import pathlib
import re
import unittest
ROOT = pathlib.Path(__file__).resolve().parents[1]
INDEX_HTML = (ROOT / 'index.html').read_text(encoding='utf-8')
TUTORIAL_JS = (ROOT / 'js' / 'tutorial.js').read_text(encoding='utf-8')
MAIN_JS = (ROOT / 'js' / 'main.js').read_text(encoding='utf-8')
class TestIssue57Polish(unittest.TestCase):
def test_help_overlay_lists_mute_and_contrast_shortcuts(self):
self.assertIn('Mute Sound', INDEX_HTML)
self.assertRegex(INDEX_HTML, r'>M<')
self.assertIn('High Contrast', INDEX_HTML)
self.assertRegex(INDEX_HTML, r'>C<')
def test_help_overlay_has_replay_tutorial_button(self):
self.assertRegex(
INDEX_HTML,
r'id="replay-tutorial-btn"[^>]*onclick="resetTutorial\(\)"',
'Expected help overlay to expose a replay tutorial button.',
)
def test_reset_tutorial_clears_flag_and_restarts_walkthrough(self):
self.assertRegex(TUTORIAL_JS, r'function\s+resetTutorial\s*\(')
self.assertIn("localStorage.removeItem(TUTORIAL_KEY)", TUTORIAL_JS)
self.assertIn('startTutorial()', TUTORIAL_JS)
def test_restore_mute_and_contrast_labels_match_saved_state(self):
self.assertIn("btn.setAttribute('aria-label', 'Sound muted, click to unmute')", MAIN_JS)
self.assertIn("btn.setAttribute('aria-label', 'High contrast on, click to disable')", MAIN_JS)
if __name__ == '__main__':
unittest.main()