'use strict'; const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const { makeGame, placeRow, almost, GameCore, Planet } = require('./helpers.js'); describe('Outgoing shots and incoming garbage', () => { it('blocks that leave the top are recorded as outgoing shots and can be consumed', () => { 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); g.place(1, 5, 4); g.resolveMatches(); assert.equal(g.consumeOutgoingShots().length, 0); g.step(2, 1 / 120); const shots = g.consumeOutgoingShots(); assert.equal(shots.length, 4, '3 rockets + 1 cargo, got ' + shots.length); assert.ok(shots.every((s) => 'id' in s && 'color' in s && 'col' in s)); assert.equal(g.consumeOutgoingShots().length, 0, 'consume clears the list'); assert.equal(g.score, 4); }); it('ingestGarbage drops a falling grey that settles 3s then recolors', () => { const g = makeGame({ noSpawn: true, seed: 4 }); const block = g.ingestGarbage(3); assert.ok(block); assert.equal(block.col, 3); assert.equal(block.color, GameCore.COLOR_GRAY); assert.equal(block.state, 'falling'); assert.ok(almost(block.y, g.height, 0.05)); let landed = false; for (let i = 0; i < 3000; i++) { g.tick(1 / 120); if (block.state === 'settling') { landed = true; break; } } assert.ok(landed, 'should settle after landing, state=' + block.state + ' y=' + block.y + ' color=' + block.color); assert.ok(almost(block.y, 0, 0.08), 'landed on the floor, y=' + block.y); assert.equal(block.color, GameCore.COLOR_GRAY); assert.ok(block.settleTime < 0.05, 'timer starts at landing'); g.step(2.9, 1 / 120); assert.equal(block.state, 'settling', 'still settling at 2.9s, t=' + block.settleTime); g.step(0.2, 1 / 120); assert.equal(block.state, 'still'); assert.ok(block.color >= 0 && block.color < 5, 'recolored, color=' + block.color); }); it('ingestGarbage skips locked and full columns, and returns null when none are open', () => { const g = makeGame({ noSpawn: true }); for (let c = 0; c < 10; c++) { for (let r = 0; r < 13; r++) { g.place(c, r, r % 5); } } g.checkLocks(); assert.equal(g.lockedColumnCount(), 10); assert.equal(g.ingestGarbage(), null); }); it('missChance defaults to the planet Power formula and can still be overridden', () => { const g = makeGame({ noSpawn: true }); const terraMiss = Planet.missChance(Planet.defaultPlanet()); assert.ok(Math.abs(g.missChance - terraMiss) < 1e-12); assert.ok(Math.abs(terraMiss - 0.30) > 0.01, 'Terra Power miss is not the old flat 30%'); assert.equal(GameCore.DEFAULT_MISS_CHANCE, 0.30); const custom = new GameCore(Planet.defaultPlanet(), Math.random, 0.05); assert.equal(custom.missChance, 0.05); const clamped = new GameCore(Planet.defaultPlanet(), Math.random, 2); assert.equal(clamped.missChance, 1); const cinder = new GameCore(Planet.planetById('cinder'), Math.random); assert.ok(Math.abs(cinder.missChance - 0.05) < 1e-12); const aurel = new GameCore(Planet.planetById('aurel'), Math.random); assert.ok(Math.abs(aurel.missChance - Planet.missChance(Planet.planetById('aurel'))) < 1e-12); assert.ok(Math.abs(aurel.missChance - (0.60 - 0.55 / 9)) < 1e-12, 'Aurel at gravity 2 (t1199)'); }); it('fieldSnapshot lists every block for opponent miniatures', () => { const g = makeGame({ noSpawn: true }); g.place(0, 0, 1); g.place(1, 2, 3); const snap = g.fieldSnapshot(); assert.equal(snap.score, 0); assert.equal(snap.state, 'playing'); assert.equal(snap.blocks.length, 2); assert.equal(snap.blocks[0].col, 0); assert.equal(snap.blocks[1].y, 2); assert.equal(snap.locked, 0); }); });