BlueGit

projects-timfalken-com meteors

t1187/t1188: spawn interval shrinks 0.3% per spawn, floor 0.1 s

timfa Grok Bot · pushed by timfa

Authored 2026-11-14 · 3 days ago

Hash
720302f6d24b7c090cbb10c97b5446de05f3b82f
Parent
ebe7d4b8
1 file changed +76 −0
test/spawn-speedup.test.js added +76 −0
@@ -0,0 +1,76 @@
1 'use strict';
2
3 // t1187 / t1188: spawn interval shrinks 0.3% per spawned block, floor 0.1 s.
4
5 const { describe, it } = require('node:test');
6 const assert = require('node:assert/strict');
7 const { makeGame, almost, Planet } = require('./helpers.js');
8 const { GameCore } = require('../src/gameCore.js');
9
10 describe('Spawn speed-up (t1187/t1188)', () =>
11 {
12 it('constants: start 1 s, factor 0.997, floor 0.1 s', () =>
13 {
14 assert.equal(Planet.SPAWN_INTERVAL, 1);
15 assert.equal(GameCore.SPAWN_SPEEDUP, 0.997);
16 assert.equal(GameCore.SPAWN_INTERVAL_MIN, 0.1);
17 const g = makeGame({ seed: 1 });
18 assert.equal(g.spawnInterval, 1);
19 });
20
21 it('every spawned block multiplies the interval by 0.997', () =>
22 {
23 const g = makeGame({ seed: 2 });
24 const b1 = g.trySpawn();
25 assert.ok(b1);
26 assert.ok(almost(g.spawnInterval, 0.997, 1e-12));
27 g.trySpawn();
28 assert.ok(almost(g.spawnInterval, 0.997 * 0.997, 1e-12));
29 });
30
31 it('no spawn (no open column) → no speed-up', () =>
32 {
33 const g = makeGame({ seed: 3 });
34 for (let c = 0; c < g.width; c++)
35 { g.createBlock(c, 12, 0, 'falling'); }
36 assert.equal(g.trySpawn(), null);
37 assert.equal(g.spawnInterval, 1);
38 });
39
40 it('floors at 0.1 s after ~767 spawns', () =>
41 {
42 const g = makeGame({ seed: 4 });
43 let n = 0;
44 while (g.spawnInterval > GameCore.SPAWN_INTERVAL_MIN + 1e-12 && n < 5000)
45 {
46 g.speedUpSpawning();
47 n++;
48 }
49 assert.equal(g.spawnInterval, 0.1);
50 assert.ok(n >= 766 && n <= 768, 'spawns to floor: ' + n);
51 g.speedUpSpawning();
52 assert.equal(g.spawnInterval, 0.1, 'never below the floor');
53 // Total time to the floor ≈ sum of intervals ≈ 300 s.
54 let total = 0, iv = 1;
55 for (let i = 0; i < n; i++) { total += iv; iv = Math.max(0.1, iv * 0.997); }
56 assert.ok(total > 290 && total < 310, 'seconds to floor ' + total.toFixed(1));
57 });
58
59 it('the game tick spawns faster over time (driven by the same logic)', () =>
60 {
61 const g = makeGame({ seed: 5 });
62 g.trySpawn = (function (orig) { let count = 0; const f = function () { const b = orig.call(this); if (b) { count++; this.removeBlock(b); } return b; }; f.count = () => count; return f; })(g.trySpawn);
63 for (let i = 0; i < 60 * 120; i++) g.tick(1 / 60);
64 const spawned = g.trySpawn.count();
65 assert.ok(spawned >= 140 && spawned <= 155, '120 s gives ~149 spawns instead of 120: ' + spawned);
66 assert.ok(almost(g.spawnInterval, Math.max(0.1, Math.pow(0.997, spawned)), 1e-9));
67 });
68
69 it('a new game (new core) starts again at 1 s', () =>
70 {
71 const g = makeGame({ seed: 6 });
72 for (let i = 0; i < 100; i++) g.speedUpSpawning();
73 assert.ok(g.spawnInterval < 0.75);
74 assert.equal(makeGame({ seed: 6 }).spawnInterval, 1);
75 });
76 });
@@ -0,0 +1,76 @@
1'use strict';
2
3// t1187 / t1188: spawn interval shrinks 0.3% per spawned block, floor 0.1 s.
4
5const { describe, it } = require('node:test');
6const assert = require('node:assert/strict');
7const { makeGame, almost, Planet } = require('./helpers.js');
8const { GameCore } = require('../src/gameCore.js');
9
10describe('Spawn speed-up (t1187/t1188)', () =>
11{
12 it('constants: start 1 s, factor 0.997, floor 0.1 s', () =>
13 {
14 assert.equal(Planet.SPAWN_INTERVAL, 1);
15 assert.equal(GameCore.SPAWN_SPEEDUP, 0.997);
16 assert.equal(GameCore.SPAWN_INTERVAL_MIN, 0.1);
17 const g = makeGame({ seed: 1 });
18 assert.equal(g.spawnInterval, 1);
19 });
20
21 it('every spawned block multiplies the interval by 0.997', () =>
22 {
23 const g = makeGame({ seed: 2 });
24 const b1 = g.trySpawn();
25 assert.ok(b1);
26 assert.ok(almost(g.spawnInterval, 0.997, 1e-12));
27 g.trySpawn();
28 assert.ok(almost(g.spawnInterval, 0.997 * 0.997, 1e-12));
29 });
30
31 it('no spawn (no open column) → no speed-up', () =>
32 {
33 const g = makeGame({ seed: 3 });
34 for (let c = 0; c < g.width; c++)
35 { g.createBlock(c, 12, 0, 'falling'); }
36 assert.equal(g.trySpawn(), null);
37 assert.equal(g.spawnInterval, 1);
38 });
39
40 it('floors at 0.1 s after ~767 spawns', () =>
41 {
42 const g = makeGame({ seed: 4 });
43 let n = 0;
44 while (g.spawnInterval > GameCore.SPAWN_INTERVAL_MIN + 1e-12 && n < 5000)
45 {
46 g.speedUpSpawning();
47 n++;
48 }
49 assert.equal(g.spawnInterval, 0.1);
50 assert.ok(n >= 766 && n <= 768, 'spawns to floor: ' + n);
51 g.speedUpSpawning();
52 assert.equal(g.spawnInterval, 0.1, 'never below the floor');
53 // Total time to the floor ≈ sum of intervals ≈ 300 s.
54 let total = 0, iv = 1;
55 for (let i = 0; i < n; i++) { total += iv; iv = Math.max(0.1, iv * 0.997); }
56 assert.ok(total > 290 && total < 310, 'seconds to floor ' + total.toFixed(1));
57 });
58
59 it('the game tick spawns faster over time (driven by the same logic)', () =>
60 {
61 const g = makeGame({ seed: 5 });
62 g.trySpawn = (function (orig) { let count = 0; const f = function () { const b = orig.call(this); if (b) { count++; this.removeBlock(b); } return b; }; f.count = () => count; return f; })(g.trySpawn);
63 for (let i = 0; i < 60 * 120; i++) g.tick(1 / 60);
64 const spawned = g.trySpawn.count();
65 assert.ok(spawned >= 140 && spawned <= 155, '120 s gives ~149 spawns instead of 120: ' + spawned);
66 assert.ok(almost(g.spawnInterval, Math.max(0.1, Math.pow(0.997, spawned)), 1e-9));
67 });
68
69 it('a new game (new core) starts again at 1 s', () =>
70 {
71 const g = makeGame({ seed: 6 });
72 for (let i = 0; i < 100; i++) g.speedUpSpawning();
73 assert.ok(g.spawnInterval < 0.75);
74 assert.equal(makeGame({ seed: 6 }).spawnInterval, 1);
75 });
76});