'use strict'; const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const { makeGame, fillColumn, GameCore } = require('./helpers.js'); describe('Column fill warning (t1123)', () => { it('pulses at 10 grounded rows (at least 70% of 13) and not at 9', () => { assert.equal(GameCore.COLUMN_WARN_ROWS, 10); const g = makeGame({ noSpawn: true }); fillColumn(g, 0, 9); assert.equal(g.groundedCount(0), 9); assert.equal(g.columnNeedsWarn(0), false); g.place(0, 9, 0); assert.equal(g.groundedCount(0), 10); assert.equal(g.columnNeedsWarn(0), true); fillColumn(g, 3, 13); assert.equal(g.columnNeedsWarn(3), true); }); it('flying, falling and manual blocks do not count; settling and locked do', () => { const g = makeGame({ noSpawn: true }); fillColumn(g, 2, 9); const flying = g.createBlock(2, 10, 1, 'flying'); const falling = g.createBlock(2, 11, 2, 'falling'); assert.equal(g.columnNeedsWarn(2), false, 'airborne must not trip the warning'); flying.state = 'still'; falling.state = 'still'; // now 11 still — but flying was at y=10, falling at 11, plus 9 = 11 assert.equal(g.columnNeedsWarn(2), true); }); it('warnColumnsFromSnapshot agrees with the live field and ignores flying', () => { const g = makeGame({ noSpawn: true }); fillColumn(g, 1, 10); g.createBlock(1, 11, 0, 'flying'); g.createBlock(4, 0, 1, 'falling'); const flags = GameCore.warnColumnsFromSnapshot(g.fieldSnapshot()); assert.equal(flags[1], true); assert.equal(flags[4], false); assert.equal(flags[0], false); }); it('columnWarnPulse is a sine in a cheap 0.16–0.44 alpha band', () => { const mid = GameCore.columnWarnPulse(0); // sin(0) = 0 → mid 0.30 const peak = GameCore.columnWarnPulse(0.25 / 0.55); const trough = GameCore.columnWarnPulse(0.75 / 0.55); for (const v of [mid, peak, trough]) { assert.ok(v >= 0.16 - 1e-9 && v <= 0.44 + 1e-9, 'pulse=' + v); } assert.ok(peak > mid && mid > trough, 'peak=' + peak + ' mid=' + mid + ' trough=' + trough); assert.ok(Math.abs(peak - 0.44) < 1e-9, 'peak=' + peak); assert.ok(Math.abs(trough - 0.16) < 1e-9, 'trough=' + trough); }); });