| 1 | 'use strict'; |
| 2 | |
| 3 | const { describe, it } = require('node:test'); |
| 4 | const assert = require('node:assert/strict'); |
| 5 | const { makeGame, fillColumn, GameCore } = require('./helpers.js'); |
| 6 | |
| 7 | describe('Column fill warning (t1123)', () => |
| 8 | { |
| 9 | it('pulses at 10 grounded rows (at least 70% of 13) and not at 9', () => |
| 10 | { |
| 11 | assert.equal(GameCore.COLUMN_WARN_ROWS, 10); |
| 12 | const g = makeGame({ noSpawn: true }); |
| 13 | fillColumn(g, 0, 9); |
| 14 | assert.equal(g.groundedCount(0), 9); |
| 15 | assert.equal(g.columnNeedsWarn(0), false); |
| 16 | g.place(0, 9, 0); |
| 17 | assert.equal(g.groundedCount(0), 10); |
| 18 | assert.equal(g.columnNeedsWarn(0), true); |
| 19 | fillColumn(g, 3, 13); |
| 20 | assert.equal(g.columnNeedsWarn(3), true); |
| 21 | }); |
| 22 | |
| 23 | it('flying, falling and manual blocks do not count; settling and locked do', () => |
| 24 | { |
| 25 | const g = makeGame({ noSpawn: true }); |
| 26 | fillColumn(g, 2, 9); |
| 27 | const flying = g.createBlock(2, 10, 1, 'flying'); |
| 28 | const falling = g.createBlock(2, 11, 2, 'falling'); |
| 29 | assert.equal(g.columnNeedsWarn(2), false, 'airborne must not trip the warning'); |
| 30 | flying.state = 'still'; |
| 31 | falling.state = 'still'; |
| 32 | // now 11 still — but flying was at y=10, falling at 11, plus 9 = 11 |
| 33 | assert.equal(g.columnNeedsWarn(2), true); |
| 34 | }); |
| 35 | |
| 36 | it('warnColumnsFromSnapshot agrees with the live field and ignores flying', () => |
| 37 | { |
| 38 | const g = makeGame({ noSpawn: true }); |
| 39 | fillColumn(g, 1, 10); |
| 40 | g.createBlock(1, 11, 0, 'flying'); |
| 41 | g.createBlock(4, 0, 1, 'falling'); |
| 42 | const flags = GameCore.warnColumnsFromSnapshot(g.fieldSnapshot()); |
| 43 | assert.equal(flags[1], true); |
| 44 | assert.equal(flags[4], false); |
| 45 | assert.equal(flags[0], false); |
| 46 | }); |
| 47 | |
| 48 | it('columnWarnPulse is a sine in a cheap 0.16–0.44 alpha band', () => |
| 49 | { |
| 50 | const mid = GameCore.columnWarnPulse(0); // sin(0) = 0 → mid 0.30 |
| 51 | const peak = GameCore.columnWarnPulse(0.25 / 0.55); |
| 52 | const trough = GameCore.columnWarnPulse(0.75 / 0.55); |
| 53 | for (const v of [mid, peak, trough]) |
| 54 | { assert.ok(v >= 0.16 - 1e-9 && v <= 0.44 + 1e-9, 'pulse=' + v); } |
| 55 | assert.ok(peak > mid && mid > trough, 'peak=' + peak + ' mid=' + mid + ' trough=' + trough); |
| 56 | assert.ok(Math.abs(peak - 0.44) < 1e-9, 'peak=' + peak); |
| 57 | assert.ok(Math.abs(trough - 0.16) < 1e-9, 'trough=' + trough); |
| 58 | }); |
| 59 | }); |
projects-timfalken-com meteors