feat: reward spawn rate 10 + 5t blocks/s (RATE0 = 10, ACCEL = 5, t1177)
@@ -10,7 +10,7 @@
10
10
* Spawn rate accelerates: rate(t) = RATE0 + ACCEL·t blocks/s, so the
11
11
* number spawned after t seconds is N(t) = RATE0·t + ACCEL·t²/2, and
12
12
* block i (0-based) leaves at T(i) = the t where N(t) = i.
13
* 253 points → the last block leaves at ≈ 11.4 s (t1175: ACCEL = 3).
13
* t1177: RATE0 = 10, ACCEL = 5 → 253 points ≈ 8.3 s, 800 = 16 s, 2000 ≈ 26.4 s.
14
14
*
15
15
* The pure timing / sequencing part (Reward.spawnTime, Reward.createSequence)
16
16
* has no DOM and is unit-tested. Reward.play wires it to an overlay.
@@ -19,9 +19,10 @@
19
19
{
20
20
'use strict';
21
21
22
var RATE0 = 5; // blocks per second at t = 0
23
/** Rate increase in blocks/s per second (t1175: was 1, now 3). */
24
var ACCEL = 3;
22
/** Blocks per second at t = 0 (t1177: was 5, now 10). */
23
var RATE0 = 10;
24
/** Rate increase in blocks/s per second (t1175: 3, t1177: 5). */
25
var ACCEL = 5;
25
26
var INTRO = 1.0; // centred title before it rises
26
27
var RISE = 0.6; // title tween to the top
27
28
var FLIGHT = 0.7; // one block's arc duration
@@ -10,7 +10,7 @@10
* Spawn rate accelerates: rate(t) = RATE0 + ACCEL·t blocks/s, so the10
* Spawn rate accelerates: rate(t) = RATE0 + ACCEL·t blocks/s, so the11
* number spawned after t seconds is N(t) = RATE0·t + ACCEL·t²/2, and11
* number spawned after t seconds is N(t) = RATE0·t + ACCEL·t²/2, and12
* block i (0-based) leaves at T(i) = the t where N(t) = i.12
* block i (0-based) leaves at T(i) = the t where N(t) = i.13
* 253 points → the last block leaves at ≈ 11.4 s (t1175: ACCEL = 3).13
* t1177: RATE0 = 10, ACCEL = 5 → 253 points ≈ 8.3 s, 800 = 16 s, 2000 ≈ 26.4 s.14
*14
*15
* The pure timing / sequencing part (Reward.spawnTime, Reward.createSequence)15
* The pure timing / sequencing part (Reward.spawnTime, Reward.createSequence)16
* has no DOM and is unit-tested. Reward.play wires it to an overlay.16
* has no DOM and is unit-tested. Reward.play wires it to an overlay.@@ -19,9 +19,10 @@19
{19
{20
'use strict';20
'use strict';21
21
22
var RATE0 = 5; // blocks per second at t = 022
/** Blocks per second at t = 0 (t1177: was 5, now 10). */23
/** Rate increase in blocks/s per second (t1175: was 1, now 3). */23
var RATE0 = 10;24
var ACCEL = 3;24
/** Rate increase in blocks/s per second (t1175: 3, t1177: 5). */25
var ACCEL = 5;25
var INTRO = 1.0; // centred title before it rises26
var INTRO = 1.0; // centred title before it rises26
var RISE = 0.6; // title tween to the top27
var RISE = 0.6; // title tween to the top27
var FLIGHT = 0.7; // one block's arc duration28
var FLIGHT = 0.7; // one block's arc duration@@ -28,17 +28,17 @@ function runToEnd (seq, dt, maxT)
28
28
return { events, t, spawned, arrived, monotonic, last: events[events.length - 1] };
29
29
}
30
30
31
describe('Reward spawn schedule (t1175: 5 + 3t blocks/s)', () =>
31
describe('Reward spawn schedule (t1177: 10 + 5t blocks/s)', () =>
32
32
{
33
it('block i leaves when 5t + 3t²/2 = i', () =>
33
it('block i leaves when 10t + 5t²/2 = i', () =>
34
34
{
35
assert.equal(Reward.RATE0, 5);
36
assert.equal(Reward.ACCEL, 3);
35
assert.equal(Reward.RATE0, 10);
36
assert.equal(Reward.ACCEL, 5);
37
37
assert.equal(Reward.spawnTime(0), 0);
38
38
for (const i of [1, 5, 10, 50, 100, 252, 1000])
39
39
{
40
40
const t = Reward.spawnTime(i);
41
assert.ok(Math.abs(5 * t + 3 * t * t / 2 - i) < 1e-9, 'i=' + i + ' t=' + t);
41
assert.ok(Math.abs(10 * t + 5 * t * t / 2 - i) < 1e-9, 'i=' + i + ' t=' + t);
42
42
}
43
43
// spawn times strictly increase, gaps shrink (accelerating)
44
44
let prevGap = Infinity;
@@ -51,24 +51,26 @@ describe('Reward spawn schedule (t1175: 5 + 3t blocks/s)', () =>
51
51
}
52
52
});
53
53
54
it('starts at 5/s and the 253rd block leaves at ≈ 11.4 s (Tim\'s example)', () =>
54
it('starts at 10/s; 253 ≈ 8.3 s, 800 = 16 s, 2000 ≈ 26.4 s (Tim\'s examples)', () =>
55
55
{
56
56
// 1/5 s between the first two blocks.
57
assert.ok(Math.abs(Reward.spawnTime(1) - (-5 + Math.sqrt(31)) / 3) < 1e-12);
58
assert.ok(Reward.spawnTime(1) > 0.18 && Reward.spawnTime(1) < 0.2);
59
const last = (-5 + Math.sqrt(25 + 6 * 252)) / 3;
57
assert.ok(Math.abs(Reward.spawnTime(1) - (-10 + Math.sqrt(110)) / 5) < 1e-12);
58
assert.ok(Reward.spawnTime(1) > 0.09 && Reward.spawnTime(1) < 0.1);
59
const last = (-10 + Math.sqrt(100 + 10 * 252)) / 5;
60
60
assert.ok(Math.abs(Reward.spawnTime(252) - last) < 1e-9);
61
assert.ok(last > 11.3 && last < 11.5, 'last=' + last);
61
assert.ok(last > 8.2 && last < 8.35, 'last=' + last);
62
assert.ok(Math.abs(Reward.spawnTime(799) - 16) < 0.02, '800: ' + Reward.spawnTime(799));
63
assert.ok(Math.abs(Reward.spawnTime(1999) - 26.4) < 0.1, '2000: ' + Reward.spawnTime(1999));
62
64
assert.equal(Reward.spawnedBy(last + 1e-6, 253), 253);
63
65
assert.equal(Reward.spawnedBy(last - 0.01, 253), 252);
64
66
assert.ok(Math.abs(Reward.countDuration(253) - (last + Reward.FLIGHT)) < 1e-9);
65
67
});
66
68
67
it('spawnedBy matches floor(5t + 3t²/2) + 1, capped by n', () =>
69
it('spawnedBy matches floor(10t + 5t²/2) + 1, capped by n', () =>
68
70
{
69
71
for (let t = 0; t <= 20; t += 0.37)
70
72
{
71
const expect = Math.min(253, Math.floor(5 * t + 3 * t * t / 2 + 1e-9) + 1);
73
const expect = Math.min(253, Math.floor(10 * t + 5 * t * t / 2 + 1e-9) + 1);
72
74
assert.equal(Reward.spawnedBy(t, 253), expect, 't=' + t);
73
75
}
74
76
assert.equal(Reward.spawnedBy(-1, 10), 0);
@@ -81,7 +83,7 @@ describe('Reward spawn schedule (t1175: 5 + 3t blocks/s)', () =>
81
83
82
84
describe('Reward sequence (t1173)', () =>
83
85
{
84
it('500 + 253 → counts every point from 500 up to 753 in ~12.1 s', () =>
86
it('500 + 253 → counts every point from 500 up to 753 in ~9 s of counting', () =>
85
87
{
86
88
const seq = Reward.createSequence({ won: true });
87
89
seq.setResult({ before: 500, after: 753 });
@@ -28,17 +28,17 @@ function runToEnd (seq, dt, maxT)28
return { events, t, spawned, arrived, monotonic, last: events[events.length - 1] };28
return { events, t, spawned, arrived, monotonic, last: events[events.length - 1] };29
}29
}30
30
31
describe('Reward spawn schedule (t1175: 5 + 3t blocks/s)', () =>31
describe('Reward spawn schedule (t1177: 10 + 5t blocks/s)', () =>32
{32
{33
it('block i leaves when 5t + 3t²/2 = i', () =>33
it('block i leaves when 10t + 5t²/2 = i', () =>34
{34
{35
assert.equal(Reward.RATE0, 5);35
assert.equal(Reward.RATE0, 10);36
assert.equal(Reward.ACCEL, 3);36
assert.equal(Reward.ACCEL, 5);37
assert.equal(Reward.spawnTime(0), 0);37
assert.equal(Reward.spawnTime(0), 0);38
for (const i of [1, 5, 10, 50, 100, 252, 1000])38
for (const i of [1, 5, 10, 50, 100, 252, 1000])39
{39
{40
const t = Reward.spawnTime(i);40
const t = Reward.spawnTime(i);41
assert.ok(Math.abs(5 * t + 3 * t * t / 2 - i) < 1e-9, 'i=' + i + ' t=' + t);41
assert.ok(Math.abs(10 * t + 5 * t * t / 2 - i) < 1e-9, 'i=' + i + ' t=' + t);42
}42
}43
// spawn times strictly increase, gaps shrink (accelerating)43
// spawn times strictly increase, gaps shrink (accelerating)44
let prevGap = Infinity;44
let prevGap = Infinity;@@ -51,24 +51,26 @@ describe('Reward spawn schedule (t1175: 5 + 3t blocks/s)', () =>51
}51
}52
});52
});53
53
54
it('starts at 5/s and the 253rd block leaves at ≈ 11.4 s (Tim\'s example)', () =>54
it('starts at 10/s; 253 ≈ 8.3 s, 800 = 16 s, 2000 ≈ 26.4 s (Tim\'s examples)', () =>55
{55
{56
// 1/5 s between the first two blocks.56
// 1/5 s between the first two blocks.57
assert.ok(Math.abs(Reward.spawnTime(1) - (-5 + Math.sqrt(31)) / 3) < 1e-12);57
assert.ok(Math.abs(Reward.spawnTime(1) - (-10 + Math.sqrt(110)) / 5) < 1e-12);58
assert.ok(Reward.spawnTime(1) > 0.18 && Reward.spawnTime(1) < 0.2);58
assert.ok(Reward.spawnTime(1) > 0.09 && Reward.spawnTime(1) < 0.1);59
const last = (-5 + Math.sqrt(25 + 6 * 252)) / 3;59
const last = (-10 + Math.sqrt(100 + 10 * 252)) / 5;60
assert.ok(Math.abs(Reward.spawnTime(252) - last) < 1e-9);60
assert.ok(Math.abs(Reward.spawnTime(252) - last) < 1e-9);61
assert.ok(last > 11.3 && last < 11.5, 'last=' + last);61
assert.ok(last > 8.2 && last < 8.35, 'last=' + last);62
assert.ok(Math.abs(Reward.spawnTime(799) - 16) < 0.02, '800: ' + Reward.spawnTime(799));63
assert.ok(Math.abs(Reward.spawnTime(1999) - 26.4) < 0.1, '2000: ' + Reward.spawnTime(1999));62
assert.equal(Reward.spawnedBy(last + 1e-6, 253), 253);64
assert.equal(Reward.spawnedBy(last + 1e-6, 253), 253);63
assert.equal(Reward.spawnedBy(last - 0.01, 253), 252);65
assert.equal(Reward.spawnedBy(last - 0.01, 253), 252);64
assert.ok(Math.abs(Reward.countDuration(253) - (last + Reward.FLIGHT)) < 1e-9);66
assert.ok(Math.abs(Reward.countDuration(253) - (last + Reward.FLIGHT)) < 1e-9);65
});67
});66
68
67
it('spawnedBy matches floor(5t + 3t²/2) + 1, capped by n', () =>69
it('spawnedBy matches floor(10t + 5t²/2) + 1, capped by n', () =>68
{70
{69
for (let t = 0; t <= 20; t += 0.37)71
for (let t = 0; t <= 20; t += 0.37)70
{72
{71
const expect = Math.min(253, Math.floor(5 * t + 3 * t * t / 2 + 1e-9) + 1);73
const expect = Math.min(253, Math.floor(10 * t + 5 * t * t / 2 + 1e-9) + 1);72
assert.equal(Reward.spawnedBy(t, 253), expect, 't=' + t);74
assert.equal(Reward.spawnedBy(t, 253), expect, 't=' + t);73
}75
}74
assert.equal(Reward.spawnedBy(-1, 10), 0);76
assert.equal(Reward.spawnedBy(-1, 10), 0);@@ -81,7 +83,7 @@ describe('Reward spawn schedule (t1175: 5 + 3t blocks/s)', () =>81
83
82
describe('Reward sequence (t1173)', () =>84
describe('Reward sequence (t1173)', () =>83
{85
{84
it('500 + 253 → counts every point from 500 up to 753 in ~12.1 s', () =>86
it('500 + 253 → counts every point from 500 up to 753 in ~9 s of counting', () =>85
{87
{86
const seq = Reward.createSequence({ won: true });88
const seq = Reward.createSequence({ won: true });87
seq.setResult({ before: 500, after: 753 });89
seq.setResult({ before: 500, after: 753 });