'use strict'; const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const { makeGame, placeRow, GameCore, Planet } = require('./helpers.js'); describe('Points, landing and recolor', () => { it('blocks that leave the top of the field become one point each and are gone', () => { const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 1, fallTime: 5, riseTime: 0.5 } }); placeRow(g, 0, [0, 1, 2], 0); const carried = g.place(1, 1, 4); g.resolveMatches(); assert.equal(g.score, 0); g.step(2, 1 / 120); assert.equal(g.blocks.filter((b) => b.state === 'flying').length, 0); assert.equal(g.score, 4, '3 rockets + 1 carried'); assert.equal(g.blockAt(1, 1), null); assert.ok(!g.blocks.includes(carried) && carried.y >= g.height || g.score === 4); }); it('a cluster that does not clear the field lands, sits for 3 seconds, then takes random colors', () => { const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 4, fallTime: 2, riseTime: 0.5 }, seed: 99 }); placeRow(g, 0, [3, 4, 5], 2); g.resolveMatches(); // Jump height is 13/4 = 3.25, they come back down. Step until they land. let landed = false; for (let i = 0; i < 2000; i++) { g.tick(1 / 120); const grayNow = g.blocks.filter((b) => b.color === GameCore.COLOR_GRAY); if (grayNow.length >= 3 && grayNow.every((b) => b.state === 'settling')) { landed = true; break; } } const gray = g.blocks.filter((b) => b.color === GameCore.COLOR_GRAY); assert.ok(landed, 'should have landed as gray, got ' + gray.length + ' states=' + gray.map((b) => b.state + '@' + b.y).join(',') + '\n' + g.snapshot().picture); for (const b of gray) { assert.equal(b.state, 'settling'); assert.ok(b.y < 6, 'landed low, y=' + b.y); assert.ok(b.settleTime < 0.05, 'timer starts at landing, t=' + b.settleTime); } g.step(2.9, 1 / 60); assert.ok(gray.every((b) => b.state === 'settling'), 'still settling just before 3s: ' + gray.map((b) => b.state + '/' + b.settleTime).join(',')); g.step(0.2, 1 / 60); for (const b of gray) { assert.equal(b.state, 'still'); assert.ok(b.color >= 0 && b.color < 5, 'recolored, color=' + b.color); assert.equal(b.clusterId, null); } }); it('carried colored blocks land as still blocks and do not wait 3 seconds', () => { const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 4, fallTime: 2, riseTime: 0.5 } }); placeRow(g, 0, [0, 1, 2], 0); const carried = g.place(1, 1, 4); g.resolveMatches(); g.step(4, 1 / 120); assert.equal(carried.color, 4); assert.equal(carried.state, 'still'); assert.equal(carried.clusterId, null); }); it('spawn drops a random color into a random open column every second', () => { const g = makeGame({ seed: 3 }); assert.equal(g.blocks.length, 0); g.step(0.99); assert.equal(g.blocks.length, 0); g.step(0.02); assert.equal(g.blocks.length, 1); assert.equal(g.blocks[0].state, 'falling'); assert.ok(g.blocks[0].color >= 0 && g.blocks[0].color < 5); assert.ok(g.blocks[0].col >= 0 && g.blocks[0].col < 10); g.step(1); assert.equal(g.blocks.length, 2); // Let the first one land. g.step(g.planet.fallTime + 0.2); const landed = g.blocks.filter((b) => b.state === 'still'); assert.ok(landed.length >= 1); for (const b of landed) { assert.equal(b.y, 0); } }); });