t1194: reward blocks start at 3/s, acceleration per reward so the last block leaves at 4 s
@@ -7,10 +7,15 @@
7
7
* planet arc from the top of the screen into a counter at the bottom
8
8
* centre, one block per newly earned point. Each arrival adds 1.
9
9
*
10
* Spawn rate accelerates: rate(t) = RATE0 + ACCEL·t blocks/s, so the
11
* number spawned after t seconds is N(t) = RATE0·t + ACCEL·t²/2, and
12
* block i (0-based) leaves at T(i) = the t where N(t) = i.
13
* t1178: RATE0 = 15, ACCEL = 10 → 253 points ≈ 5.8 s, 800 ≈ 11.2 s, 2000 ≈ 18.6 s.
10
* Spawn rate (t1194): starts at RATE0 = 3 blocks/s and accelerates
11
* linearly, rate(t) = RATE0 + a·t, with `a` chosen per reward so the last
12
* block always leaves at SPAWN_END = 4 s, whatever the point count.
13
* Blocks spawned after t seconds: N(t) = RATE0·t + a·t²/2; block i
14
* (0-based) leaves at T(i) = the t where N(t) = i. The last block is
15
* i = n − 1, so N(4) = n − 1 → a = 2·((n − 1) − RATE0·T) / T².
16
* If n − 1 ≤ RATE0·T (n ≤ 13) a would be ≤ 0: then a constant rate
17
* (n − 1) / T is used (a = 0), so it still ends at 4 s (1 point: one
18
* block at t = 0).
14
19
*
15
20
* The pure timing / sequencing part (Reward.spawnTime, Reward.createSequence)
16
21
* has no DOM and is unit-tested. Reward.play wires it to an overlay.
@@ -19,10 +24,10 @@
19
24
{
20
25
'use strict';
21
26
22
/** Blocks per second at t = 0 (t1177: 10, t1178: 15). */
23
var RATE0 = 15;
24
/** Rate increase in blocks/s per second (t1175: 3, t1177: 5, t1178: 10). */
25
var ACCEL = 10;
27
/** Blocks per second at t = 0 (t1177: 10, t1178: 15, t1194: 3). */
28
var RATE0 = 3;
29
/** Seconds after the first block when the last block leaves (t1194). */
30
var SPAWN_END = 4;
26
31
var INTRO = 1.0; // centred title before it rises
27
32
var RISE = 0.6; // title tween to the top
28
33
var FLIGHT = 0.7; // one block's arc duration
@@ -30,14 +35,28 @@ var HOLD = 1.5; // final total shown before continuing
30
35
var HOLD_ZERO = 1.5; // earned 0: show the number briefly
31
36
var WAIT_MAX = 8; // give up waiting for the server after this
32
37
33
/** Seconds after the start of counting when block i (0-based) leaves. */
34
function spawnTime (i)
38
/**
39
* Spawn parameters for a reward of n blocks (t1194): { r0, a } with
40
* rate(t) = r0 + a·t and the last block (i = n − 1) leaving at SPAWN_END.
41
*/
42
function spawnParams (n)
43
{
44
var T = SPAWN_END;
45
var last = Math.max(0, (n | 0) - 1);
46
if (last <= RATE0 * T)
47
{ return { r0: last / T, a: 0 }; }
48
return { r0: RATE0, a: 2 * (last - RATE0 * T) / (T * T) };
49
}
50
51
/** Seconds after the start of counting when block i (0-based) of n leaves. */
52
function spawnTime (i, n)
35
53
{
36
54
if (!(i > 0))
37
55
{ return 0; }
38
if (ACCEL === 0)
39
{ return i / RATE0; }
40
return (-RATE0 + Math.sqrt(RATE0 * RATE0 + 2 * ACCEL * i)) / ACCEL;
56
var p = spawnParams(n == null ? i + 1 : n);
57
if (p.a === 0)
58
{ return p.r0 > 0 ? i / p.r0 : 0; }
59
return (-p.r0 + Math.sqrt(p.r0 * p.r0 + 2 * p.a * i)) / p.a;
41
60
}
42
61
43
62
/** Blocks spawned (left the top) by time t, capped at n. */
@@ -45,8 +64,9 @@ function spawnedBy (t, n)
45
64
{
46
65
if (!(t >= 0) || !(n > 0))
47
66
{ return 0; }
67
var p = spawnParams(n);
48
68
// Block i has left when T(i) <= t, i.e. i <= N(t).
49
var k = Math.floor(RATE0 * t + ACCEL * t * t / 2 + 1e-9) + 1;
69
var k = Math.floor(p.r0 * t + p.a * t * t / 2 + 1e-9) + 1;
50
70
return Math.min(n, Math.max(0, k));
51
71
}
52
72
@@ -63,7 +83,7 @@ function countDuration (n, flight)
63
83
flight = flight == null ? FLIGHT : flight;
64
84
if (!(n > 0))
65
85
{ return 0; }
66
return spawnTime(n - 1) + flight;
86
return spawnTime(n - 1, n) + flight;
67
87
}
68
88
69
89
/**
@@ -295,8 +315,9 @@ function play (opts)
295
315
var W = 0;
296
316
var H = 0;
297
317
298
title.textContent = opts.won ? tr('reward.won', 'You won!') : tr('reward.lost', 'You lost...');
299
title.className = 'reward-title' + (opts.won ? ' won' : ' lost');
318
// t1193: quitting via the in-game menu shows a neutral title.
319
title.textContent = opts.title ? String(opts.title) : (opts.won ? tr('reward.won', 'You won!') : tr('reward.lost', 'You lost...'));
320
title.className = 'reward-title' + (opts.title ? ' ended' : (opts.won ? ' won' : ' lost'));
300
321
if (label)
301
322
{ label.textContent = tr('reward.total', 'Total points'); }
302
323
counter.textContent = '';
@@ -482,7 +503,8 @@ function play (opts)
482
503
483
504
var Reward = {
484
505
RATE0: RATE0,
485
ACCEL: ACCEL,
506
SPAWN_END: SPAWN_END,
507
spawnParams: spawnParams,
486
508
INTRO: INTRO,
487
509
RISE: RISE,
488
510
FLIGHT: FLIGHT,
@@ -7,10 +7,15 @@7
* planet arc from the top of the screen into a counter at the bottom7
* planet arc from the top of the screen into a counter at the bottom8
* centre, one block per newly earned point. Each arrival adds 1.8
* centre, one block per newly earned point. Each arrival adds 1.9
*9
*10
* Spawn rate accelerates: rate(t) = RATE0 + ACCEL·t blocks/s, so the10
* Spawn rate (t1194): starts at RATE0 = 3 blocks/s and accelerates11
* number spawned after t seconds is N(t) = RATE0·t + ACCEL·t²/2, and11
* linearly, rate(t) = RATE0 + a·t, with `a` chosen per reward so the last12
* block i (0-based) leaves at T(i) = the t where N(t) = i.12
* block always leaves at SPAWN_END = 4 s, whatever the point count.13
* t1178: RATE0 = 15, ACCEL = 10 → 253 points ≈ 5.8 s, 800 ≈ 11.2 s, 2000 ≈ 18.6 s.13
* Blocks spawned after t seconds: N(t) = RATE0·t + a·t²/2; block i14
* (0-based) leaves at T(i) = the t where N(t) = i. The last block is15
* i = n − 1, so N(4) = n − 1 → a = 2·((n − 1) − RATE0·T) / T².16
* If n − 1 ≤ RATE0·T (n ≤ 13) a would be ≤ 0: then a constant rate17
* (n − 1) / T is used (a = 0), so it still ends at 4 s (1 point: one18
* block at t = 0).14
*19
*15
* The pure timing / sequencing part (Reward.spawnTime, Reward.createSequence)20
* The pure timing / sequencing part (Reward.spawnTime, Reward.createSequence)16
* has no DOM and is unit-tested. Reward.play wires it to an overlay.21
* has no DOM and is unit-tested. Reward.play wires it to an overlay.@@ -19,10 +24,10 @@19
{24
{20
'use strict';25
'use strict';21
26
22
/** Blocks per second at t = 0 (t1177: 10, t1178: 15). */27
/** Blocks per second at t = 0 (t1177: 10, t1178: 15, t1194: 3). */23
var RATE0 = 15;28
var RATE0 = 3;24
/** Rate increase in blocks/s per second (t1175: 3, t1177: 5, t1178: 10). */29
/** Seconds after the first block when the last block leaves (t1194). */25
var ACCEL = 10;30
var SPAWN_END = 4;26
var INTRO = 1.0; // centred title before it rises31
var INTRO = 1.0; // centred title before it rises27
var RISE = 0.6; // title tween to the top32
var RISE = 0.6; // title tween to the top28
var FLIGHT = 0.7; // one block's arc duration33
var FLIGHT = 0.7; // one block's arc duration@@ -30,14 +35,28 @@ var HOLD = 1.5; // final total shown before continuing30
var HOLD_ZERO = 1.5; // earned 0: show the number briefly35
var HOLD_ZERO = 1.5; // earned 0: show the number briefly31
var WAIT_MAX = 8; // give up waiting for the server after this36
var WAIT_MAX = 8; // give up waiting for the server after this32
37
33
/** Seconds after the start of counting when block i (0-based) leaves. */38
/**34
function spawnTime (i)39
* Spawn parameters for a reward of n blocks (t1194): { r0, a } with40
* rate(t) = r0 + a·t and the last block (i = n − 1) leaving at SPAWN_END.41
*/42
function spawnParams (n)43
{44
var T = SPAWN_END;45
var last = Math.max(0, (n | 0) - 1);46
if (last <= RATE0 * T)47
{ return { r0: last / T, a: 0 }; }48
return { r0: RATE0, a: 2 * (last - RATE0 * T) / (T * T) };49
}50
51
/** Seconds after the start of counting when block i (0-based) of n leaves. */52
function spawnTime (i, n)35
{53
{36
if (!(i > 0))54
if (!(i > 0))37
{ return 0; }55
{ return 0; }38
if (ACCEL === 0)56
var p = spawnParams(n == null ? i + 1 : n);39
{ return i / RATE0; }57
if (p.a === 0)40
return (-RATE0 + Math.sqrt(RATE0 * RATE0 + 2 * ACCEL * i)) / ACCEL;58
{ return p.r0 > 0 ? i / p.r0 : 0; }59
return (-p.r0 + Math.sqrt(p.r0 * p.r0 + 2 * p.a * i)) / p.a;41
}60
}42
61
43
/** Blocks spawned (left the top) by time t, capped at n. */62
/** Blocks spawned (left the top) by time t, capped at n. */@@ -45,8 +64,9 @@ function spawnedBy (t, n)45
{64
{46
if (!(t >= 0) || !(n > 0))65
if (!(t >= 0) || !(n > 0))47
{ return 0; }66
{ return 0; }67
var p = spawnParams(n);48
// Block i has left when T(i) <= t, i.e. i <= N(t).68
// Block i has left when T(i) <= t, i.e. i <= N(t).49
var k = Math.floor(RATE0 * t + ACCEL * t * t / 2 + 1e-9) + 1;69
var k = Math.floor(p.r0 * t + p.a * t * t / 2 + 1e-9) + 1;50
return Math.min(n, Math.max(0, k));70
return Math.min(n, Math.max(0, k));51
}71
}52
72
@@ -63,7 +83,7 @@ function countDuration (n, flight)63
flight = flight == null ? FLIGHT : flight;83
flight = flight == null ? FLIGHT : flight;64
if (!(n > 0))84
if (!(n > 0))65
{ return 0; }85
{ return 0; }66
return spawnTime(n - 1) + flight;86
return spawnTime(n - 1, n) + flight;67
}87
}68
88
69
/**89
/**@@ -295,8 +315,9 @@ function play (opts)295
var W = 0;315
var W = 0;296
var H = 0;316
var H = 0;297
317
298
title.textContent = opts.won ? tr('reward.won', 'You won!') : tr('reward.lost', 'You lost...');318
// t1193: quitting via the in-game menu shows a neutral title.299
title.className = 'reward-title' + (opts.won ? ' won' : ' lost');319
title.textContent = opts.title ? String(opts.title) : (opts.won ? tr('reward.won', 'You won!') : tr('reward.lost', 'You lost...'));320
title.className = 'reward-title' + (opts.title ? ' ended' : (opts.won ? ' won' : ' lost'));300
if (label)321
if (label)301
{ label.textContent = tr('reward.total', 'Total points'); }322
{ label.textContent = tr('reward.total', 'Total points'); }302
counter.textContent = '';323
counter.textContent = '';@@ -482,7 +503,8 @@ function play (opts)482
503
483
var Reward = {504
var Reward = {484
RATE0: RATE0,505
RATE0: RATE0,485
ACCEL: ACCEL,506
SPAWN_END: SPAWN_END,507
spawnParams: spawnParams,486
INTRO: INTRO,508
INTRO: INTRO,487
RISE: RISE,509
RISE: RISE,488
FLIGHT: FLIGHT,510
FLIGHT: FLIGHT,@@ -28,49 +28,60 @@ 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 (t1178: 15 + 10t blocks/s)', () =>
31
describe('Reward spawn schedule (t1194: 3 blocks/s, last block at 4 s)', () =>
32
32
{
33
it('block i leaves when 15t + 10t²/2 = i', () =>
33
it('constants and per-reward acceleration a = 2((n−1) − 3·4) / 4²', () =>
34
34
{
35
assert.equal(Reward.RATE0, 15);
36
assert.equal(Reward.ACCEL, 10);
37
assert.equal(Reward.spawnTime(0), 0);
38
for (const i of [1, 5, 10, 50, 100, 252, 1000])
35
assert.equal(Reward.RATE0, 3);
36
assert.equal(Reward.SPAWN_END, 4);
37
assert.deepEqual(Reward.spawnParams(253), { r0: 3, a: 2 * (252 - 12) / 16 });
38
assert.deepEqual(Reward.spawnParams(13), { r0: 3, a: 0 });
39
assert.deepEqual(Reward.spawnParams(5), { r0: 1, a: 0 }, 'n ≤ 13: constant (n−1)/4');
40
assert.deepEqual(Reward.spawnParams(1), { r0: 0, a: 0 });
41
});
42
43
it('the last block always leaves at 4 s, whatever the point count', () =>
44
{
45
for (const n of [2, 5, 12, 13, 14, 50, 253, 800, 2000, 10000])
46
{
47
const last = Reward.spawnTime(n - 1, n);
48
assert.ok(Math.abs(last - 4) < 1e-9, 'n=' + n + ' last=' + last);
49
assert.ok(Reward.spawnedBy(4 - 1e-3, n) < n, 'n=' + n + ' not all out just before 4 s');
50
assert.equal(Reward.spawnedBy(4 + 1e-6, n), n, 'n=' + n + ' at 4 s');
51
assert.ok(Math.abs(Reward.countDuration(n) - (4 + Reward.FLIGHT)) < 1e-9);
52
}
53
assert.equal(Reward.spawnTime(0, 1), 0);
54
assert.equal(Reward.countDuration(1), Reward.FLIGHT);
55
});
56
57
it('block i leaves when 3t + a·t²/2 = i; starts at 3/s and accelerates', () =>
58
{
59
const n = 253;
60
const { r0, a } = Reward.spawnParams(n);
61
for (const i of [1, 5, 10, 50, 100, 252])
39
62
{
40
const t = Reward.spawnTime(i);
41
assert.ok(Math.abs(15 * t + 10 * t * t / 2 - i) < 1e-9, 'i=' + i + ' t=' + t);
63
const t = Reward.spawnTime(i, n);
64
assert.ok(Math.abs(r0 * t + a * t * t / 2 - i) < 1e-9, 'i=' + i + ' t=' + t);
42
65
}
43
// spawn times strictly increase, gaps shrink (accelerating)
66
// First gap ≈ 1/3 s at the start rate (slightly less: it accelerates).
67
const g1 = Reward.spawnTime(1, n);
68
assert.ok(g1 < 1 / 3 && g1 > 0.1, 'first gap ' + g1);
44
69
let prevGap = Infinity;
45
for (let i = 1; i < 300; i++)
70
for (let i = 1; i < n; i++)
46
71
{
47
const gap = Reward.spawnTime(i) - Reward.spawnTime(i - 1);
72
const gap = Reward.spawnTime(i, n) - Reward.spawnTime(i - 1, n);
48
73
assert.ok(gap > 0);
49
74
assert.ok(gap <= prevGap + 1e-12, 'gap grew at ' + i);
50
75
prevGap = gap;
51
76
}
52
77
});
53
78
54
it('starts at 15/s; 253 ≈ 5.8 s, 800 ≈ 11.2 s, 2000 ≈ 18.6 s (Tim\'s examples)', () =>
55
{
56
// 1/5 s between the first two blocks.
57
assert.ok(Math.abs(Reward.spawnTime(1) - (-15 + Math.sqrt(245)) / 10) < 1e-12);
58
assert.ok(Reward.spawnTime(1) > 0.06 && Reward.spawnTime(1) < 0.067);
59
const last = (-15 + Math.sqrt(225 + 20 * 252)) / 10;
60
assert.ok(Math.abs(Reward.spawnTime(252) - last) < 1e-9);
61
assert.ok(last > 5.7 && last < 5.85, 'last=' + last);
62
assert.ok(Math.abs(Reward.spawnTime(799) - 11.2) < 0.05, '800: ' + Reward.spawnTime(799));
63
assert.ok(Math.abs(Reward.spawnTime(1999) - 18.6) < 0.1, '2000: ' + Reward.spawnTime(1999));
64
assert.equal(Reward.spawnedBy(last + 1e-6, 253), 253);
65
assert.equal(Reward.spawnedBy(last - 0.01, 253), 252);
66
assert.ok(Math.abs(Reward.countDuration(253) - (last + Reward.FLIGHT)) < 1e-9);
67
});
68
69
it('spawnedBy matches floor(15t + 10t²/2) + 1, capped by n', () =>
79
it('spawnedBy matches floor(r0·t + a·t²/2) + 1, capped by n', () =>
70
80
{
71
for (let t = 0; t <= 20; t += 0.37)
81
const { r0, a } = Reward.spawnParams(253);
82
for (let t = 0; t <= 6; t += 0.137)
72
83
{
73
const expect = Math.min(253, Math.floor(15 * t + 10 * t * t / 2 + 1e-9) + 1);
84
const expect = Math.min(253, Math.floor(r0 * t + a * t * t / 2 + 1e-9) + 1);
74
85
assert.equal(Reward.spawnedBy(t, 253), expect, 't=' + t);
75
86
}
76
87
assert.equal(Reward.spawnedBy(-1, 10), 0);
@@ -79,11 +90,37 @@ describe('Reward spawn schedule (t1178: 15 + 10t blocks/s)', () =>
79
90
assert.equal(Reward.arrivedBy(Reward.FLIGHT - 0.01, 10), 0);
80
91
assert.equal(Reward.arrivedBy(Reward.FLIGHT, 10), 1);
81
92
});
93
94
it('measured end times through the real sequence (60 fps): ~4 s for 5…2000 points', () =>
95
{
96
for (const n of [5, 50, 253, 800, 2000])
97
{
98
const seq = Reward.createSequence({ won: true });
99
seq.setResult({ before: 100, after: 100 + n });
100
let t = 0, firstSpawn = null, lastSpawn = null, lastArrive = null, prev = 0;
101
for (let k = 0; k < 60 * 30; k++)
102
{
103
const out = seq.tick(1 / 60);
104
t += 1 / 60;
105
if (out.spawn.length)
106
{
107
if (firstSpawn == null) firstSpawn = t;
108
lastSpawn = t;
109
}
110
if (seq.arrived === n && lastArrive == null && prev < n) lastArrive = t;
111
prev = seq.arrived;
112
if (out.done) break;
113
}
114
const spawnSpan = lastSpawn - firstSpawn;
115
assert.ok(Math.abs(spawnSpan - 4) < 0.05, 'n=' + n + ' last spawn after ' + spawnSpan.toFixed(3) + ' s');
116
assert.equal(seq.counter, 100 + n);
117
}
118
});
82
119
});
83
120
84
121
describe('Reward sequence (t1173)', () =>
85
122
{
86
it('500 + 253 → counts every point from 500 up to 753 in ~6.5 s of counting', () =>
123
it('500 + 253 → counts every point from 500 up to 753 (last block at 4 s)', () =>
87
124
{
88
125
const seq = Reward.createSequence({ won: true });
89
126
seq.setResult({ before: 500, after: 753 });
@@ -28,49 +28,60 @@ 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 (t1178: 15 + 10t blocks/s)', () =>31
describe('Reward spawn schedule (t1194: 3 blocks/s, last block at 4 s)', () =>32
{32
{33
it('block i leaves when 15t + 10t²/2 = i', () =>33
it('constants and per-reward acceleration a = 2((n−1) − 3·4) / 4²', () =>34
{34
{35
assert.equal(Reward.RATE0, 15);35
assert.equal(Reward.RATE0, 3);36
assert.equal(Reward.ACCEL, 10);36
assert.equal(Reward.SPAWN_END, 4);37
assert.equal(Reward.spawnTime(0), 0);37
assert.deepEqual(Reward.spawnParams(253), { r0: 3, a: 2 * (252 - 12) / 16 });38
for (const i of [1, 5, 10, 50, 100, 252, 1000])38
assert.deepEqual(Reward.spawnParams(13), { r0: 3, a: 0 });39
assert.deepEqual(Reward.spawnParams(5), { r0: 1, a: 0 }, 'n ≤ 13: constant (n−1)/4');40
assert.deepEqual(Reward.spawnParams(1), { r0: 0, a: 0 });41
});42
43
it('the last block always leaves at 4 s, whatever the point count', () =>44
{45
for (const n of [2, 5, 12, 13, 14, 50, 253, 800, 2000, 10000])46
{47
const last = Reward.spawnTime(n - 1, n);48
assert.ok(Math.abs(last - 4) < 1e-9, 'n=' + n + ' last=' + last);49
assert.ok(Reward.spawnedBy(4 - 1e-3, n) < n, 'n=' + n + ' not all out just before 4 s');50
assert.equal(Reward.spawnedBy(4 + 1e-6, n), n, 'n=' + n + ' at 4 s');51
assert.ok(Math.abs(Reward.countDuration(n) - (4 + Reward.FLIGHT)) < 1e-9);52
}53
assert.equal(Reward.spawnTime(0, 1), 0);54
assert.equal(Reward.countDuration(1), Reward.FLIGHT);55
});56
57
it('block i leaves when 3t + a·t²/2 = i; starts at 3/s and accelerates', () =>58
{59
const n = 253;60
const { r0, a } = Reward.spawnParams(n);61
for (const i of [1, 5, 10, 50, 100, 252])39
{62
{40
const t = Reward.spawnTime(i);63
const t = Reward.spawnTime(i, n);41
assert.ok(Math.abs(15 * t + 10 * t * t / 2 - i) < 1e-9, 'i=' + i + ' t=' + t);64
assert.ok(Math.abs(r0 * t + a * t * t / 2 - i) < 1e-9, 'i=' + i + ' t=' + t);42
}65
}43
// spawn times strictly increase, gaps shrink (accelerating)66
// First gap ≈ 1/3 s at the start rate (slightly less: it accelerates).67
const g1 = Reward.spawnTime(1, n);68
assert.ok(g1 < 1 / 3 && g1 > 0.1, 'first gap ' + g1);44
let prevGap = Infinity;69
let prevGap = Infinity;45
for (let i = 1; i < 300; i++)70
for (let i = 1; i < n; i++)46
{71
{47
const gap = Reward.spawnTime(i) - Reward.spawnTime(i - 1);72
const gap = Reward.spawnTime(i, n) - Reward.spawnTime(i - 1, n);48
assert.ok(gap > 0);73
assert.ok(gap > 0);49
assert.ok(gap <= prevGap + 1e-12, 'gap grew at ' + i);74
assert.ok(gap <= prevGap + 1e-12, 'gap grew at ' + i);50
prevGap = gap;75
prevGap = gap;51
}76
}52
});77
});53
78
54
it('starts at 15/s; 253 ≈ 5.8 s, 800 ≈ 11.2 s, 2000 ≈ 18.6 s (Tim\'s examples)', () =>79
it('spawnedBy matches floor(r0·t + a·t²/2) + 1, capped by n', () =>55
{56
// 1/5 s between the first two blocks.57
assert.ok(Math.abs(Reward.spawnTime(1) - (-15 + Math.sqrt(245)) / 10) < 1e-12);58
assert.ok(Reward.spawnTime(1) > 0.06 && Reward.spawnTime(1) < 0.067);59
const last = (-15 + Math.sqrt(225 + 20 * 252)) / 10;60
assert.ok(Math.abs(Reward.spawnTime(252) - last) < 1e-9);61
assert.ok(last > 5.7 && last < 5.85, 'last=' + last);62
assert.ok(Math.abs(Reward.spawnTime(799) - 11.2) < 0.05, '800: ' + Reward.spawnTime(799));63
assert.ok(Math.abs(Reward.spawnTime(1999) - 18.6) < 0.1, '2000: ' + Reward.spawnTime(1999));64
assert.equal(Reward.spawnedBy(last + 1e-6, 253), 253);65
assert.equal(Reward.spawnedBy(last - 0.01, 253), 252);66
assert.ok(Math.abs(Reward.countDuration(253) - (last + Reward.FLIGHT)) < 1e-9);67
});68
69
it('spawnedBy matches floor(15t + 10t²/2) + 1, capped by n', () =>70
{80
{71
for (let t = 0; t <= 20; t += 0.37)81
const { r0, a } = Reward.spawnParams(253);82
for (let t = 0; t <= 6; t += 0.137)72
{83
{73
const expect = Math.min(253, Math.floor(15 * t + 10 * t * t / 2 + 1e-9) + 1);84
const expect = Math.min(253, Math.floor(r0 * t + a * t * t / 2 + 1e-9) + 1);74
assert.equal(Reward.spawnedBy(t, 253), expect, 't=' + t);85
assert.equal(Reward.spawnedBy(t, 253), expect, 't=' + t);75
}86
}76
assert.equal(Reward.spawnedBy(-1, 10), 0);87
assert.equal(Reward.spawnedBy(-1, 10), 0);@@ -79,11 +90,37 @@ describe('Reward spawn schedule (t1178: 15 + 10t blocks/s)', () =>79
assert.equal(Reward.arrivedBy(Reward.FLIGHT - 0.01, 10), 0);90
assert.equal(Reward.arrivedBy(Reward.FLIGHT - 0.01, 10), 0);80
assert.equal(Reward.arrivedBy(Reward.FLIGHT, 10), 1);91
assert.equal(Reward.arrivedBy(Reward.FLIGHT, 10), 1);81
});92
});93
94
it('measured end times through the real sequence (60 fps): ~4 s for 5…2000 points', () =>95
{96
for (const n of [5, 50, 253, 800, 2000])97
{98
const seq = Reward.createSequence({ won: true });99
seq.setResult({ before: 100, after: 100 + n });100
let t = 0, firstSpawn = null, lastSpawn = null, lastArrive = null, prev = 0;101
for (let k = 0; k < 60 * 30; k++)102
{103
const out = seq.tick(1 / 60);104
t += 1 / 60;105
if (out.spawn.length)106
{107
if (firstSpawn == null) firstSpawn = t;108
lastSpawn = t;109
}110
if (seq.arrived === n && lastArrive == null && prev < n) lastArrive = t;111
prev = seq.arrived;112
if (out.done) break;113
}114
const spawnSpan = lastSpawn - firstSpawn;115
assert.ok(Math.abs(spawnSpan - 4) < 0.05, 'n=' + n + ' last spawn after ' + spawnSpan.toFixed(3) + ' s');116
assert.equal(seq.counter, 100 + n);117
}118
});82
});119
});83
120
84
describe('Reward sequence (t1173)', () =>121
describe('Reward sequence (t1173)', () =>85
{122
{86
it('500 + 253 → counts every point from 500 up to 753 in ~6.5 s of counting', () =>123
it('500 + 253 → counts every point from 500 up to 753 (last block at 4 s)', () =>87
{124
{88
const seq = Reward.createSequence({ won: true });125
const seq = Reward.createSequence({ won: true });89
seq.setResult({ before: 500, after: 753 });126
seq.setResult({ before: 500, after: 753 });@@ -125,7 +125,7 @@ def watch_reward(page, prefix, expect_title, expect_earned):
125
125
check(st["titleTop"] < st["vh"] * 0.15, f"{prefix}: title rose to the top ({st['titleTop']:.0f})")
126
126
if expect_earned > 0:
127
127
page.wait_for_function(
128
"() => Reward.debugState() && Reward.debugState().phase === 'count' && Reward.debugState().flying >= 2",
128
"() => Reward.debugState() && Reward.debugState().phase === 'count' && Reward.debugState().flying >= 1",
129
129
timeout=6000,
130
130
)
131
131
page.wait_for_timeout(250)
@@ -125,7 +125,7 @@ def watch_reward(page, prefix, expect_title, expect_earned):125
check(st["titleTop"] < st["vh"] * 0.15, f"{prefix}: title rose to the top ({st['titleTop']:.0f})")125
check(st["titleTop"] < st["vh"] * 0.15, f"{prefix}: title rose to the top ({st['titleTop']:.0f})")126
if expect_earned > 0:126
if expect_earned > 0:127
page.wait_for_function(127
page.wait_for_function(128
"() => Reward.debugState() && Reward.debugState().phase === 'count' && Reward.debugState().flying >= 2",128
"() => Reward.debugState() && Reward.debugState().phase === 'count' && Reward.debugState().flying >= 1",129
timeout=6000,129
timeout=6000,130
)130
)131
page.wait_for_timeout(250)131
page.wait_for_timeout(250)