BlueGit

projects-timfalken-com meteors

Files

meteors / test / combo.test.js

combo.test.js

combo.test.js 2.8 KiB Download Raw
1'use strict';
2
3// t1197: combo — each match adds +5% jump height (additive with the
4// landing-chain bonus); resets after 5 s without a match.
5
6const { describe, it } = require('node:test');
7const assert = require('node:assert/strict');
8const { makeGame, almost, GameCore, Planet } = require('./helpers.js');
9
10
11function run (g, secs)
12{
13 for (let t = 0; t < secs - 1e-9; t += 0.05) g.tick(0.05);
14}
15
16function freshMatch (g, color)
17{
18 const h = makeGame({ noSpawn: true });
19 h.combo = g.combo;
20 h.comboAge = g.comboAge;
21 h.place(0, 0, color);
22 h.place(1, 0, color);
23 h.place(2, 0, color);
24 const l = h.resolveMatches();
25 g.combo = h.combo;
26 g.comboAge = h.comboAge;
27 g.lastChainIndicator = h.lastChainIndicator;
28 return l[0];
29}
30
31describe('Match combo (t1197)', () =>
32{
33 const base = () => Planet.jumpHeight(makeGame({ noSpawn: true }).planet, 3, false);
34
35 it('constants', () =>
36 {
37 assert.equal(GameCore.COMBO_STEP, 0.05);
38 assert.equal(GameCore.COMBO_RESET_S, 5);
39 });
40
41 it('first match +0%, then +5%, +10%, ... per earlier match in the combo', () =>
42 {
43 const g = makeGame({ noSpawn: true });
44 for (let k = 0; k < 4; k++)
45 {
46 const l = freshMatch(g, 1 + (k % 3));
47 assert.ok(almost(l.comboBonus, 0.05 * k, 1e-12), 'k=' + k);
48 assert.ok(almost(l.jumpHeight, base() * (1 + 0.05 * k), 1e-9));
49 assert.equal(g.combo, k + 1);
50 }
51 assert.equal(g.lastChainIndicator.bonusPct, 15);
52 assert.equal(g.comboBonusPct(), 20);
53 });
54
55 it('adds to the landing-chain bonus (chain 1 + 2 combo matches = +35%)', () =>
56 {
57 const g = makeGame({ noSpawn: true });
58 g.combo = 2;
59 g.place(0, 0, 2);
60 g.place(1, 0, 2);
61 const cluster = { id: g.nextClusterId++, jumpHeight: 3, vy: 0, decel: 0, phase: 'down', landingChain: 0 };
62 g.clusters[cluster.id] = cluster;
63 const b = g.createBlock(2, 0, 2, 'flying');
64 b.clusterId = cluster.id;
65 g.landCluster(cluster, [b]);
66 const l = g.resolveMatches()[0];
67 assert.ok(almost(l.chainBonus, 1.35, 1e-12));
68 assert.equal(g.lastChainIndicator.bonusPct, 35);
69 });
70
71 it('resets after 5 s without a match, not before', () =>
72 {
73 const g = makeGame({ noSpawn: true });
74 freshMatch(g, 1);
75 freshMatch(g, 2);
76 assert.equal(g.combo, 2);
77 run(g, 4.9);
78 assert.equal(g.combo, 2, 'still alive at 4.9 s');
79 freshMatch(g, 3); // a match restarts the 5 s window
80 assert.equal(g.combo, 3);
81 run(g, 4.0);
82 assert.equal(g.combo, 3);
83 run(g, 1.1);
84 assert.equal(g.combo, 0, 'gone after 5 s without a match');
85 const l = freshMatch(g, 1);
86 assert.equal(l.comboBonus, 0);
87 });
88
89 it('bots share it: an offline bot core is a GameCore with the same combo', () =>
90 {
91 const Offline = require('../src/offline.js');
92 const battle = Offline.createBattle({ playerPlanet: Planet.defaultPlanet(), rng: () => 0.5 });
93 const bot = battle.bots[0].core;
94 assert.equal(bot.combo, 0);
95 assert.equal(typeof bot.comboBonusPct, 'function');
96 });
97});