'use strict'; const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const { makeGame, placeRow, almost, Planet } = require('./helpers.js'); describe('Cluster float-down is halved, single-block fall is not (t1124)', () => { it('a newly spawned block falls at the full fallSpeed', () => { const g = makeGame({ seed: 3 }); const spawned = g.trySpawn(); assert.ok(spawned); assert.equal(spawned.state, 'falling'); assert.ok(almost(spawned.vy, -g.planet.fallSpeed, 1e-12)); assert.ok(g.planet.fallSpeed > g.planet.clusterFallSpeed + 0.5); const y1 = spawned.y; g.step(0.2, 1 / 120); const speed = (y1 - spawned.y) / 0.2; assert.ok(almost(speed, g.planet.fallSpeed, 0.15), 'spawn speed=' + speed); }); it('unsupported and ingested garbage fall at the full fallSpeed', () => { const g = makeGame({ noSpawn: true, seed: 2 }); const hanging = g.place(0, 4, 1); g.releaseUnsupported(); assert.equal(hanging.state, 'falling'); assert.ok(almost(hanging.vy, 0, 1e-12), 'starts from rest'); g.step(g.planet.apexEaseTime + 0.05, 1 / 120); assert.ok(almost(Math.abs(hanging.vy), g.planet.fallSpeed, 0.1), 'unsupported terminal vy=' + hanging.vy); const garbage = g.ingestGarbage(3); assert.ok(almost(garbage.vy, -g.planet.fallSpeed, 1e-12)); }); it('a launched cluster eases into the halved clusterFallSpeed, not fallSpeed', () => { const g = makeGame({ noSpawn: true }); placeRow(g, 0, [0, 1, 2], 0); g.resolveMatches(); g.step(g.planet.riseTime + g.planet.apexEaseTime + 0.05, 1 / 240); const cluster = g.clusters[g.blocks[0].clusterId]; assert.ok(cluster, 'still flying'); assert.equal(cluster.phase, 'down'); assert.ok(almost(Math.abs(cluster.vy), g.planet.clusterFallSpeed, 0.08), 'cluster vy=' + cluster.vy + ' expected ' + (-g.planet.clusterFallSpeed)); assert.ok(Math.abs(cluster.vy) < g.planet.fallSpeed - 0.5, 'must not use the full single-block fallSpeed'); }); it('a manual jump comes down at the full fallSpeed', () => { const g = makeGame({ noSpawn: true }); const block = g.place(4, 0, 2); g.startManualLaunch(block); assert.equal(block.state, 'manual'); g.step(g.planet.riseTime + g.planet.apexEaseTime + 0.05, 1 / 240); assert.equal(block.manualPhase, 'down'); assert.ok(almost(Math.abs(block.vy), g.planet.fallSpeed, 0.12), 'manual vy=' + block.vy + ' expected ' + (-g.planet.fallSpeed)); assert.ok(Math.abs(block.vy) > g.planet.clusterFallSpeed + 0.5); }); it('cargo riding a descending cluster shares the halved float-down', () => { const g = makeGame({ noSpawn: true }); placeRow(g, 0, [0, 1, 2], 0); const cargo = g.place(1, 1, 4); g.resolveMatches(); assert.equal(cargo.state, 'flying'); g.step(g.planet.riseTime + g.planet.apexEaseTime + 0.05, 1 / 240); const cluster = g.clusters[cargo.clusterId]; assert.ok(cluster); assert.ok(almost(Math.abs(cluster.vy), g.planet.clusterFallSpeed, 0.08)); assert.ok(almost(cargo.vy, cluster.vy, 1e-9)); }); });