'use strict'; const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const { makeGame, GameCore } = require('./helpers.js'); function landClusterAt (game, members) { const cluster = { id: game.nextClusterId++, jumpHeight: 3, vy: 0, decel: 0, phase: 'down' }; 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('Landed clusters form mixed matches with resting blocks (t1110)', () => { it('coloured cargo that lands next to two resting blocks of the same colour launches immediately', () => { 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 }, { col: 2, y: 1, color: GameCore.COLOR_GRAY } ]); const cargo = blocks[0]; assert.equal(cargo.state, 'settling'); assert.equal(cargo.color, 2); const launched = g.resolveMatches(); assert.ok(launched.length >= 1, 'mixed horizontal row must launch, launched=' + launched.length); assert.equal(cargo.state, 'flying'); assert.equal(cargo.color, GameCore.COLOR_GRAY, 'matched cargo is greyed'); const flying = g.blocks.filter((b) => b.state === 'flying'); assert.ok(flying.length >= 3, 'the two resting blocks and the cargo fly, got ' + flying.length); const cluster = g.clusters[cargo.clusterId]; assert.ok(cluster && cluster.phase === 'up' && cluster.vy > 0); }); it('a vertical mixed line of resting blocks and landed cargo also launches', () => { 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, 'vertical mixed match must launch'); assert.equal(blocks[0].state, 'flying'); assert.equal(g.blocks.filter((b) => b.state === 'flying').length, 3); }); it('grey cluster blocks have no colour and do not match until they recolor', () => { const g = makeGame({ noSpawn: true }); g.place(1, 0, 0); g.place(2, 0, 0); g.place(0, 0, 3); const { blocks } = landClusterAt(g, [ { col: 0, y: 1, color: GameCore.COLOR_GRAY } ]); assert.equal(blocks[0].color, GameCore.COLOR_GRAY); assert.equal(g.resolveMatches().length, 0, 'greys cannot match'); assert.equal(blocks[0].state, 'settling'); }); it('after greys recolor on landing, a mixed line with resting blocks launches', () => { const g = makeGame({ noSpawn: true, seed: 1 }); g.place(0, 0, 4); g.place(1, 0, 3); g.place(2, 0, 2); g.place(1, 1, 0); g.place(2, 1, 0); landClusterAt(g, [ { col: 0, y: 1, color: GameCore.COLOR_GRAY } ]); g.randomColor = () => 0; g.step(g.settleTime + 0.05, 1 / 120); const flying = g.blocks.filter((b) => b.state === 'flying'); assert.ok(flying.length >= 3, 'recolored grey + two resting must launch, flying=' + flying.length + '\n' + g.snapshot().picture + '\n' + JSON.stringify(g.blocks.map((b) => ({ col: b.col, y: b.y, color: b.color, state: b.state })))); const cluster = Object.values(g.clusters).find((c) => c.phase === 'up'); assert.ok(cluster && cluster.vy > 0); }); it('a descending cluster that lands onto a mixed row launches through the tick', () => { const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 2, fallTime: 3, riseTime: 1.5 } }); g.place(5, 0, 3); g.place(6, 0, 3); const cluster = { id: g.nextClusterId++, jumpHeight: 3, vy: -g.planet.fallSpeed, decel: 0, phase: 'down' }; g.clusters[cluster.id] = cluster; const cargo = g.createBlock(7, 4, 3, 'flying'); cargo.clusterId = cluster.id; cargo.vy = cluster.vy; const grey = g.createBlock(7, 5, GameCore.COLOR_GRAY, 'flying'); grey.clusterId = cluster.id; grey.vy = cluster.vy; grey.flame = true; g.step(2.0, 1 / 120); const up = Object.values(g.clusters).find((c) => c.phase === 'up'); assert.ok(up, 'landing then matching must launch a new rocket, clusters=' + JSON.stringify(Object.values(g.clusters).map((c) => ({ id: c.id, phase: c.phase, vy: c.vy }))) + ' blocks=' + JSON.stringify(g.blocks.map((b) => ({ col: b.col, y: Math.round(b.y * 100) / 100, color: b.color, state: b.state })))); assert.ok(up.vy > 0); assert.ok(g.blocks.filter((b) => b.state === 'flying' && b.color === GameCore.COLOR_GRAY).length >= 3); }); });