| 1 | 'use strict'; |
| 2 | |
| 3 | // t1197/t1198: combo — each match adds +1% jump height (max +30%) (additive with the |
| 4 | // landing-chain bonus); resets after 5 s without a match. |
| 5 | |
| 6 | const { describe, it } = require('node:test'); |
| 7 | const assert = require('node:assert/strict'); |
| 8 | const { makeGame, almost, GameCore, Planet } = require('./helpers.js'); |
| 9 | |
| 10 | |
| 11 | function run (g, secs) |
| 12 | { |
| 13 | for (let t = 0; t < secs - 1e-9; t += 0.05) g.tick(0.05); |
| 14 | } |
| 15 | |
| 16 | function 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 | |
| 31 | describe('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.01); |
| 38 | assert.equal(GameCore.COMBO_MAX_STEPS, 30); |
| 39 | assert.equal(GameCore.COMBO_RESET_S, 5); |
| 40 | }); |
| 41 | |
| 42 | it('first match +0%, then +1%, +2%, ... per earlier match in the combo', () => |
| 43 | { |
| 44 | const g = makeGame({ noSpawn: true }); |
| 45 | for (let k = 0; k < 4; k++) |
| 46 | { |
| 47 | const l = freshMatch(g, 1 + (k % 3)); |
| 48 | assert.ok(almost(l.comboBonus, 0.01 * k, 1e-12), 'k=' + k); |
| 49 | assert.ok(almost(l.jumpHeight, base() * (1 + 0.01 * k), 1e-9)); |
| 50 | assert.equal(g.combo, k + 1); |
| 51 | } |
| 52 | assert.equal(g.lastChainIndicator.bonusPct, 3); |
| 53 | assert.equal(g.comboBonusPct(), 4); |
| 54 | }); |
| 55 | |
| 56 | it('adds to the landing-chain bonus (chain 1 + 2 combo matches = +27%)', () => |
| 57 | { |
| 58 | const g = makeGame({ noSpawn: true }); |
| 59 | g.combo = 2; |
| 60 | g.place(0, 0, 2); |
| 61 | g.place(1, 0, 2); |
| 62 | const cluster = { id: g.nextClusterId++, jumpHeight: 3, vy: 0, decel: 0, phase: 'down', landingChain: 0 }; |
| 63 | g.clusters[cluster.id] = cluster; |
| 64 | const b = g.createBlock(2, 0, 2, 'flying'); |
| 65 | b.clusterId = cluster.id; |
| 66 | g.landCluster(cluster, [b]); |
| 67 | const l = g.resolveMatches()[0]; |
| 68 | assert.ok(almost(l.chainBonus, 1.27, 1e-12)); |
| 69 | assert.equal(g.lastChainIndicator.bonusPct, 27); |
| 70 | }); |
| 71 | |
| 72 | it('combo bonus is capped at +30% (0.01 * min(combo, 30))', () => |
| 73 | { |
| 74 | for (const [combo, pct] of [[29, 29], [30, 30], [31, 30], [100, 30]]) |
| 75 | { |
| 76 | const g = makeGame({ noSpawn: true }); |
| 77 | g.combo = combo; |
| 78 | const l = freshMatch(g, 1); |
| 79 | assert.ok(almost(l.comboBonus, pct / 100, 1e-12), 'combo ' + combo); |
| 80 | assert.ok(almost(l.jumpHeight, base() * (1 + pct / 100), 1e-9)); |
| 81 | assert.equal(g.lastChainIndicator.bonusPct, pct); |
| 82 | } |
| 83 | const g = makeGame({ noSpawn: true }); |
| 84 | g.combo = 50; |
| 85 | assert.equal(g.comboBonusPct(), 30); |
| 86 | }); |
| 87 | |
| 88 | it('the cap does not touch the landing chain (chain 1 + capped combo = +55%)', () => |
| 89 | { |
| 90 | const g = makeGame({ noSpawn: true }); |
| 91 | g.combo = 40; |
| 92 | g.place(0, 0, 2); |
| 93 | g.place(1, 0, 2); |
| 94 | const cluster = { id: g.nextClusterId++, jumpHeight: 3, vy: 0, decel: 0, phase: 'down', landingChain: 0 }; |
| 95 | g.clusters[cluster.id] = cluster; |
| 96 | const b = g.createBlock(2, 0, 2, 'flying'); |
| 97 | b.clusterId = cluster.id; |
| 98 | g.landCluster(cluster, [b]); |
| 99 | const l = g.resolveMatches()[0]; |
| 100 | assert.ok(almost(l.chainBonus, 1.55, 1e-12)); |
| 101 | }); |
| 102 | |
| 103 | it('HUD number (t1200) is only the combo part: 0.01 * min(combo, 30), landing chain excluded', () => |
| 104 | { |
| 105 | const g = makeGame({ noSpawn: true }); |
| 106 | assert.equal(g.comboBonusPct(), 0, 'nothing to show before a match'); |
| 107 | freshMatch(g, 1); |
| 108 | assert.equal(g.comboBonusPct(), 1); |
| 109 | g.combo = 2; |
| 110 | g.place(0, 0, 2); |
| 111 | g.place(1, 0, 2); |
| 112 | const cluster = { id: g.nextClusterId++, jumpHeight: 3, vy: 0, decel: 0, phase: 'down', landingChain: 0 }; |
| 113 | g.clusters[cluster.id] = cluster; |
| 114 | const b = g.createBlock(2, 0, 2, 'flying'); |
| 115 | b.clusterId = cluster.id; |
| 116 | g.landCluster(cluster, [b]); |
| 117 | const l = g.resolveMatches()[0]; |
| 118 | assert.ok(almost(l.chainBonus, 1.27, 1e-12), 'jump still gets chain + combo'); |
| 119 | assert.equal(g.comboBonusPct(), 3, 'HUD shows only the combo (3 matches), not +27%'); |
| 120 | g.combo = 45; |
| 121 | assert.equal(g.comboBonusPct(), 30, 'capped'); |
| 122 | for (let t = 0; t < 5.1; t += 0.05) g.tick(0.05); |
| 123 | assert.equal(g.comboBonusPct(), 0, 'hidden again after the combo resets'); |
| 124 | }); |
| 125 | |
| 126 | it('resets after 5 s without a match, not before', () => |
| 127 | { |
| 128 | const g = makeGame({ noSpawn: true }); |
| 129 | freshMatch(g, 1); |
| 130 | freshMatch(g, 2); |
| 131 | assert.equal(g.combo, 2); |
| 132 | run(g, 4.9); |
| 133 | assert.equal(g.combo, 2, 'still alive at 4.9 s'); |
| 134 | freshMatch(g, 3); // a match restarts the 5 s window |
| 135 | assert.equal(g.combo, 3); |
| 136 | run(g, 4.0); |
| 137 | assert.equal(g.combo, 3); |
| 138 | run(g, 1.1); |
| 139 | assert.equal(g.combo, 0, 'gone after 5 s without a match'); |
| 140 | const l = freshMatch(g, 1); |
| 141 | assert.equal(l.comboBonus, 0); |
| 142 | }); |
| 143 | |
| 144 | it('bots share it: an offline bot core is a GameCore with the same combo', () => |
| 145 | { |
| 146 | const Offline = require('../src/offline.js'); |
| 147 | const battle = Offline.createBattle({ playerPlanet: Planet.defaultPlanet(), rng: () => 0.5 }); |
| 148 | const bot = battle.bots[0].core; |
| 149 | assert.equal(bot.combo, 0); |
| 150 | assert.equal(typeof bot.comboBonusPct, 'function'); |
| 151 | }); |
| 152 | }); |
projects-timfalken-com meteors