'use strict'; const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const { makeGame, almost, GameCore, Planet } = require('./helpers.js'); function landClusterAt (game, members, opts) { opts = opts || {}; const cluster = { id: game.nextClusterId++, jumpHeight: 3, vy: 0, decel: 0, phase: 'down', landingChain: opts.landingChain || 0 }; game.clusters[cluster.id] = cluster; const blocks = []; for (const m of members) { const b = game.createBlock(m.col, m.y, m.color, 'flying'); b.clusterId = cluster.id; b.vy = 0; b.flame = m.color === GameCore.COLOR_GRAY; blocks.push(b); } game.landCluster(cluster, blocks); return { cluster, blocks }; } describe('Landing-chain jump bonus (t1120)', () => { it('a landing that immediately makes a match launches 25% stronger (chain 1)', () => { const g = makeGame({ noSpawn: true }); g.place(0, 0, 2); g.place(1, 0, 2); const { blocks } = landClusterAt(g, [{ col: 2, y: 0, color: 2 }]); const launched = g.resolveMatches(); assert.ok(launched.length >= 1); const expected = Planet.jumpHeight(g.planet, 3, false) * 1.25; assert.ok(almost(launched[0].jumpHeight, expected, 1e-9), 'height=' + launched[0].jumpHeight + ' expected ' + expected); assert.equal(launched[0].landingChain, 1); assert.ok(almost(launched[0].chainBonus, 1.25, 1e-12)); const cluster = g.clusters[blocks[0].clusterId]; assert.ok(cluster); assert.equal(cluster.landingChain, 1); assert.equal(g.lastChainIndicator.chain, 1); assert.equal(g.lastChainIndicator.bonusPct, 25); }); it('a second consecutive landing-match stacks additively to +50% (chain 2)', () => { const g = makeGame({ noSpawn: true }); g.place(0, 0, 1); g.place(1, 0, 1); const { blocks } = landClusterAt(g, [{ col: 2, y: 0, color: 1 }], { landingChain: 1 }); const launched = g.resolveMatches(); assert.ok(launched.length >= 1); const expected = Planet.jumpHeight(g.planet, 3, false) * 1.5; assert.ok(almost(launched[0].jumpHeight, expected, 1e-9), 'height=' + launched[0].jumpHeight + ' expected ' + expected); assert.equal(launched[0].landingChain, 2); assert.equal(g.clusters[blocks[0].clusterId].landingChain, 2); assert.equal(g.lastChainIndicator.bonusPct, 50); }); it('a third step is +75% (x1.75), additive not multiplicative', () => { const g = makeGame({ noSpawn: true }); g.place(3, 0, 0); g.place(4, 0, 0); landClusterAt(g, [{ col: 5, y: 0, color: 0 }], { landingChain: 2 }); const launched = g.resolveMatches(); const expected = Planet.jumpHeight(g.planet, 3, false) * 1.75; assert.ok(almost(launched[0].jumpHeight, expected, 1e-9)); assert.equal(launched[0].landingChain, 3); // Additive was chosen: 1 + 0.25*3 = 1.75, not 1.25^3 ≈ 1.953. assert.ok(!almost(launched[0].jumpHeight, Planet.jumpHeight(g.planet, 3, false) * 1.25 ** 3, 1e-6)); }); it('landing without a match resets the chain, so the next launch is un-bonused', () => { const g = makeGame({ noSpawn: true }); g.place(0, 0, 4); g.place(1, 0, 4); const { cluster, blocks } = landClusterAt(g, [ { col: 2, y: 0, color: 3 } ], { landingChain: 2 }); // Coloured-only clusters are released in advanceSettle (same as a // real tick), then resolveMatches sees justLanded and, with no // match, resets the chain. g.advanceSettle(0); assert.equal(g.resolveMatches().length, 0); assert.equal(blocks[0].justLanded, false); assert.equal(blocks[0].landingChain || 0, 0, 'reset after a dry landing'); // A later ordinary match (no new landing) must not get a bonus. g.place(3, 0, 3); g.place(4, 0, 3); const launched = g.resolveMatches(); assert.ok(launched.length >= 1); assert.equal(launched[0].landingChain, 0); assert.ok(almost(launched[0].jumpHeight, Planet.jumpHeight(g.planet, 3, false), 1e-9)); }); it('applies to stacked landings (not only the floor)', () => { const g = makeGame({ noSpawn: true }); g.place(4, 0, 1); g.place(4, 1, 1); const { blocks } = landClusterAt(g, [{ col: 4, y: 2, color: 1 }]); const launched = g.resolveMatches(); assert.ok(launched.length >= 1); const expected = Planet.jumpHeight(g.planet, 3, true) * 1.25; assert.ok(almost(launched[0].jumpHeight, expected, 1e-9), 'vertical stacked landing height=' + launched[0].jumpHeight); assert.equal(launched[0].landingChain, 1); assert.equal(blocks[0].state, 'flying'); }); it('a regular (non-landing) match is unchanged', () => { const g = makeGame({ noSpawn: true }); g.place(0, 0, 2); g.place(1, 0, 2); g.place(2, 0, 2); const launched = g.resolveMatches(); assert.equal(launched[0].landingChain, 0); assert.ok(almost(launched[0].jumpHeight, Planet.jumpHeight(g.planet, 3, false), 1e-9)); }); it('LANDING_CHAIN_BONUS is 0.25 additive per step', () => { assert.equal(GameCore.LANDING_CHAIN_BONUS, 0.25); }); });