feat: reward spawn rate accelerates by 3 blocks/s per second (ACCEL = 3, t1175)
@@ -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 exactly 18 s.
13
* 253 points → the last block leaves at ≈ 11.4 s (t1175: ACCEL = 3).
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.
@@ -20,7 +20,8 @@
20
20
'use strict';
21
21
22
22
var RATE0 = 5; // blocks per second at t = 0
23
var ACCEL = 1; // +1 block/s every second
23
/** Rate increase in blocks/s per second (t1175: was 1, now 3). */
24
var ACCEL = 3;
24
25
var INTRO = 1.0; // centred title before it rises
25
26
var RISE = 0.6; // title tween to the top
26
27
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 exactly 18 s.13
* 253 points → the last block leaves at ≈ 11.4 s (t1175: ACCEL = 3).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.@@ -20,7 +20,8 @@20
'use strict';20
'use strict';21
21
22
var RATE0 = 5; // blocks per second at t = 022
var RATE0 = 5; // blocks per second at t = 023
var ACCEL = 1; // +1 block/s every second23
/** Rate increase in blocks/s per second (t1175: was 1, now 3). */24
var ACCEL = 3;24
var INTRO = 1.0; // centred title before it rises25
var INTRO = 1.0; // centred title before it rises25
var RISE = 0.6; // title tween to the top26
var RISE = 0.6; // title tween to the top26
var FLIGHT = 0.7; // one block's arc duration27
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 (t1174: 5 + t blocks/s)', () =>
31
describe('Reward spawn schedule (t1175: 5 + 3t blocks/s)', () =>
32
32
{
33
it('block i leaves when 5t + t²/2 = i', () =>
33
it('block i leaves when 5t + 3t²/2 = i', () =>
34
34
{
35
35
assert.equal(Reward.RATE0, 5);
36
assert.equal(Reward.ACCEL, 1);
36
assert.equal(Reward.ACCEL, 3);
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 + t * t / 2 - i) < 1e-9, 'i=' + i + ' t=' + t);
41
assert.ok(Math.abs(5 * t + 3 * 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,22 +51,24 @@ describe('Reward spawn schedule (t1174: 5 + t blocks/s)', () =>
51
51
}
52
52
});
53
53
54
it('starts at 5/s and the 253rd block leaves at 18 s (Tim\'s example)', () =>
54
it('starts at 5/s and the 253rd block leaves at ≈ 11.4 s (Tim\'s example)', () =>
55
55
{
56
56
// 1/5 s between the first two blocks.
57
assert.ok(Math.abs(Reward.spawnTime(1) - (-5 + Math.sqrt(27))) < 1e-12);
58
assert.ok(Reward.spawnTime(1) > 0.19 && Reward.spawnTime(1) < 0.2);
59
assert.ok(Math.abs(Reward.spawnTime(252) - 18) < 1e-9);
60
assert.equal(Reward.spawnedBy(18, 253), 253);
61
assert.equal(Reward.spawnedBy(17.99, 253), 252);
62
assert.ok(Math.abs(Reward.countDuration(253) - (18 + Reward.FLIGHT)) < 1e-9);
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;
60
assert.ok(Math.abs(Reward.spawnTime(252) - last) < 1e-9);
61
assert.ok(last > 11.3 && last < 11.5, 'last=' + last);
62
assert.equal(Reward.spawnedBy(last + 1e-6, 253), 253);
63
assert.equal(Reward.spawnedBy(last - 0.01, 253), 252);
64
assert.ok(Math.abs(Reward.countDuration(253) - (last + Reward.FLIGHT)) < 1e-9);
63
65
});
64
66
65
it('spawnedBy matches floor(5t + t²/2) + 1, capped by n', () =>
67
it('spawnedBy matches floor(5t + 3t²/2) + 1, capped by n', () =>
66
68
{
67
69
for (let t = 0; t <= 20; t += 0.37)
68
70
{
69
const expect = Math.min(253, Math.floor(5 * t + t * t / 2 + 1e-9) + 1);
71
const expect = Math.min(253, Math.floor(5 * t + 3 * t * t / 2 + 1e-9) + 1);
70
72
assert.equal(Reward.spawnedBy(t, 253), expect, 't=' + t);
71
73
}
72
74
assert.equal(Reward.spawnedBy(-1, 10), 0);
@@ -79,7 +81,7 @@ describe('Reward spawn schedule (t1174: 5 + t blocks/s)', () =>
79
81
80
82
describe('Reward sequence (t1173)', () =>
81
83
{
82
it('500 + 253 → counts every point from 500 up to 753 in ~18.7 s', () =>
84
it('500 + 253 → counts every point from 500 up to 753 in ~12.1 s', () =>
83
85
{
84
86
const seq = Reward.createSequence({ won: true });
85
87
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 (t1174: 5 + t blocks/s)', () =>31
describe('Reward spawn schedule (t1175: 5 + 3t blocks/s)', () =>32
{32
{33
it('block i leaves when 5t + t²/2 = i', () =>33
it('block i leaves when 5t + 3t²/2 = i', () =>34
{34
{35
assert.equal(Reward.RATE0, 5);35
assert.equal(Reward.RATE0, 5);36
assert.equal(Reward.ACCEL, 1);36
assert.equal(Reward.ACCEL, 3);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 + t * t / 2 - i) < 1e-9, 'i=' + i + ' t=' + t);41
assert.ok(Math.abs(5 * t + 3 * 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,22 +51,24 @@ describe('Reward spawn schedule (t1174: 5 + t blocks/s)', () =>51
}51
}52
});52
});53
53
54
it('starts at 5/s and the 253rd block leaves at 18 s (Tim\'s example)', () =>54
it('starts at 5/s and the 253rd block leaves at ≈ 11.4 s (Tim\'s example)', () =>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(27))) < 1e-12);57
assert.ok(Math.abs(Reward.spawnTime(1) - (-5 + Math.sqrt(31)) / 3) < 1e-12);58
assert.ok(Reward.spawnTime(1) > 0.19 && Reward.spawnTime(1) < 0.2);58
assert.ok(Reward.spawnTime(1) > 0.18 && Reward.spawnTime(1) < 0.2);59
assert.ok(Math.abs(Reward.spawnTime(252) - 18) < 1e-9);59
const last = (-5 + Math.sqrt(25 + 6 * 252)) / 3;60
assert.equal(Reward.spawnedBy(18, 253), 253);60
assert.ok(Math.abs(Reward.spawnTime(252) - last) < 1e-9);61
assert.equal(Reward.spawnedBy(17.99, 253), 252);61
assert.ok(last > 11.3 && last < 11.5, 'last=' + last);62
assert.ok(Math.abs(Reward.countDuration(253) - (18 + Reward.FLIGHT)) < 1e-9);62
assert.equal(Reward.spawnedBy(last + 1e-6, 253), 253);63
assert.equal(Reward.spawnedBy(last - 0.01, 253), 252);64
assert.ok(Math.abs(Reward.countDuration(253) - (last + Reward.FLIGHT)) < 1e-9);63
});65
});64
66
65
it('spawnedBy matches floor(5t + t²/2) + 1, capped by n', () =>67
it('spawnedBy matches floor(5t + 3t²/2) + 1, capped by n', () =>66
{68
{67
for (let t = 0; t <= 20; t += 0.37)69
for (let t = 0; t <= 20; t += 0.37)68
{70
{69
const expect = Math.min(253, Math.floor(5 * t + t * t / 2 + 1e-9) + 1);71
const expect = Math.min(253, Math.floor(5 * t + 3 * t * t / 2 + 1e-9) + 1);70
assert.equal(Reward.spawnedBy(t, 253), expect, 't=' + t);72
assert.equal(Reward.spawnedBy(t, 253), expect, 't=' + t);71
}73
}72
assert.equal(Reward.spawnedBy(-1, 10), 0);74
assert.equal(Reward.spawnedBy(-1, 10), 0);@@ -79,7 +81,7 @@ describe('Reward spawn schedule (t1174: 5 + t blocks/s)', () =>79
81
80
describe('Reward sequence (t1173)', () =>82
describe('Reward sequence (t1173)', () =>81
{83
{82
it('500 + 253 → counts every point from 500 up to 753 in ~18.7 s', () =>84
it('500 + 253 → counts every point from 500 up to 753 in ~12.1 s', () =>83
{85
{84
const seq = Reward.createSequence({ won: true });86
const seq = Reward.createSequence({ won: true });85
seq.setResult({ before: 500, after: 753 });87
seq.setResult({ before: 500, after: 753 });