| 1 | 'use strict'; |
| 2 | |
| 3 | const { describe, it } = require('node:test'); |
| 4 | const assert = require('node:assert/strict'); |
| 5 | const { makeGame, placeRow, almost, GameCore, Planet } = require('./helpers.js'); |
| 6 | |
| 7 | describe('Outgoing shots and incoming garbage', () => |
| 8 | { |
| 9 | it('blocks that leave the top are recorded as outgoing shots and can be consumed', () => |
| 10 | { |
| 11 | const g = makeGame({ |
| 12 | noSpawn: true, |
| 13 | planetOpts: { jumpsToClear: 1, fallTime: 5, riseTime: 0.5 } |
| 14 | }); |
| 15 | placeRow(g, 0, [0, 1, 2], 0); |
| 16 | g.place(1, 1, 4); |
| 17 | g.resolveMatches(); |
| 18 | assert.equal(g.consumeOutgoingShots().length, 0); |
| 19 | g.step(2, 1 / 120); |
| 20 | const shots = g.consumeOutgoingShots(); |
| 21 | assert.equal(shots.length, 4, '3 rockets + 1 cargo, got ' + shots.length); |
| 22 | assert.ok(shots.every((s) => 'id' in s && 'color' in s && 'col' in s)); |
| 23 | assert.equal(g.consumeOutgoingShots().length, 0, 'consume clears the list'); |
| 24 | assert.equal(g.score, 4); |
| 25 | }); |
| 26 | |
| 27 | it('ingestGarbage drops a falling grey that settles 3s then recolors', () => |
| 28 | { |
| 29 | const g = makeGame({ noSpawn: true, seed: 4 }); |
| 30 | const block = g.ingestGarbage(3); |
| 31 | assert.ok(block); |
| 32 | assert.equal(block.col, 3); |
| 33 | assert.equal(block.color, GameCore.COLOR_GRAY); |
| 34 | assert.equal(block.state, 'falling'); |
| 35 | assert.ok(almost(block.y, g.height, 0.05)); |
| 36 | let landed = false; |
| 37 | for (let i = 0; i < 3000; i++) |
| 38 | { |
| 39 | g.tick(1 / 120); |
| 40 | if (block.state === 'settling') |
| 41 | { |
| 42 | landed = true; |
| 43 | break; |
| 44 | } |
| 45 | } |
| 46 | assert.ok(landed, 'should settle after landing, state=' + block.state + ' y=' + block.y + ' color=' + block.color); |
| 47 | assert.ok(almost(block.y, 0, 0.08), 'landed on the floor, y=' + block.y); |
| 48 | assert.equal(block.color, GameCore.COLOR_GRAY); |
| 49 | assert.ok(block.settleTime < 0.05, 'timer starts at landing'); |
| 50 | g.step(2.9, 1 / 120); |
| 51 | assert.equal(block.state, 'settling', 'still settling at 2.9s, t=' + block.settleTime); |
| 52 | g.step(0.2, 1 / 120); |
| 53 | assert.equal(block.state, 'still'); |
| 54 | assert.ok(block.color >= 0 && block.color < 5, 'recolored, color=' + block.color); |
| 55 | }); |
| 56 | |
| 57 | it('ingestGarbage skips locked and full columns, and returns null when none are open', () => |
| 58 | { |
| 59 | const g = makeGame({ noSpawn: true }); |
| 60 | for (let c = 0; c < 10; c++) |
| 61 | { |
| 62 | for (let r = 0; r < 13; r++) |
| 63 | { g.place(c, r, r % 5); } |
| 64 | } |
| 65 | g.checkLocks(); |
| 66 | assert.equal(g.lockedColumnCount(), 10); |
| 67 | assert.equal(g.ingestGarbage(), null); |
| 68 | }); |
| 69 | |
| 70 | it('missChance is a parameter defaulting to 0.30, independent of planet Power', () => |
| 71 | { |
| 72 | const g = makeGame({ noSpawn: true }); |
| 73 | assert.equal(g.missChance, 0.30); |
| 74 | assert.equal(GameCore.DEFAULT_MISS_CHANCE, 0.30); |
| 75 | const custom = new GameCore(Planet.defaultPlanet(), Math.random, 0.05); |
| 76 | assert.equal(custom.missChance, 0.05); |
| 77 | const clamped = new GameCore(Planet.defaultPlanet(), Math.random, 2); |
| 78 | assert.equal(clamped.missChance, 1); |
| 79 | // Planet.missChance stays the stage-3 Power formula, unused here. |
| 80 | const terraMiss = Planet.missChance(Planet.defaultPlanet()); |
| 81 | assert.ok(Math.abs(terraMiss - 0.30) > 0.01, 'Terra Power miss is not the stage-2 30%'); |
| 82 | }); |
| 83 | |
| 84 | it('fieldSnapshot lists every block for opponent miniatures', () => |
| 85 | { |
| 86 | const g = makeGame({ noSpawn: true }); |
| 87 | g.place(0, 0, 1); |
| 88 | g.place(1, 2, 3); |
| 89 | const snap = g.fieldSnapshot(); |
| 90 | assert.equal(snap.score, 0); |
| 91 | assert.equal(snap.state, 'playing'); |
| 92 | assert.equal(snap.blocks.length, 2); |
| 93 | assert.equal(snap.blocks[0].col, 0); |
| 94 | assert.equal(snap.blocks[1].y, 2); |
| 95 | assert.equal(snap.locked, 0); |
| 96 | }); |
| 97 | }); |
projects-timfalken-com meteors