'use strict'; const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const { makeGame, placeRow, almost, 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: 2, fallTime: 5, riseTime: 0.5 } }); // t1199: minimum gravity is 2 (9.75-tile jump), so the match sits on // a non-matching support stack and one jump still clears the field. for (let y = 0; y < 4; y++) for (const c of [0, 1, 2]) g.place(c, y, 1 + (c + y) % 3); placeRow(g, 4, [0, 1, 2], 0); const carried = g.place(1, 5, 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, 5), 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 keep their color and stay in the rigid group until greys convert', () => { 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(); // Land (jump is short) then sit mid-settle. let landed = false; for (let i = 0; i < 2000; i++) { g.tick(1 / 120); if (carried.state === 'settling' && g.clusters[carried.clusterId] && g.clusters[carried.clusterId].phase === 'landed') { landed = true; break; } } assert.ok(landed, 'cargo should land with the rigid group, state=' + carried.state); assert.equal(carried.color, 4, 'cargo does not recolor'); assert.ok(carried.clusterId != null, 'cargo stays in the group'); g.step(2.9, 1 / 60); assert.equal(carried.color, 4); assert.equal(carried.state, 'settling'); g.step(0.2, 1 / 60); assert.equal(carried.color, 4); assert.equal(carried.state, 'still'); assert.equal(carried.clusterId, null); assert.ok(almost(carried.y, 1, 1e-6), 'y=' + carried.y); }); it('spawn drops a random color into a random open column every second', () => { const g = makeGame({ seed: 3 }); g.playTime = 6; // after the opening burst / ramp (t1189) 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); } }); });