BlueGit

projects-timfalken-com meteors

Files

meteors / test / landing-chain.test.js

landing-chain.test.js

landing-chain.test.js 4.8 KiB Download Raw
1'use strict';
2
3const { describe, it } = require('node:test');
4const assert = require('node:assert/strict');
5const { makeGame, almost, GameCore, Planet } = require('./helpers.js');
6
7function landClusterAt (game, members, opts)
8{
9 opts = opts || {};
10 const cluster = {
11 id: game.nextClusterId++,
12 jumpHeight: 3,
13 vy: 0,
14 decel: 0,
15 phase: 'down',
16 landingChain: opts.landingChain || 0
17 };
18 game.clusters[cluster.id] = cluster;
19 const blocks = [];
20 for (const m of members)
21 {
22 const b = game.createBlock(m.col, m.y, m.color, 'flying');
23 b.clusterId = cluster.id;
24 b.vy = 0;
25 b.flame = m.color === GameCore.COLOR_GRAY;
26 blocks.push(b);
27 }
28 game.landCluster(cluster, blocks);
29 return { cluster, blocks };
30}
31
32describe('Landing-chain jump bonus (t1120)', () =>
33{
34 it('a landing that immediately makes a match launches 25% stronger (chain 1)', () =>
35 {
36 const g = makeGame({ noSpawn: true });
37 g.place(0, 0, 2);
38 g.place(1, 0, 2);
39 const { blocks } = landClusterAt(g, [{ col: 2, y: 0, color: 2 }]);
40 const launched = g.resolveMatches();
41 assert.ok(launched.length >= 1);
42 const expected = Planet.jumpHeight(g.planet, 3, false) * 1.25;
43 assert.ok(almost(launched[0].jumpHeight, expected, 1e-9),
44 'height=' + launched[0].jumpHeight + ' expected ' + expected);
45 assert.equal(launched[0].landingChain, 1);
46 assert.ok(almost(launched[0].chainBonus, 1.25, 1e-12));
47 const cluster = g.clusters[blocks[0].clusterId];
48 assert.ok(cluster);
49 assert.equal(cluster.landingChain, 1);
50 assert.equal(g.lastChainIndicator.chain, 1);
51 assert.equal(g.lastChainIndicator.bonusPct, 25);
52 });
53
54 it('a second consecutive landing-match stacks additively to +50% (chain 2)', () =>
55 {
56 const g = makeGame({ noSpawn: true });
57 g.place(0, 0, 1);
58 g.place(1, 0, 1);
59 const { blocks } = landClusterAt(g, [{ col: 2, y: 0, color: 1 }], { landingChain: 1 });
60 const launched = g.resolveMatches();
61 assert.ok(launched.length >= 1);
62 const expected = Planet.jumpHeight(g.planet, 3, false) * 1.5;
63 assert.ok(almost(launched[0].jumpHeight, expected, 1e-9),
64 'height=' + launched[0].jumpHeight + ' expected ' + expected);
65 assert.equal(launched[0].landingChain, 2);
66 assert.equal(g.clusters[blocks[0].clusterId].landingChain, 2);
67 assert.equal(g.lastChainIndicator.bonusPct, 50);
68 });
69
70 it('a third step is +75% (x1.75), additive not multiplicative', () =>
71 {
72 const g = makeGame({ noSpawn: true });
73 g.place(3, 0, 0);
74 g.place(4, 0, 0);
75 landClusterAt(g, [{ col: 5, y: 0, color: 0 }], { landingChain: 2 });
76 const launched = g.resolveMatches();
77 const expected = Planet.jumpHeight(g.planet, 3, false) * 1.75;
78 assert.ok(almost(launched[0].jumpHeight, expected, 1e-9));
79 assert.equal(launched[0].landingChain, 3);
80 // Additive was chosen: 1 + 0.25*3 = 1.75, not 1.25^3 ≈ 1.953.
81 assert.ok(!almost(launched[0].jumpHeight, Planet.jumpHeight(g.planet, 3, false) * 1.25 ** 3, 1e-6));
82 });
83
84 it('landing without a match resets the chain, so the next launch is un-bonused', () =>
85 {
86 const g = makeGame({ noSpawn: true });
87 g.place(0, 0, 4);
88 g.place(1, 0, 4);
89 const { cluster, blocks } = landClusterAt(g, [
90 { col: 2, y: 0, color: 3 }
91 ], { landingChain: 2 });
92 // Coloured-only clusters are released in advanceSettle (same as a
93 // real tick), then resolveMatches sees justLanded and, with no
94 // match, resets the chain.
95 g.advanceSettle(0);
96 assert.equal(g.resolveMatches().length, 0);
97 assert.equal(blocks[0].justLanded, false);
98 assert.equal(blocks[0].landingChain || 0, 0, 'reset after a dry landing');
99 // A later ordinary match (no new landing) must not get a bonus.
100 g.place(3, 0, 3);
101 g.place(4, 0, 3);
102 const launched = g.resolveMatches();
103 assert.ok(launched.length >= 1);
104 assert.equal(launched[0].landingChain, 0);
105 assert.ok(almost(launched[0].jumpHeight, Planet.jumpHeight(g.planet, 3, false), 1e-9));
106 });
107
108 it('applies to stacked landings (not only the floor)', () =>
109 {
110 const g = makeGame({ noSpawn: true });
111 g.place(4, 0, 1);
112 g.place(4, 1, 1);
113 const { blocks } = landClusterAt(g, [{ col: 4, y: 2, color: 1 }]);
114 const launched = g.resolveMatches();
115 assert.ok(launched.length >= 1);
116 const expected = Planet.jumpHeight(g.planet, 3, true) * 1.25;
117 assert.ok(almost(launched[0].jumpHeight, expected, 1e-9),
118 'vertical stacked landing height=' + launched[0].jumpHeight);
119 assert.equal(launched[0].landingChain, 1);
120 assert.equal(blocks[0].state, 'flying');
121 });
122
123 it('a regular (non-landing) match is unchanged', () =>
124 {
125 const g = makeGame({ noSpawn: true });
126 g.place(0, 0, 2);
127 g.place(1, 0, 2);
128 g.place(2, 0, 2);
129 const launched = g.resolveMatches();
130 assert.equal(launched[0].landingChain, 0);
131 assert.ok(almost(launched[0].jumpHeight, Planet.jumpHeight(g.planet, 3, false), 1e-9));
132 });
133
134 it('LANDING_CHAIN_BONUS is 0.25 additive per step', () =>
135 {
136 assert.equal(GameCore.LANDING_CHAIN_BONUS, 0.25);
137 });
138});