| 1 | 'use strict'; |
| 2 | |
| 3 | const { describe, it } = require('node:test'); |
| 4 | const assert = require('node:assert/strict'); |
| 5 | const { makeGame, GameCore } = require('./helpers.js'); |
| 6 | |
| 7 | function landClusterAt (game, members) |
| 8 | { |
| 9 | const cluster = { |
| 10 | id: game.nextClusterId++, |
| 11 | jumpHeight: 3, |
| 12 | vy: 0, |
| 13 | decel: 0, |
| 14 | phase: 'down' |
| 15 | }; |
| 16 | game.clusters[cluster.id] = cluster; |
| 17 | const blocks = []; |
| 18 | for (const m of members) |
| 19 | { |
| 20 | const b = game.createBlock(m.col, m.y, m.color, 'flying'); |
| 21 | b.clusterId = cluster.id; |
| 22 | b.vy = 0; |
| 23 | b.flame = m.color === GameCore.COLOR_GRAY; |
| 24 | blocks.push(b); |
| 25 | } |
| 26 | game.landCluster(cluster, blocks); |
| 27 | return { cluster, blocks }; |
| 28 | } |
| 29 | |
| 30 | describe('Landed clusters form mixed matches with resting blocks (t1110)', () => |
| 31 | { |
| 32 | it('coloured cargo that lands next to two resting blocks of the same colour launches immediately', () => |
| 33 | { |
| 34 | const g = makeGame({ noSpawn: true }); |
| 35 | g.place(0, 0, 2); |
| 36 | g.place(1, 0, 2); |
| 37 | const { blocks } = landClusterAt(g, [ |
| 38 | { col: 2, y: 0, color: 2 }, |
| 39 | { col: 2, y: 1, color: GameCore.COLOR_GRAY } |
| 40 | ]); |
| 41 | const cargo = blocks[0]; |
| 42 | assert.equal(cargo.state, 'settling'); |
| 43 | assert.equal(cargo.color, 2); |
| 44 | const launched = g.resolveMatches(); |
| 45 | assert.ok(launched.length >= 1, 'mixed horizontal row must launch, launched=' + launched.length); |
| 46 | assert.equal(cargo.state, 'flying'); |
| 47 | assert.equal(cargo.color, GameCore.COLOR_GRAY, 'matched cargo is greyed'); |
| 48 | const flying = g.blocks.filter((b) => b.state === 'flying'); |
| 49 | assert.ok(flying.length >= 3, 'the two resting blocks and the cargo fly, got ' + flying.length); |
| 50 | const cluster = g.clusters[cargo.clusterId]; |
| 51 | assert.ok(cluster && cluster.phase === 'up' && cluster.vy > 0); |
| 52 | }); |
| 53 | |
| 54 | it('a vertical mixed line of resting blocks and landed cargo also launches', () => |
| 55 | { |
| 56 | const g = makeGame({ noSpawn: true }); |
| 57 | g.place(4, 0, 1); |
| 58 | g.place(4, 1, 1); |
| 59 | const { blocks } = landClusterAt(g, [ |
| 60 | { col: 4, y: 2, color: 1 } |
| 61 | ]); |
| 62 | const launched = g.resolveMatches(); |
| 63 | assert.ok(launched.length >= 1, 'vertical mixed match must launch'); |
| 64 | assert.equal(blocks[0].state, 'flying'); |
| 65 | assert.equal(g.blocks.filter((b) => b.state === 'flying').length, 3); |
| 66 | }); |
| 67 | |
| 68 | it('grey cluster blocks have no colour and do not match until they recolor', () => |
| 69 | { |
| 70 | const g = makeGame({ noSpawn: true }); |
| 71 | g.place(1, 0, 0); |
| 72 | g.place(2, 0, 0); |
| 73 | g.place(0, 0, 3); |
| 74 | const { blocks } = landClusterAt(g, [ |
| 75 | { col: 0, y: 1, color: GameCore.COLOR_GRAY } |
| 76 | ]); |
| 77 | assert.equal(blocks[0].color, GameCore.COLOR_GRAY); |
| 78 | assert.equal(g.resolveMatches().length, 0, 'greys cannot match'); |
| 79 | assert.equal(blocks[0].state, 'settling'); |
| 80 | }); |
| 81 | |
| 82 | it('after greys recolor on landing, a mixed line with resting blocks launches', () => |
| 83 | { |
| 84 | const g = makeGame({ noSpawn: true, seed: 1 }); |
| 85 | g.place(0, 0, 4); |
| 86 | g.place(1, 0, 3); |
| 87 | g.place(2, 0, 2); |
| 88 | g.place(1, 1, 0); |
| 89 | g.place(2, 1, 0); |
| 90 | landClusterAt(g, [ |
| 91 | { col: 0, y: 1, color: GameCore.COLOR_GRAY } |
| 92 | ]); |
| 93 | g.randomColor = () => 0; |
| 94 | g.step(g.settleTime + 0.05, 1 / 120); |
| 95 | const flying = g.blocks.filter((b) => b.state === 'flying'); |
| 96 | assert.ok(flying.length >= 3, |
| 97 | 'recolored grey + two resting must launch, flying=' + flying.length |
| 98 | + '\n' + g.snapshot().picture |
| 99 | + '\n' + JSON.stringify(g.blocks.map((b) => ({ |
| 100 | col: b.col, y: b.y, color: b.color, state: b.state |
| 101 | })))); |
| 102 | const cluster = Object.values(g.clusters).find((c) => c.phase === 'up'); |
| 103 | assert.ok(cluster && cluster.vy > 0); |
| 104 | }); |
| 105 | |
| 106 | it('a descending cluster that lands onto a mixed row launches through the tick', () => |
| 107 | { |
| 108 | const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 2, fallTime: 3, riseTime: 1.5 } }); |
| 109 | g.place(5, 0, 3); |
| 110 | g.place(6, 0, 3); |
| 111 | const cluster = { |
| 112 | id: g.nextClusterId++, |
| 113 | jumpHeight: 3, |
| 114 | vy: -g.planet.fallSpeed, |
| 115 | decel: 0, |
| 116 | phase: 'down' |
| 117 | }; |
| 118 | g.clusters[cluster.id] = cluster; |
| 119 | const cargo = g.createBlock(7, 4, 3, 'flying'); |
| 120 | cargo.clusterId = cluster.id; |
| 121 | cargo.vy = cluster.vy; |
| 122 | const grey = g.createBlock(7, 5, GameCore.COLOR_GRAY, 'flying'); |
| 123 | grey.clusterId = cluster.id; |
| 124 | grey.vy = cluster.vy; |
| 125 | grey.flame = true; |
| 126 | g.step(2.0, 1 / 120); |
| 127 | const up = Object.values(g.clusters).find((c) => c.phase === 'up'); |
| 128 | assert.ok(up, 'landing then matching must launch a new rocket, clusters=' |
| 129 | + JSON.stringify(Object.values(g.clusters).map((c) => ({ id: c.id, phase: c.phase, vy: c.vy }))) |
| 130 | + ' blocks=' + JSON.stringify(g.blocks.map((b) => ({ |
| 131 | col: b.col, y: Math.round(b.y * 100) / 100, color: b.color, state: b.state |
| 132 | })))); |
| 133 | assert.ok(up.vy > 0); |
| 134 | assert.ok(g.blocks.filter((b) => b.state === 'flying' && b.color === GameCore.COLOR_GRAY).length >= 3); |
| 135 | }); |
| 136 | }); |
projects-timfalken-com meteors