BlueGit

projects-timfalken-com meteors

Merge branch 'feature/t1189-spawn-intro'

timfa Grok Bot · pushed by timfa

Authored 2026-11-14 · 3 days ago

Hash
ff34c91df5670dfd8bb17ff892ddc74e9333106d
Pipeline
Passed
8 files changed +494 −21
README.md +6 −3
@@ -202,9 +202,12 @@ op het podium en daarna ga je terug naar de lobby.
202 202 veldhoogte en gaat hij zeker het scherm uit, dan valt er geen nieuw blok
203 203 en geen ontvangen (grijs) blok in de kolommen van die stapel: ze kiezen
204 204 een andere kolom.
205 - Het tempo loopt op: na elk nieuw blok wordt de spawn-interval 0,3%
206 korter (start 1 s, minimum 0,1 s, na ca. 767 blokken / 5 minuten). Elk
207 spel en elke ronde begint weer op 1 s, ook voor bots.
205 - Start van elke match/ronde: de eerste 3 s valt er elke 0,1 s een blok
206 (verdeeld over de legere kolommen), van 3 tot 6 s loopt de tussentijd
207 lineair terug naar 1 s.
208 - Daarna loopt het tempo op: na elk nieuw blok wordt de spawn-interval 0,3%
209 korter (minimum 0,1 s, na ca. 767 blokken / 5 minuten). Elk spel en elke
210 ronde begint weer bij 0 s, ook voor bots en online.
208 211
209 212 ### Raketvlam
210 213
@@ -202,9 +202,12 @@ op het podium en daarna ga je terug naar de lobby.
202 veldhoogte en gaat hij zeker het scherm uit, dan valt er geen nieuw blok
202 veldhoogte en gaat hij zeker het scherm uit, dan valt er geen nieuw blok
203 en geen ontvangen (grijs) blok in de kolommen van die stapel: ze kiezen
203 en geen ontvangen (grijs) blok in de kolommen van die stapel: ze kiezen
204 een andere kolom.
204 een andere kolom.
205- Het tempo loopt op: na elk nieuw blok wordt de spawn-interval 0,3%
205- Start van elke match/ronde: de eerste 3 s valt er elke 0,1 s een blok
206 korter (start 1 s, minimum 0,1 s, na ca. 767 blokken / 5 minuten). Elk
206 (verdeeld over de legere kolommen), van 3 tot 6 s loopt de tussentijd
207 spel en elke ronde begint weer op 1 s, ook voor bots.
207 lineair terug naar 1 s.
208- Daarna loopt het tempo op: na elk nieuw blok wordt de spawn-interval 0,3%
209 korter (minimum 0,1 s, na ca. 767 blokken / 5 minuten). Elk spel en elke
210 ronde begint weer bij 0 s, ook voor bots en online.
208
211
209### Raketvlam
212### Raketvlam
210
213
build/game.js +95 −9
@@ -5171,6 +5171,8 @@ function GameCore (planet, rng)
5171 5171 this.nextClusterId = 1;
5172 5172 this.spawnTimer = 0;
5173 5173 this.spawnInterval = PlanetMod.SPAWN_INTERVAL;
5174 /** Seconds of actual play in this match / round (t1189). */
5175 this.playTime = 0;
5174 5176 this.settleTime = PlanetMod.SETTLE_TIME;
5175 5177 this.score = 0;
5176 5178 this.state = 'playing';
@@ -5679,12 +5681,17 @@ GameCore.prototype.tick = function (dt)
5679 5681 { return; }
5680 5682 dt = Math.min(dt, 0.1);
5681 5683
5684 // t1189: spawn timeline by elapsed play time (intro burst, ramp, then
5685 // the per-spawn speed-up). Interval is re-read after every spawn.
5682 5686 this.spawnTimer += dt;
5683 while (this.spawnTimer >= this.spawnInterval)
5687 var iv = this.currentSpawnInterval();
5688 while (this.spawnTimer >= iv)
5684 5689 {
5685 this.spawnTimer -= this.spawnInterval;
5690 this.spawnTimer -= iv;
5686 5691 this.trySpawn();
5692 iv = this.currentSpawnInterval();
5687 5693 }
5694 this.playTime += dt;
5688 5695
5689 5696 var left = dt;
5690 5697 while (left > 1e-12)
@@ -5822,27 +5829,106 @@ GameCore.prototype.trySpawn = function ()
5822 5829 { continue; }
5823 5830 var alreadyFalling = false;
5824 5831 var list = this.blocksInColumn(col);
5832 // t1189/t1191: during the opening burst and ramp a column may take
5833 // another block as soon as the previous falling one has cleared a
5834 // full cell below the spawn row (no overlap); later the classic
5835 // one-falling-block-per-column rule applies.
5836 var opening = this.playTime < GameCore.SPAWN_RAMP_END;
5825 5837 for (var i = 0; i < list.length; i++)
5826 5838 {
5827 if (list[i].state === STATE_FALLING)
5828 {
5829 alreadyFalling = true;
5830 break;
5831 }
5839 if (list[i].state !== STATE_FALLING)
5840 { continue; }
5841 if (opening && list[i].y <= this.height - 1 + 1e-9)
5842 { continue; }
5843 alreadyFalling = true;
5844 break;
5832 5845 }
5833 5846 if (!alreadyFalling)
5834 5847 { eligible.push(col); }
5835 5848 }
5836 5849 if (!eligible.length)
5837 5850 { return null; }
5838 var col = eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
5851 var col = this.playTime < GameCore.SPAWN_INTRO_END
5852 ? this.pickWeightedSpawnColumn(eligible)
5853 : eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
5839 5854 var color = this.randomColor();
5840 5855 var block = this.createBlock(col, this.height, color, STATE_FALLING);
5841 5856 block.vy = -this.planet.fallSpeed;
5842 this.speedUpSpawning();
5857 // t1187/t1188 speed-up only counts blocks spawned after the intro (t1189).
5858 if (this.playTime >= GameCore.SPAWN_RAMP_END)
5859 { this.speedUpSpawning(); }
5843 5860 return block;
5844 5861 };
5845 5862
5863 /**
5864 * Burst-phase column choice (t1191): weight each eligible column by its
5865 * free cells (height − grounded − already falling blocks, min 1), so the fast opening burst fills
5866 * the field evenly instead of piling onto one column. One rng() draw, like
5867 * the uniform pick.
5868 */
5869 GameCore.prototype.fallingCount = function (col)
5870 {
5871 var n = 0;
5872 for (var i = 0; i < this.blocks.length; i++)
5873 {
5874 if (this.blocks[i].col === col && this.blocks[i].state === STATE_FALLING)
5875 { n++; }
5876 }
5877 return n;
5878 };
5879
5880 GameCore.prototype.pickWeightedSpawnColumn = function (eligible)
5881 {
5882 var weights = [];
5883 var total = 0;
5884 for (var i = 0; i < eligible.length; i++)
5885 {
5886 var w = Math.max(1, this.height - this.groundedCount(eligible[i]) - this.fallingCount(eligible[i]));
5887 weights.push(w);
5888 total += w;
5889 }
5890 var r = this.rng() * total;
5891 for (var j = 0; j < eligible.length; j++)
5892 {
5893 r -= weights[j];
5894 if (r < 0)
5895 { return eligible[j]; }
5896 }
5897 return eligible[eligible.length - 1];
5898 };
5899
5900 /** t1189/t1191: first seconds of a match spawn fast ... */
5901 GameCore.SPAWN_INTRO_END = 3;
5902 /** ... at this interval (seconds) ... */
5903 GameCore.SPAWN_INTRO_INTERVAL = 0.1;
5904 /** ... then lerp back to PlanetMod.SPAWN_INTERVAL (1 s) until this time. */
5905 GameCore.SPAWN_RAMP_END = 6;
5906
5907 /**
5908 * Spawn interval right now (t1189):
5909 * playTime < 3 s → 0.1 s (burst, weighted column choice)
5910 * 3 s – 6 s → linear 0.1 s → 1.0 s
5911 * ≥ 6 s → spawnInterval (starts at 1 s, ×0.997 per spawn
5912 * after 6 s, floor 0.1 s)
5913 * An interval set above the 1 s start (tests / tools use 1e9 to switch
5914 * spawning off) is always respected.
5915 */
5916 GameCore.prototype.currentSpawnInterval = function ()
5917 {
5918 var base = PlanetMod.SPAWN_INTERVAL;
5919 if (this.spawnInterval > base + 1e-9)
5920 { return this.spawnInterval; }
5921 var t = this.playTime || 0;
5922 if (t < GameCore.SPAWN_INTRO_END)
5923 { return GameCore.SPAWN_INTRO_INTERVAL; }
5924 if (t < GameCore.SPAWN_RAMP_END)
5925 {
5926 var k = (t - GameCore.SPAWN_INTRO_END) / (GameCore.SPAWN_RAMP_END - GameCore.SPAWN_INTRO_END);
5927 return GameCore.SPAWN_INTRO_INTERVAL + (base - GameCore.SPAWN_INTRO_INTERVAL) * k;
5928 }
5929 return this.spawnInterval;
5930 };
5931
5846 5932 /** Each spawned block shrinks the spawn interval by 0.3% (t1187 / t1188). */
5847 5933 GameCore.SPAWN_SPEEDUP = 0.997;
5848 5934 /** The spawn interval never goes below this (seconds, t1187). */
@@ -5171,6 +5171,8 @@ function GameCore (planet, rng)
5171 this.nextClusterId = 1;
5171 this.nextClusterId = 1;
5172 this.spawnTimer = 0;
5172 this.spawnTimer = 0;
5173 this.spawnInterval = PlanetMod.SPAWN_INTERVAL;
5173 this.spawnInterval = PlanetMod.SPAWN_INTERVAL;
5174 /** Seconds of actual play in this match / round (t1189). */
5175 this.playTime = 0;
5174 this.settleTime = PlanetMod.SETTLE_TIME;
5176 this.settleTime = PlanetMod.SETTLE_TIME;
5175 this.score = 0;
5177 this.score = 0;
5176 this.state = 'playing';
5178 this.state = 'playing';
@@ -5679,12 +5681,17 @@ GameCore.prototype.tick = function (dt)
5679 { return; }
5681 { return; }
5680 dt = Math.min(dt, 0.1);
5682 dt = Math.min(dt, 0.1);
5681
5683
5684 // t1189: spawn timeline by elapsed play time (intro burst, ramp, then
5685 // the per-spawn speed-up). Interval is re-read after every spawn.
5682 this.spawnTimer += dt;
5686 this.spawnTimer += dt;
5683 while (this.spawnTimer >= this.spawnInterval)
5687 var iv = this.currentSpawnInterval();
5688 while (this.spawnTimer >= iv)
5684 {
5689 {
5685 this.spawnTimer -= this.spawnInterval;
5690 this.spawnTimer -= iv;
5686 this.trySpawn();
5691 this.trySpawn();
5692 iv = this.currentSpawnInterval();
5687 }
5693 }
5694 this.playTime += dt;
5688
5695
5689 var left = dt;
5696 var left = dt;
5690 while (left > 1e-12)
5697 while (left > 1e-12)
@@ -5822,27 +5829,106 @@ GameCore.prototype.trySpawn = function ()
5822 { continue; }
5829 { continue; }
5823 var alreadyFalling = false;
5830 var alreadyFalling = false;
5824 var list = this.blocksInColumn(col);
5831 var list = this.blocksInColumn(col);
5832 // t1189/t1191: during the opening burst and ramp a column may take
5833 // another block as soon as the previous falling one has cleared a
5834 // full cell below the spawn row (no overlap); later the classic
5835 // one-falling-block-per-column rule applies.
5836 var opening = this.playTime < GameCore.SPAWN_RAMP_END;
5825 for (var i = 0; i < list.length; i++)
5837 for (var i = 0; i < list.length; i++)
5826 {
5838 {
5827 if (list[i].state === STATE_FALLING)
5839 if (list[i].state !== STATE_FALLING)
5828 {
5840 { continue; }
5829 alreadyFalling = true;
5841 if (opening && list[i].y <= this.height - 1 + 1e-9)
5830 break;
5842 { continue; }
5831 }
5843 alreadyFalling = true;
5844 break;
5832 }
5845 }
5833 if (!alreadyFalling)
5846 if (!alreadyFalling)
5834 { eligible.push(col); }
5847 { eligible.push(col); }
5835 }
5848 }
5836 if (!eligible.length)
5849 if (!eligible.length)
5837 { return null; }
5850 { return null; }
5838 var col = eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
5851 var col = this.playTime < GameCore.SPAWN_INTRO_END
5852 ? this.pickWeightedSpawnColumn(eligible)
5853 : eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
5839 var color = this.randomColor();
5854 var color = this.randomColor();
5840 var block = this.createBlock(col, this.height, color, STATE_FALLING);
5855 var block = this.createBlock(col, this.height, color, STATE_FALLING);
5841 block.vy = -this.planet.fallSpeed;
5856 block.vy = -this.planet.fallSpeed;
5842 this.speedUpSpawning();
5857 // t1187/t1188 speed-up only counts blocks spawned after the intro (t1189).
5858 if (this.playTime >= GameCore.SPAWN_RAMP_END)
5859 { this.speedUpSpawning(); }
5843 return block;
5860 return block;
5844};
5861};
5845
5862
5863/**
5864 * Burst-phase column choice (t1191): weight each eligible column by its
5865 * free cells (height − grounded − already falling blocks, min 1), so the fast opening burst fills
5866 * the field evenly instead of piling onto one column. One rng() draw, like
5867 * the uniform pick.
5868 */
5869GameCore.prototype.fallingCount = function (col)
5870{
5871 var n = 0;
5872 for (var i = 0; i < this.blocks.length; i++)
5873 {
5874 if (this.blocks[i].col === col && this.blocks[i].state === STATE_FALLING)
5875 { n++; }
5876 }
5877 return n;
5878};
5879
5880GameCore.prototype.pickWeightedSpawnColumn = function (eligible)
5881{
5882 var weights = [];
5883 var total = 0;
5884 for (var i = 0; i < eligible.length; i++)
5885 {
5886 var w = Math.max(1, this.height - this.groundedCount(eligible[i]) - this.fallingCount(eligible[i]));
5887 weights.push(w);
5888 total += w;
5889 }
5890 var r = this.rng() * total;
5891 for (var j = 0; j < eligible.length; j++)
5892 {
5893 r -= weights[j];
5894 if (r < 0)
5895 { return eligible[j]; }
5896 }
5897 return eligible[eligible.length - 1];
5898};
5899
5900/** t1189/t1191: first seconds of a match spawn fast ... */
5901GameCore.SPAWN_INTRO_END = 3;
5902/** ... at this interval (seconds) ... */
5903GameCore.SPAWN_INTRO_INTERVAL = 0.1;
5904/** ... then lerp back to PlanetMod.SPAWN_INTERVAL (1 s) until this time. */
5905GameCore.SPAWN_RAMP_END = 6;
5906
5907/**
5908 * Spawn interval right now (t1189):
5909 * playTime < 3 s → 0.1 s (burst, weighted column choice)
5910 * 3 s – 6 s → linear 0.1 s → 1.0 s
5911 * ≥ 6 s → spawnInterval (starts at 1 s, ×0.997 per spawn
5912 * after 6 s, floor 0.1 s)
5913 * An interval set above the 1 s start (tests / tools use 1e9 to switch
5914 * spawning off) is always respected.
5915 */
5916GameCore.prototype.currentSpawnInterval = function ()
5917{
5918 var base = PlanetMod.SPAWN_INTERVAL;
5919 if (this.spawnInterval > base + 1e-9)
5920 { return this.spawnInterval; }
5921 var t = this.playTime || 0;
5922 if (t < GameCore.SPAWN_INTRO_END)
5923 { return GameCore.SPAWN_INTRO_INTERVAL; }
5924 if (t < GameCore.SPAWN_RAMP_END)
5925 {
5926 var k = (t - GameCore.SPAWN_INTRO_END) / (GameCore.SPAWN_RAMP_END - GameCore.SPAWN_INTRO_END);
5927 return GameCore.SPAWN_INTRO_INTERVAL + (base - GameCore.SPAWN_INTRO_INTERVAL) * k;
5928 }
5929 return this.spawnInterval;
5930};
5931
5846/** Each spawned block shrinks the spawn interval by 0.3% (t1187 / t1188). */
5932/** Each spawned block shrinks the spawn interval by 0.3% (t1187 / t1188). */
5847GameCore.SPAWN_SPEEDUP = 0.997;
5933GameCore.SPAWN_SPEEDUP = 0.997;
5848/** The spawn interval never goes below this (seconds, t1187). */
5934/** The spawn interval never goes below this (seconds, t1187). */
docs/ASSUMPTIONS.md +40 −0
@@ -1076,3 +1076,43 @@ Tests: `test/departing.test.js`; browser:
1076 1076
1077 1077 Tests: `test/spawn-speedup.test.js`.
1078 1078
1079 ## t1189 / t1191 — openingsburst en aanloop van het spawn-tempo
1080
1081 Tim (t1189): "In de eerste 5 seconden van een match, beginnen met 0.1s
1082 tussen blokjes. Dan tussen de 5 en 8 seconden lerpen terug naar 1 per
1083 seconde, en daarna pas de rate increase doen die we nu hebben." Daarna
1084 (t1191) aangepast: burst de eerste **3 s**, dan lerp van **3 naar 6 s**.
1085
1086 - `GameCore.playTime`: seconden echte speeltijd van deze match/ronde. Telt
1087 vanaf de eerste `tick` van een nieuwe `GameCore`; er is geen aftelling,
1088 dus de tijd start als het spelen start. Elke ronde/match maakt een nieuwe
1089 core, dus de klok begint steeds bij 0 (spelers, bots, online).
1090 - `GameCore.currentSpawnInterval()`:
1091 - `playTime < SPAWN_INTRO_END` (3 s): `SPAWN_INTRO_INTERVAL` = 0,1 s.
1092 - 3 s – `SPAWN_RAMP_END` (6 s): lineair van 0,1 s naar 1,0 s
1093 (`PlanetMod.SPAWN_INTERVAL`). De lerp-duur van 3 s is behouden uit de
1094 eerste versie (aanname).
1095 - Vanaf 6 s: `spawnInterval`, start 1 s, ×0,997 per gespawnd blok,
1096 minimum 0,1 s (t1187/t1188). **Alleen blokken die na 6 s spawnen
1097 tellen** voor die versnelling.
1098 - De interval wordt na elke spawn opnieuw gelezen.
1099 - **Kolomkeuze in de burst** ("weighted column choice", t1191): tijdens de
1100 eerste 3 s kiest `pickWeightedSpawnColumn` een kolom met gewicht = vrije
1101 cellen (13 − vaste − al vallende blokken, minimaal 1). Legere kolommen
1102 krijgen dus vaker een blok; daarna weer uniform willekeurig. (De exacte
1103 weging stond niet in de opdracht; dit is mijn invulling.)
1104 - **Meerdere vallende blokken per kolom in de opening:** met 0,1 s
1105 tussentijd zouden na 10 blokken alle kolommen bezet zijn (regel: één
1106 vallend blok per kolom) en zou de burst ~2 s stilvallen. Tot 6 s mag een
1107 kolom daarom een nieuw blok krijgen zodra het vorige vallende blok een
1108 hele cel onder de spawnrij zit (geen overlap). Na 6 s geldt weer één
1109 vallend blok per kolom.
1110 - Gemeten: 30 blokken in 0–3 s, 6 in 3–6 s (36 in de eerste 6 s).
1111 - De regel voor vertrekkende raketten (t1184) blijft gelden, ook in de
1112 burst.
1113 - Testhaak: een `spawnInterval` boven 1 s (tests/tools zetten 1e9 om
1114 spawnen uit te zetten) wordt altijd gerespecteerd, ook in de burst.
1115
1116 Tests: `test/spawn-timeline.test.js`; browser:
1117 `test/t1189-spawn-timeline-playwright.py URL TAG`.
1118
@@ -1076,3 +1076,43 @@ Tests: `test/departing.test.js`; browser:
1076
1076
1077Tests: `test/spawn-speedup.test.js`.
1077Tests: `test/spawn-speedup.test.js`.
1078
1078
1079## t1189 / t1191 — openingsburst en aanloop van het spawn-tempo
1080
1081Tim (t1189): "In de eerste 5 seconden van een match, beginnen met 0.1s
1082tussen blokjes. Dan tussen de 5 en 8 seconden lerpen terug naar 1 per
1083seconde, en daarna pas de rate increase doen die we nu hebben." Daarna
1084(t1191) aangepast: burst de eerste **3 s**, dan lerp van **3 naar 6 s**.
1085
1086- `GameCore.playTime`: seconden echte speeltijd van deze match/ronde. Telt
1087 vanaf de eerste `tick` van een nieuwe `GameCore`; er is geen aftelling,
1088 dus de tijd start als het spelen start. Elke ronde/match maakt een nieuwe
1089 core, dus de klok begint steeds bij 0 (spelers, bots, online).
1090- `GameCore.currentSpawnInterval()`:
1091 - `playTime < SPAWN_INTRO_END` (3 s): `SPAWN_INTRO_INTERVAL` = 0,1 s.
1092 - 3 s – `SPAWN_RAMP_END` (6 s): lineair van 0,1 s naar 1,0 s
1093 (`PlanetMod.SPAWN_INTERVAL`). De lerp-duur van 3 s is behouden uit de
1094 eerste versie (aanname).
1095 - Vanaf 6 s: `spawnInterval`, start 1 s, ×0,997 per gespawnd blok,
1096 minimum 0,1 s (t1187/t1188). **Alleen blokken die na 6 s spawnen
1097 tellen** voor die versnelling.
1098 - De interval wordt na elke spawn opnieuw gelezen.
1099- **Kolomkeuze in de burst** ("weighted column choice", t1191): tijdens de
1100 eerste 3 s kiest `pickWeightedSpawnColumn` een kolom met gewicht = vrije
1101 cellen (13 − vaste − al vallende blokken, minimaal 1). Legere kolommen
1102 krijgen dus vaker een blok; daarna weer uniform willekeurig. (De exacte
1103 weging stond niet in de opdracht; dit is mijn invulling.)
1104- **Meerdere vallende blokken per kolom in de opening:** met 0,1 s
1105 tussentijd zouden na 10 blokken alle kolommen bezet zijn (regel: één
1106 vallend blok per kolom) en zou de burst ~2 s stilvallen. Tot 6 s mag een
1107 kolom daarom een nieuw blok krijgen zodra het vorige vallende blok een
1108 hele cel onder de spawnrij zit (geen overlap). Na 6 s geldt weer één
1109 vallend blok per kolom.
1110- Gemeten: 30 blokken in 0–3 s, 6 in 3–6 s (36 in de eerste 6 s).
1111- De regel voor vertrekkende raketten (t1184) blijft gelden, ook in de
1112 burst.
1113- Testhaak: een `spawnInterval` boven 1 s (tests/tools zetten 1e9 om
1114 spawnen uit te zetten) wordt altijd gerespecteerd, ook in de burst.
1115
1116Tests: `test/spawn-timeline.test.js`; browser:
1117`test/t1189-spawn-timeline-playwright.py URL TAG`.
1118
src/gameCore.js +95 −9
@@ -79,6 +79,8 @@ function GameCore (planet, rng)
79 79 this.nextClusterId = 1;
80 80 this.spawnTimer = 0;
81 81 this.spawnInterval = PlanetMod.SPAWN_INTERVAL;
82 /** Seconds of actual play in this match / round (t1189). */
83 this.playTime = 0;
82 84 this.settleTime = PlanetMod.SETTLE_TIME;
83 85 this.score = 0;
84 86 this.state = 'playing';
@@ -587,12 +589,17 @@ GameCore.prototype.tick = function (dt)
587 589 { return; }
588 590 dt = Math.min(dt, 0.1);
589 591
592 // t1189: spawn timeline by elapsed play time (intro burst, ramp, then
593 // the per-spawn speed-up). Interval is re-read after every spawn.
590 594 this.spawnTimer += dt;
591 while (this.spawnTimer >= this.spawnInterval)
595 var iv = this.currentSpawnInterval();
596 while (this.spawnTimer >= iv)
592 597 {
593 this.spawnTimer -= this.spawnInterval;
598 this.spawnTimer -= iv;
594 599 this.trySpawn();
600 iv = this.currentSpawnInterval();
595 601 }
602 this.playTime += dt;
596 603
597 604 var left = dt;
598 605 while (left > 1e-12)
@@ -730,27 +737,106 @@ GameCore.prototype.trySpawn = function ()
730 737 { continue; }
731 738 var alreadyFalling = false;
732 739 var list = this.blocksInColumn(col);
740 // t1189/t1191: during the opening burst and ramp a column may take
741 // another block as soon as the previous falling one has cleared a
742 // full cell below the spawn row (no overlap); later the classic
743 // one-falling-block-per-column rule applies.
744 var opening = this.playTime < GameCore.SPAWN_RAMP_END;
733 745 for (var i = 0; i < list.length; i++)
734 746 {
735 if (list[i].state === STATE_FALLING)
736 {
737 alreadyFalling = true;
738 break;
739 }
747 if (list[i].state !== STATE_FALLING)
748 { continue; }
749 if (opening && list[i].y <= this.height - 1 + 1e-9)
750 { continue; }
751 alreadyFalling = true;
752 break;
740 753 }
741 754 if (!alreadyFalling)
742 755 { eligible.push(col); }
743 756 }
744 757 if (!eligible.length)
745 758 { return null; }
746 var col = eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
759 var col = this.playTime < GameCore.SPAWN_INTRO_END
760 ? this.pickWeightedSpawnColumn(eligible)
761 : eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
747 762 var color = this.randomColor();
748 763 var block = this.createBlock(col, this.height, color, STATE_FALLING);
749 764 block.vy = -this.planet.fallSpeed;
750 this.speedUpSpawning();
765 // t1187/t1188 speed-up only counts blocks spawned after the intro (t1189).
766 if (this.playTime >= GameCore.SPAWN_RAMP_END)
767 { this.speedUpSpawning(); }
751 768 return block;
752 769 };
753 770
771 /**
772 * Burst-phase column choice (t1191): weight each eligible column by its
773 * free cells (height − grounded − already falling blocks, min 1), so the fast opening burst fills
774 * the field evenly instead of piling onto one column. One rng() draw, like
775 * the uniform pick.
776 */
777 GameCore.prototype.fallingCount = function (col)
778 {
779 var n = 0;
780 for (var i = 0; i < this.blocks.length; i++)
781 {
782 if (this.blocks[i].col === col && this.blocks[i].state === STATE_FALLING)
783 { n++; }
784 }
785 return n;
786 };
787
788 GameCore.prototype.pickWeightedSpawnColumn = function (eligible)
789 {
790 var weights = [];
791 var total = 0;
792 for (var i = 0; i < eligible.length; i++)
793 {
794 var w = Math.max(1, this.height - this.groundedCount(eligible[i]) - this.fallingCount(eligible[i]));
795 weights.push(w);
796 total += w;
797 }
798 var r = this.rng() * total;
799 for (var j = 0; j < eligible.length; j++)
800 {
801 r -= weights[j];
802 if (r < 0)
803 { return eligible[j]; }
804 }
805 return eligible[eligible.length - 1];
806 };
807
808 /** t1189/t1191: first seconds of a match spawn fast ... */
809 GameCore.SPAWN_INTRO_END = 3;
810 /** ... at this interval (seconds) ... */
811 GameCore.SPAWN_INTRO_INTERVAL = 0.1;
812 /** ... then lerp back to PlanetMod.SPAWN_INTERVAL (1 s) until this time. */
813 GameCore.SPAWN_RAMP_END = 6;
814
815 /**
816 * Spawn interval right now (t1189):
817 * playTime < 3 s → 0.1 s (burst, weighted column choice)
818 * 3 s – 6 s → linear 0.1 s → 1.0 s
819 * ≥ 6 s → spawnInterval (starts at 1 s, ×0.997 per spawn
820 * after 6 s, floor 0.1 s)
821 * An interval set above the 1 s start (tests / tools use 1e9 to switch
822 * spawning off) is always respected.
823 */
824 GameCore.prototype.currentSpawnInterval = function ()
825 {
826 var base = PlanetMod.SPAWN_INTERVAL;
827 if (this.spawnInterval > base + 1e-9)
828 { return this.spawnInterval; }
829 var t = this.playTime || 0;
830 if (t < GameCore.SPAWN_INTRO_END)
831 { return GameCore.SPAWN_INTRO_INTERVAL; }
832 if (t < GameCore.SPAWN_RAMP_END)
833 {
834 var k = (t - GameCore.SPAWN_INTRO_END) / (GameCore.SPAWN_RAMP_END - GameCore.SPAWN_INTRO_END);
835 return GameCore.SPAWN_INTRO_INTERVAL + (base - GameCore.SPAWN_INTRO_INTERVAL) * k;
836 }
837 return this.spawnInterval;
838 };
839
754 840 /** Each spawned block shrinks the spawn interval by 0.3% (t1187 / t1188). */
755 841 GameCore.SPAWN_SPEEDUP = 0.997;
756 842 /** The spawn interval never goes below this (seconds, t1187). */
@@ -79,6 +79,8 @@ function GameCore (planet, rng)
79 this.nextClusterId = 1;
79 this.nextClusterId = 1;
80 this.spawnTimer = 0;
80 this.spawnTimer = 0;
81 this.spawnInterval = PlanetMod.SPAWN_INTERVAL;
81 this.spawnInterval = PlanetMod.SPAWN_INTERVAL;
82 /** Seconds of actual play in this match / round (t1189). */
83 this.playTime = 0;
82 this.settleTime = PlanetMod.SETTLE_TIME;
84 this.settleTime = PlanetMod.SETTLE_TIME;
83 this.score = 0;
85 this.score = 0;
84 this.state = 'playing';
86 this.state = 'playing';
@@ -587,12 +589,17 @@ GameCore.prototype.tick = function (dt)
587 { return; }
589 { return; }
588 dt = Math.min(dt, 0.1);
590 dt = Math.min(dt, 0.1);
589
591
592 // t1189: spawn timeline by elapsed play time (intro burst, ramp, then
593 // the per-spawn speed-up). Interval is re-read after every spawn.
590 this.spawnTimer += dt;
594 this.spawnTimer += dt;
591 while (this.spawnTimer >= this.spawnInterval)
595 var iv = this.currentSpawnInterval();
596 while (this.spawnTimer >= iv)
592 {
597 {
593 this.spawnTimer -= this.spawnInterval;
598 this.spawnTimer -= iv;
594 this.trySpawn();
599 this.trySpawn();
600 iv = this.currentSpawnInterval();
595 }
601 }
602 this.playTime += dt;
596
603
597 var left = dt;
604 var left = dt;
598 while (left > 1e-12)
605 while (left > 1e-12)
@@ -730,27 +737,106 @@ GameCore.prototype.trySpawn = function ()
730 { continue; }
737 { continue; }
731 var alreadyFalling = false;
738 var alreadyFalling = false;
732 var list = this.blocksInColumn(col);
739 var list = this.blocksInColumn(col);
740 // t1189/t1191: during the opening burst and ramp a column may take
741 // another block as soon as the previous falling one has cleared a
742 // full cell below the spawn row (no overlap); later the classic
743 // one-falling-block-per-column rule applies.
744 var opening = this.playTime < GameCore.SPAWN_RAMP_END;
733 for (var i = 0; i < list.length; i++)
745 for (var i = 0; i < list.length; i++)
734 {
746 {
735 if (list[i].state === STATE_FALLING)
747 if (list[i].state !== STATE_FALLING)
736 {
748 { continue; }
737 alreadyFalling = true;
749 if (opening && list[i].y <= this.height - 1 + 1e-9)
738 break;
750 { continue; }
739 }
751 alreadyFalling = true;
752 break;
740 }
753 }
741 if (!alreadyFalling)
754 if (!alreadyFalling)
742 { eligible.push(col); }
755 { eligible.push(col); }
743 }
756 }
744 if (!eligible.length)
757 if (!eligible.length)
745 { return null; }
758 { return null; }
746 var col = eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
759 var col = this.playTime < GameCore.SPAWN_INTRO_END
760 ? this.pickWeightedSpawnColumn(eligible)
761 : eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
747 var color = this.randomColor();
762 var color = this.randomColor();
748 var block = this.createBlock(col, this.height, color, STATE_FALLING);
763 var block = this.createBlock(col, this.height, color, STATE_FALLING);
749 block.vy = -this.planet.fallSpeed;
764 block.vy = -this.planet.fallSpeed;
750 this.speedUpSpawning();
765 // t1187/t1188 speed-up only counts blocks spawned after the intro (t1189).
766 if (this.playTime >= GameCore.SPAWN_RAMP_END)
767 { this.speedUpSpawning(); }
751 return block;
768 return block;
752};
769};
753
770
771/**
772 * Burst-phase column choice (t1191): weight each eligible column by its
773 * free cells (height − grounded − already falling blocks, min 1), so the fast opening burst fills
774 * the field evenly instead of piling onto one column. One rng() draw, like
775 * the uniform pick.
776 */
777GameCore.prototype.fallingCount = function (col)
778{
779 var n = 0;
780 for (var i = 0; i < this.blocks.length; i++)
781 {
782 if (this.blocks[i].col === col && this.blocks[i].state === STATE_FALLING)
783 { n++; }
784 }
785 return n;
786};
787
788GameCore.prototype.pickWeightedSpawnColumn = function (eligible)
789{
790 var weights = [];
791 var total = 0;
792 for (var i = 0; i < eligible.length; i++)
793 {
794 var w = Math.max(1, this.height - this.groundedCount(eligible[i]) - this.fallingCount(eligible[i]));
795 weights.push(w);
796 total += w;
797 }
798 var r = this.rng() * total;
799 for (var j = 0; j < eligible.length; j++)
800 {
801 r -= weights[j];
802 if (r < 0)
803 { return eligible[j]; }
804 }
805 return eligible[eligible.length - 1];
806};
807
808/** t1189/t1191: first seconds of a match spawn fast ... */
809GameCore.SPAWN_INTRO_END = 3;
810/** ... at this interval (seconds) ... */
811GameCore.SPAWN_INTRO_INTERVAL = 0.1;
812/** ... then lerp back to PlanetMod.SPAWN_INTERVAL (1 s) until this time. */
813GameCore.SPAWN_RAMP_END = 6;
814
815/**
816 * Spawn interval right now (t1189):
817 * playTime < 3 s → 0.1 s (burst, weighted column choice)
818 * 3 s – 6 s → linear 0.1 s → 1.0 s
819 * ≥ 6 s → spawnInterval (starts at 1 s, ×0.997 per spawn
820 * after 6 s, floor 0.1 s)
821 * An interval set above the 1 s start (tests / tools use 1e9 to switch
822 * spawning off) is always respected.
823 */
824GameCore.prototype.currentSpawnInterval = function ()
825{
826 var base = PlanetMod.SPAWN_INTERVAL;
827 if (this.spawnInterval > base + 1e-9)
828 { return this.spawnInterval; }
829 var t = this.playTime || 0;
830 if (t < GameCore.SPAWN_INTRO_END)
831 { return GameCore.SPAWN_INTRO_INTERVAL; }
832 if (t < GameCore.SPAWN_RAMP_END)
833 {
834 var k = (t - GameCore.SPAWN_INTRO_END) / (GameCore.SPAWN_RAMP_END - GameCore.SPAWN_INTRO_END);
835 return GameCore.SPAWN_INTRO_INTERVAL + (base - GameCore.SPAWN_INTRO_INTERVAL) * k;
836 }
837 return this.spawnInterval;
838};
839
754/** Each spawned block shrinks the spawn interval by 0.3% (t1187 / t1188). */
840/** Each spawned block shrinks the spawn interval by 0.3% (t1187 / t1188). */
755GameCore.SPAWN_SPEEDUP = 0.997;
841GameCore.SPAWN_SPEEDUP = 0.997;
756/** The spawn interval never goes below this (seconds, t1187). */
842/** The spawn interval never goes below this (seconds, t1187). */
test/points.test.js +1 −0
@@ -100,6 +100,7 @@ describe('Points, landing and recolor', () =>
100 100 it('spawn drops a random color into a random open column every second', () =>
101 101 {
102 102 const g = makeGame({ seed: 3 });
103 g.playTime = 6; // after the opening burst / ramp (t1189)
103 104 assert.equal(g.blocks.length, 0);
104 105 g.step(0.99);
105 106 assert.equal(g.blocks.length, 0);
@@ -100,6 +100,7 @@ describe('Points, landing and recolor', () =>
100 it('spawn drops a random color into a random open column every second', () =>
100 it('spawn drops a random color into a random open column every second', () =>
101 {
101 {
102 const g = makeGame({ seed: 3 });
102 const g = makeGame({ seed: 3 });
103 g.playTime = 6; // after the opening burst / ramp (t1189)
103 assert.equal(g.blocks.length, 0);
104 assert.equal(g.blocks.length, 0);
104 g.step(0.99);
105 g.step(0.99);
105 assert.equal(g.blocks.length, 0);
106 assert.equal(g.blocks.length, 0);
test/spawn-speedup.test.js +3 −0
@@ -21,6 +21,7 @@ describe('Spawn speed-up (t1187/t1188)', () =>
21 21 it('every spawned block multiplies the interval by 0.997', () =>
22 22 {
23 23 const g = makeGame({ seed: 2 });
24 g.playTime = 6;
24 25 const b1 = g.trySpawn();
25 26 assert.ok(b1);
26 27 assert.ok(almost(g.spawnInterval, 0.997, 1e-12));
@@ -31,6 +32,7 @@ describe('Spawn speed-up (t1187/t1188)', () =>
31 32 it('no spawn (no open column) → no speed-up', () =>
32 33 {
33 34 const g = makeGame({ seed: 3 });
35 g.playTime = 6;
34 36 for (let c = 0; c < g.width; c++)
35 37 { g.createBlock(c, 12, 0, 'falling'); }
36 38 assert.equal(g.trySpawn(), null);
@@ -59,6 +61,7 @@ describe('Spawn speed-up (t1187/t1188)', () =>
59 61 it('the game tick spawns faster over time (driven by the same logic)', () =>
60 62 {
61 63 const g = makeGame({ seed: 5 });
64 g.playTime = 6;
62 65 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 66 for (let i = 0; i < 60 * 120; i++) g.tick(1 / 60);
64 67 const spawned = g.trySpawn.count();
@@ -21,6 +21,7 @@ describe('Spawn speed-up (t1187/t1188)', () =>
21 it('every spawned block multiplies the interval by 0.997', () =>
21 it('every spawned block multiplies the interval by 0.997', () =>
22 {
22 {
23 const g = makeGame({ seed: 2 });
23 const g = makeGame({ seed: 2 });
24 g.playTime = 6;
24 const b1 = g.trySpawn();
25 const b1 = g.trySpawn();
25 assert.ok(b1);
26 assert.ok(b1);
26 assert.ok(almost(g.spawnInterval, 0.997, 1e-12));
27 assert.ok(almost(g.spawnInterval, 0.997, 1e-12));
@@ -31,6 +32,7 @@ describe('Spawn speed-up (t1187/t1188)', () =>
31 it('no spawn (no open column) → no speed-up', () =>
32 it('no spawn (no open column) → no speed-up', () =>
32 {
33 {
33 const g = makeGame({ seed: 3 });
34 const g = makeGame({ seed: 3 });
35 g.playTime = 6;
34 for (let c = 0; c < g.width; c++)
36 for (let c = 0; c < g.width; c++)
35 { g.createBlock(c, 12, 0, 'falling'); }
37 { g.createBlock(c, 12, 0, 'falling'); }
36 assert.equal(g.trySpawn(), null);
38 assert.equal(g.trySpawn(), null);
@@ -59,6 +61,7 @@ describe('Spawn speed-up (t1187/t1188)', () =>
59 it('the game tick spawns faster over time (driven by the same logic)', () =>
61 it('the game tick spawns faster over time (driven by the same logic)', () =>
60 {
62 {
61 const g = makeGame({ seed: 5 });
63 const g = makeGame({ seed: 5 });
64 g.playTime = 6;
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);
65 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);
66 for (let i = 0; i < 60 * 120; i++) g.tick(1 / 60);
64 const spawned = g.trySpawn.count();
67 const spawned = g.trySpawn.count();
test/spawn-timeline.test.js added +165 −0
@@ -0,0 +1,165 @@
1 'use strict';
2
3 // t1189 / t1191: opening spawn burst (0.1 s for 3 s), lerp to 1 s by 6 s,
4 // then the 0.3% per-spawn speed-up (only spawns after 6 s count).
5
6 const { describe, it } = require('node:test');
7 const assert = require('node:assert/strict');
8 const { makeGame, almost, placeRow } = require('./helpers.js');
9 const { GameCore } = require('../src/gameCore.js');
10
11 function fresh (seed)
12 {
13 const g = makeGame({ seed: seed || 1 });
14 return g;
15 }
16
17 describe('Spawn timeline (t1189/t1191)', () =>
18 {
19 it('constants', () =>
20 {
21 assert.equal(GameCore.SPAWN_INTRO_END, 3);
22 assert.equal(GameCore.SPAWN_INTRO_INTERVAL, 0.1);
23 assert.equal(GameCore.SPAWN_RAMP_END, 6);
24 });
25
26 it('interval: 0.1 s until 3 s, linear to 1 s at 6 s, then the per-spawn rate', () =>
27 {
28 const g = fresh();
29 const at = (t) => { g.playTime = t; return g.currentSpawnInterval(); };
30 assert.equal(at(0), 0.1);
31 assert.equal(at(2.99), 0.1);
32 assert.ok(almost(at(3), 0.1));
33 assert.ok(almost(at(4.5), 0.55));
34 assert.ok(almost(at(5.999), 0.1 + 0.9 * (2.999 / 3), 1e-9));
35 assert.equal(at(6), 1);
36 g.spawnInterval = 0.8;
37 assert.equal(at(7), 0.8);
38 });
39
40 it('no speed-up from blocks spawned before 6 s; after 6 s each spawn ×0.997', () =>
41 {
42 const g = fresh(2);
43 g.playTime = 1;
44 assert.ok(g.trySpawn());
45 g.playTime = 5;
46 assert.ok(g.trySpawn());
47 assert.equal(g.spawnInterval, 1);
48 g.playTime = 6.2;
49 assert.ok(g.trySpawn());
50 assert.ok(almost(g.spawnInterval, 0.997, 1e-12));
51 });
52
53 it('the real tick follows the timeline; play time starts at the first tick', () =>
54 {
55 const g = fresh(3);
56 assert.equal(g.playTime, 0);
57 const ticks = [];
58 const orig = g.trySpawn;
59 g.trySpawn = function ()
60 {
61 ticks.push(+this.playTime.toFixed(4));
62 const b = orig.call(this);
63 if (b) { this.removeBlock(b); } // keep every column open: count spawn ticks
64 return b;
65 };
66 for (let i = 0; i < 60 * 10; i++) g.tick(1 / 60);
67 const inBurst = ticks.filter((t) => t < 3).length;
68 const inRamp = ticks.filter((t) => t >= 3 && t < 6).length;
69 const after = ticks.filter((t) => t >= 6 && t < 10).length;
70 assert.ok(inBurst >= 29 && inBurst <= 31, 'burst ticks ' + inBurst);
71 // ∫ dt / (0.1 + 0.3 (t-3)) over 3..6 = ln(10)/0.3 ≈ 7.7
72 assert.ok(inRamp >= 7 && inRamp <= 9, 'ramp ticks ' + inRamp);
73 assert.ok(after >= 4 && after <= 5, 'after ticks ' + after);
74 assert.ok(ticks.length >= 36 && ticks.length <= 40, 'spawn ticks in first 6 s+ ' + ticks.length);
75 assert.ok(almost(g.playTime, 10, 1e-6));
76 });
77
78 it('first 6 s of a normal game: how many blocks really spawn', () =>
79 {
80 const g = fresh(4);
81 let spawned = 0;
82 const orig = g.trySpawn;
83 g.trySpawn = function () { const b = orig.call(this); if (b && this.playTime < 6) spawned++; return b; };
84 for (let i = 0; i < 60 * 6; i++) g.tick(1 / 60);
85 // One falling block per column at a time limits the burst.
86 assert.ok(spawned >= 12 && spawned <= 38, 'spawned ' + spawned);
87 assert.ok(g.state === 'playing');
88 });
89
90 it('burst column choice is weighted towards emptier columns', () =>
91 {
92 const g = fresh(5);
93 g.spawnInterval = 1; // normal
94 for (let r = 0; r < 10; r++) g.place(0, r, r % 5); // column 0 almost full
95 const counts = new Array(10).fill(0);
96 for (let i = 0; i < 4000; i++)
97 {
98 counts[g.pickWeightedSpawnColumn([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])]++;
99 }
100 // weight col 0 = 3, others 13 → ~2.4% vs ~10.8%
101 assert.ok(counts[0] < 160, 'full-ish column picked ' + counts[0]);
102 for (let c = 1; c < 10; c++) assert.ok(counts[c] > 330, 'col ' + c + ' ' + counts[c]);
103 });
104
105 it('the departing-rocket rule still applies during the burst', () =>
106 {
107 const g = fresh(6);
108 g.spawnInterval = 1e9; // drive manually
109 const row = placeRow(g, 0, [3, 4, 5], 1);
110 const cluster = g.launchCluster(row, 30);
111 for (let i = 0; i < 400 && Math.max(...row.map((b) => b.y)) < 10; i++) g.step(1 / 120, 1 / 120);
112 g.playTime = 1;
113 for (let i = 0; i < 200; i++)
114 {
115 const b = g.trySpawn();
116 assert.ok(b && ![3, 4, 5].includes(b.col), 'col ' + (b && b.col));
117 g.removeBlock(b);
118 }
119 assert.ok(cluster);
120 });
121
122 it('spawning switched off by tools/tests (interval above 1 s) stays off in the burst', () =>
123 {
124 const g = makeGame({ noSpawn: true });
125 for (let i = 0; i < 60 * 4; i++) g.tick(1 / 60);
126 assert.equal(g.blocks.length, 0);
127 });
128
129 it('opening: a column takes the next block once the previous one cleared a cell; later one at a time', () =>
130 {
131 const g = fresh(7);
132 g.playTime = 1;
133 for (let c = 1; c < 10; c++) g.place(c, 0, 0, 'locked');
134 const a = g.trySpawn();
135 assert.equal(a.col, 0);
136 assert.equal(g.trySpawn(), null, 'previous block still in the spawn cell');
137 a.y = 12;
138 const b = g.trySpawn();
139 assert.ok(b && b.col === 0 && b.y - a.y >= 1 - 1e-9, 'second block above, no overlap');
140 g.playTime = 6;
141 a.y = 5; b.y = 9;
142 assert.equal(g.trySpawn(), null, 'after 6 s: one falling block per column');
143 });
144
145 it('a full game through the burst keeps the physics invariants (strict mode)', () =>
146 {
147 for (const seed of [1, 2, 3, 4, 5])
148 {
149 const g = fresh(seed);
150 let spawned = 0;
151 const orig = g.trySpawn;
152 g.trySpawn = function () { const b = orig.call(this); if (b && this.playTime < 6) spawned++; return b; };
153 for (let i = 0; i < 60 * 20 && g.state === 'playing'; i++) g.tick(1 / 60);
154 assert.ok(spawned >= 25, 'seed ' + seed + ' spawned in first 6 s: ' + spawned);
155 // No two blocks overlap in a column.
156 for (let c = 0; c < g.width; c++)
157 {
158 const col = g.blocksInColumn(c);
159 for (let k = 1; k < col.length; k++)
160 { assert.ok(col[k].y - col[k - 1].y >= 1 - 1e-6, 'overlap col ' + c + ' ' + col[k - 1].y + '/' + col[k].y); }
161 }
162 }
163 });
164 });
165
@@ -0,0 +1,165 @@
1'use strict';
2
3// t1189 / t1191: opening spawn burst (0.1 s for 3 s), lerp to 1 s by 6 s,
4// then the 0.3% per-spawn speed-up (only spawns after 6 s count).
5
6const { describe, it } = require('node:test');
7const assert = require('node:assert/strict');
8const { makeGame, almost, placeRow } = require('./helpers.js');
9const { GameCore } = require('../src/gameCore.js');
10
11function fresh (seed)
12{
13 const g = makeGame({ seed: seed || 1 });
14 return g;
15}
16
17describe('Spawn timeline (t1189/t1191)', () =>
18{
19 it('constants', () =>
20 {
21 assert.equal(GameCore.SPAWN_INTRO_END, 3);
22 assert.equal(GameCore.SPAWN_INTRO_INTERVAL, 0.1);
23 assert.equal(GameCore.SPAWN_RAMP_END, 6);
24 });
25
26 it('interval: 0.1 s until 3 s, linear to 1 s at 6 s, then the per-spawn rate', () =>
27 {
28 const g = fresh();
29 const at = (t) => { g.playTime = t; return g.currentSpawnInterval(); };
30 assert.equal(at(0), 0.1);
31 assert.equal(at(2.99), 0.1);
32 assert.ok(almost(at(3), 0.1));
33 assert.ok(almost(at(4.5), 0.55));
34 assert.ok(almost(at(5.999), 0.1 + 0.9 * (2.999 / 3), 1e-9));
35 assert.equal(at(6), 1);
36 g.spawnInterval = 0.8;
37 assert.equal(at(7), 0.8);
38 });
39
40 it('no speed-up from blocks spawned before 6 s; after 6 s each spawn ×0.997', () =>
41 {
42 const g = fresh(2);
43 g.playTime = 1;
44 assert.ok(g.trySpawn());
45 g.playTime = 5;
46 assert.ok(g.trySpawn());
47 assert.equal(g.spawnInterval, 1);
48 g.playTime = 6.2;
49 assert.ok(g.trySpawn());
50 assert.ok(almost(g.spawnInterval, 0.997, 1e-12));
51 });
52
53 it('the real tick follows the timeline; play time starts at the first tick', () =>
54 {
55 const g = fresh(3);
56 assert.equal(g.playTime, 0);
57 const ticks = [];
58 const orig = g.trySpawn;
59 g.trySpawn = function ()
60 {
61 ticks.push(+this.playTime.toFixed(4));
62 const b = orig.call(this);
63 if (b) { this.removeBlock(b); } // keep every column open: count spawn ticks
64 return b;
65 };
66 for (let i = 0; i < 60 * 10; i++) g.tick(1 / 60);
67 const inBurst = ticks.filter((t) => t < 3).length;
68 const inRamp = ticks.filter((t) => t >= 3 && t < 6).length;
69 const after = ticks.filter((t) => t >= 6 && t < 10).length;
70 assert.ok(inBurst >= 29 && inBurst <= 31, 'burst ticks ' + inBurst);
71 // ∫ dt / (0.1 + 0.3 (t-3)) over 3..6 = ln(10)/0.3 ≈ 7.7
72 assert.ok(inRamp >= 7 && inRamp <= 9, 'ramp ticks ' + inRamp);
73 assert.ok(after >= 4 && after <= 5, 'after ticks ' + after);
74 assert.ok(ticks.length >= 36 && ticks.length <= 40, 'spawn ticks in first 6 s+ ' + ticks.length);
75 assert.ok(almost(g.playTime, 10, 1e-6));
76 });
77
78 it('first 6 s of a normal game: how many blocks really spawn', () =>
79 {
80 const g = fresh(4);
81 let spawned = 0;
82 const orig = g.trySpawn;
83 g.trySpawn = function () { const b = orig.call(this); if (b && this.playTime < 6) spawned++; return b; };
84 for (let i = 0; i < 60 * 6; i++) g.tick(1 / 60);
85 // One falling block per column at a time limits the burst.
86 assert.ok(spawned >= 12 && spawned <= 38, 'spawned ' + spawned);
87 assert.ok(g.state === 'playing');
88 });
89
90 it('burst column choice is weighted towards emptier columns', () =>
91 {
92 const g = fresh(5);
93 g.spawnInterval = 1; // normal
94 for (let r = 0; r < 10; r++) g.place(0, r, r % 5); // column 0 almost full
95 const counts = new Array(10).fill(0);
96 for (let i = 0; i < 4000; i++)
97 {
98 counts[g.pickWeightedSpawnColumn([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])]++;
99 }
100 // weight col 0 = 3, others 13 → ~2.4% vs ~10.8%
101 assert.ok(counts[0] < 160, 'full-ish column picked ' + counts[0]);
102 for (let c = 1; c < 10; c++) assert.ok(counts[c] > 330, 'col ' + c + ' ' + counts[c]);
103 });
104
105 it('the departing-rocket rule still applies during the burst', () =>
106 {
107 const g = fresh(6);
108 g.spawnInterval = 1e9; // drive manually
109 const row = placeRow(g, 0, [3, 4, 5], 1);
110 const cluster = g.launchCluster(row, 30);
111 for (let i = 0; i < 400 && Math.max(...row.map((b) => b.y)) < 10; i++) g.step(1 / 120, 1 / 120);
112 g.playTime = 1;
113 for (let i = 0; i < 200; i++)
114 {
115 const b = g.trySpawn();
116 assert.ok(b && ![3, 4, 5].includes(b.col), 'col ' + (b && b.col));
117 g.removeBlock(b);
118 }
119 assert.ok(cluster);
120 });
121
122 it('spawning switched off by tools/tests (interval above 1 s) stays off in the burst', () =>
123 {
124 const g = makeGame({ noSpawn: true });
125 for (let i = 0; i < 60 * 4; i++) g.tick(1 / 60);
126 assert.equal(g.blocks.length, 0);
127 });
128
129 it('opening: a column takes the next block once the previous one cleared a cell; later one at a time', () =>
130 {
131 const g = fresh(7);
132 g.playTime = 1;
133 for (let c = 1; c < 10; c++) g.place(c, 0, 0, 'locked');
134 const a = g.trySpawn();
135 assert.equal(a.col, 0);
136 assert.equal(g.trySpawn(), null, 'previous block still in the spawn cell');
137 a.y = 12;
138 const b = g.trySpawn();
139 assert.ok(b && b.col === 0 && b.y - a.y >= 1 - 1e-9, 'second block above, no overlap');
140 g.playTime = 6;
141 a.y = 5; b.y = 9;
142 assert.equal(g.trySpawn(), null, 'after 6 s: one falling block per column');
143 });
144
145 it('a full game through the burst keeps the physics invariants (strict mode)', () =>
146 {
147 for (const seed of [1, 2, 3, 4, 5])
148 {
149 const g = fresh(seed);
150 let spawned = 0;
151 const orig = g.trySpawn;
152 g.trySpawn = function () { const b = orig.call(this); if (b && this.playTime < 6) spawned++; return b; };
153 for (let i = 0; i < 60 * 20 && g.state === 'playing'; i++) g.tick(1 / 60);
154 assert.ok(spawned >= 25, 'seed ' + seed + ' spawned in first 6 s: ' + spawned);
155 // No two blocks overlap in a column.
156 for (let c = 0; c < g.width; c++)
157 {
158 const col = g.blocksInColumn(c);
159 for (let k = 1; k < col.length; k++)
160 { assert.ok(col[k].y - col[k - 1].y >= 1 - 1e-6, 'overlap col ' + c + ' ' + col[k - 1].y + '/' + col[k].y); }
161 }
162 }
163 });
164});
165
test/t1189-spawn-timeline-playwright.py added +89 −0
@@ -0,0 +1,89 @@
1 #!/usr/bin/env python3
2 """t1189/t1191: measure the opening spawn timeline in a real browser.
3
4 Usage: python3 test/t1189-spawn-timeline-playwright.py URL TAG
5 Wraps GameCore.prototype.trySpawn before the game starts, plays 12 s of
6 a logged-out solo game and records every spawn tick (play time, interval,
7 whether a block appeared) plus per-frame interval samples.
8 """
9 import json, sys
10 from pathlib import Path
11 from playwright.sync_api import sync_playwright
12
13 URL = sys.argv[1] if len(sys.argv) > 1 else "https://projects.timfalken.com/meteors/"
14 TAG = sys.argv[2] if len(sys.argv) > 2 else "live"
15 SHOTS = Path("/workspace/meteors-shots")
16 fails = []
17
18 def check(c, m):
19 print(("OK " if c else "FAIL ") + m)
20 if not c: fails.append(m)
21
22 HOOK = """() => {
23 const R = window.__sp = { ticks: [], samples: [] };
24 const orig = GameCore.prototype.trySpawn;
25 GameCore.prototype.trySpawn = function () {
26 const t = this.playTime, iv = this.currentSpawnInterval();
27 const b = orig.apply(this, arguments);
28 if (this === app.core) R.ticks.push([+t.toFixed(3), +iv.toFixed(4), b ? b.col : null, +this.spawnInterval.toFixed(4)]);
29 return b;
30 };
31 const loop = () => { if (window.app && app.core) R.samples.push([+app.core.playTime.toFixed(3), +app.core.currentSpawnInterval().toFixed(4)]); requestAnimationFrame(loop); };
32 requestAnimationFrame(loop);
33 }"""
34
35 out = {}
36 with sync_playwright() as pw:
37 br = pw.chromium.launch(args=["--use-gl=angle", "--use-angle=swiftshader"])
38 for name, vp, mobile in (("desktop", {"width": 1280, "height": 800}, False), ("mobile", {"width": 390, "height": 844}, True)):
39 ctx = br.new_context(viewport=vp, is_mobile=mobile, has_touch=mobile, device_scale_factor=3 if mobile else 1)
40 page = ctx.new_page()
41 errors = []
42 page.on("pageerror", lambda e: errors.append(str(e)))
43 page.goto(URL + ("" if URL.endswith("/") else "/") + "index.html?t1189=" + TAG, wait_until="networkidle")
44 consts = page.evaluate("() => [GameCore.SPAWN_INTRO_END, GameCore.SPAWN_INTRO_INTERVAL, GameCore.SPAWN_RAMP_END, GameCore.SPAWN_SPEEDUP, GameCore.SPAWN_INTERVAL_MIN]")
45 page.evaluate(HOOK)
46 page.locator("#btn-play").click()
47 page.wait_for_selector("#planet-select:not([hidden])", timeout=8000)
48 page.wait_for_timeout(200)
49 page.locator("#btn-planet-go").click()
50 page.wait_for_function("() => window.app && app.mode === 'playing' && app.core", timeout=10000)
51 page.wait_for_function("() => app.core.playTime >= 2.5", timeout=10000, polling="raf")
52 page.screenshot(path=str(SHOTS / f"t1189-{TAG}-{name}-burst-2.5s.png"))
53 page.wait_for_function("() => app.core.playTime >= 6.0", timeout=15000, polling="raf")
54 page.screenshot(path=str(SHOTS / f"t1189-{TAG}-{name}-6s.png"))
55 page.wait_for_function("() => app.core.playTime >= 12 || app.core.state !== 'playing'", timeout=20000, polling="raf")
56 d = page.evaluate("() => window.__sp")
57 ctx.close()
58 ticks = d["ticks"]; samples = d["samples"]
59 def seg(a, b): return [t for t in ticks if a <= t[0] < b]
60 def iv_at(t):
61 best = min(samples, key=lambda s: abs(s[0] - t))
62 return best[1]
63 r = {
64 "constants": dict(zip(["intro_end", "intro_interval", "ramp_end", "speedup", "min"], consts)),
65 "interval_at": {str(t): iv_at(t) for t in (0.5, 2.0, 2.9, 3.5, 4.5, 5.5, 6.5, 9, 11.5)},
66 "ticks_0_3": len(seg(0, 3)), "spawned_0_3": sum(1 for t in seg(0, 3) if t[2] is not None),
67 "ticks_3_6": len(seg(3, 6)), "spawned_3_6": sum(1 for t in seg(3, 6) if t[2] is not None),
68 "ticks_6_12": len(seg(6, 12)), "spawned_6_12": sum(1 for t in seg(6, 12) if t[2] is not None),
69 "spawn_interval_at_12s": ticks[-1][3] if ticks else None,
70 "gaps_ramp": [round(b[0] - a[0], 3) for a, b in zip(seg(3, 6.5), seg(3, 6.5)[1:])],
71 "errors": errors,
72 }
73 r["spawned_0_6"] = r["spawned_0_3"] + r["spawned_3_6"]
74 r["ticks_0_6"] = r["ticks_0_3"] + r["ticks_3_6"]
75 out[name] = r
76 print(name, json.dumps(r))
77 ia = r["interval_at"]
78 check(r["constants"]["intro_end"] == 3 and r["constants"]["ramp_end"] == 6, f"{name}: constants {r['constants']}")
79 check(ia["0.5"] == 0.1 and ia["2.9"] == 0.1, f"{name}: 0.1 s during the burst")
80 check(abs(ia["4.5"] - 0.55) < 0.03, f"{name}: ~0.55 s halfway through the ramp ({ia['4.5']})")
81 check(0.95 <= ia["6.5"] <= 1.0 and ia["11.5"] < ia["6.5"], f"{name}: ~1 s after 6 s, then shrinking ({ia['6.5']} → {ia['11.5']})")
82 check(28 <= r["ticks_0_3"] <= 31, f"{name}: {r['ticks_0_3']} spawn ticks in 0–3 s")
83 check(6 <= r["ticks_3_6"] <= 9, f"{name}: {r['ticks_3_6']} spawn ticks in 3–6 s")
84 check(r["spawned_0_3"] >= 25, f"{name}: {r['spawned_0_3']} blocks really spawned in 0–3 s")
85 check(not errors, f"{name}: no page errors")
86 br.close()
87 (SHOTS / f"t1189-{TAG}-metrics.json").write_text(json.dumps(out, indent=1))
88 print("ALL OK" if not fails else f"{len(fails)} FAIL")
89 sys.exit(1 if fails else 0)
@@ -0,0 +1,89 @@
1#!/usr/bin/env python3
2"""t1189/t1191: measure the opening spawn timeline in a real browser.
3
4Usage: python3 test/t1189-spawn-timeline-playwright.py URL TAG
5Wraps GameCore.prototype.trySpawn before the game starts, plays 12 s of
6a logged-out solo game and records every spawn tick (play time, interval,
7whether a block appeared) plus per-frame interval samples.
8"""
9import json, sys
10from pathlib import Path
11from playwright.sync_api import sync_playwright
12
13URL = sys.argv[1] if len(sys.argv) > 1 else "https://projects.timfalken.com/meteors/"
14TAG = sys.argv[2] if len(sys.argv) > 2 else "live"
15SHOTS = Path("/workspace/meteors-shots")
16fails = []
17
18def check(c, m):
19 print(("OK " if c else "FAIL ") + m)
20 if not c: fails.append(m)
21
22HOOK = """() => {
23 const R = window.__sp = { ticks: [], samples: [] };
24 const orig = GameCore.prototype.trySpawn;
25 GameCore.prototype.trySpawn = function () {
26 const t = this.playTime, iv = this.currentSpawnInterval();
27 const b = orig.apply(this, arguments);
28 if (this === app.core) R.ticks.push([+t.toFixed(3), +iv.toFixed(4), b ? b.col : null, +this.spawnInterval.toFixed(4)]);
29 return b;
30 };
31 const loop = () => { if (window.app && app.core) R.samples.push([+app.core.playTime.toFixed(3), +app.core.currentSpawnInterval().toFixed(4)]); requestAnimationFrame(loop); };
32 requestAnimationFrame(loop);
33}"""
34
35out = {}
36with sync_playwright() as pw:
37 br = pw.chromium.launch(args=["--use-gl=angle", "--use-angle=swiftshader"])
38 for name, vp, mobile in (("desktop", {"width": 1280, "height": 800}, False), ("mobile", {"width": 390, "height": 844}, True)):
39 ctx = br.new_context(viewport=vp, is_mobile=mobile, has_touch=mobile, device_scale_factor=3 if mobile else 1)
40 page = ctx.new_page()
41 errors = []
42 page.on("pageerror", lambda e: errors.append(str(e)))
43 page.goto(URL + ("" if URL.endswith("/") else "/") + "index.html?t1189=" + TAG, wait_until="networkidle")
44 consts = page.evaluate("() => [GameCore.SPAWN_INTRO_END, GameCore.SPAWN_INTRO_INTERVAL, GameCore.SPAWN_RAMP_END, GameCore.SPAWN_SPEEDUP, GameCore.SPAWN_INTERVAL_MIN]")
45 page.evaluate(HOOK)
46 page.locator("#btn-play").click()
47 page.wait_for_selector("#planet-select:not([hidden])", timeout=8000)
48 page.wait_for_timeout(200)
49 page.locator("#btn-planet-go").click()
50 page.wait_for_function("() => window.app && app.mode === 'playing' && app.core", timeout=10000)
51 page.wait_for_function("() => app.core.playTime >= 2.5", timeout=10000, polling="raf")
52 page.screenshot(path=str(SHOTS / f"t1189-{TAG}-{name}-burst-2.5s.png"))
53 page.wait_for_function("() => app.core.playTime >= 6.0", timeout=15000, polling="raf")
54 page.screenshot(path=str(SHOTS / f"t1189-{TAG}-{name}-6s.png"))
55 page.wait_for_function("() => app.core.playTime >= 12 || app.core.state !== 'playing'", timeout=20000, polling="raf")
56 d = page.evaluate("() => window.__sp")
57 ctx.close()
58 ticks = d["ticks"]; samples = d["samples"]
59 def seg(a, b): return [t for t in ticks if a <= t[0] < b]
60 def iv_at(t):
61 best = min(samples, key=lambda s: abs(s[0] - t))
62 return best[1]
63 r = {
64 "constants": dict(zip(["intro_end", "intro_interval", "ramp_end", "speedup", "min"], consts)),
65 "interval_at": {str(t): iv_at(t) for t in (0.5, 2.0, 2.9, 3.5, 4.5, 5.5, 6.5, 9, 11.5)},
66 "ticks_0_3": len(seg(0, 3)), "spawned_0_3": sum(1 for t in seg(0, 3) if t[2] is not None),
67 "ticks_3_6": len(seg(3, 6)), "spawned_3_6": sum(1 for t in seg(3, 6) if t[2] is not None),
68 "ticks_6_12": len(seg(6, 12)), "spawned_6_12": sum(1 for t in seg(6, 12) if t[2] is not None),
69 "spawn_interval_at_12s": ticks[-1][3] if ticks else None,
70 "gaps_ramp": [round(b[0] - a[0], 3) for a, b in zip(seg(3, 6.5), seg(3, 6.5)[1:])],
71 "errors": errors,
72 }
73 r["spawned_0_6"] = r["spawned_0_3"] + r["spawned_3_6"]
74 r["ticks_0_6"] = r["ticks_0_3"] + r["ticks_3_6"]
75 out[name] = r
76 print(name, json.dumps(r))
77 ia = r["interval_at"]
78 check(r["constants"]["intro_end"] == 3 and r["constants"]["ramp_end"] == 6, f"{name}: constants {r['constants']}")
79 check(ia["0.5"] == 0.1 and ia["2.9"] == 0.1, f"{name}: 0.1 s during the burst")
80 check(abs(ia["4.5"] - 0.55) < 0.03, f"{name}: ~0.55 s halfway through the ramp ({ia['4.5']})")
81 check(0.95 <= ia["6.5"] <= 1.0 and ia["11.5"] < ia["6.5"], f"{name}: ~1 s after 6 s, then shrinking ({ia['6.5']} → {ia['11.5']})")
82 check(28 <= r["ticks_0_3"] <= 31, f"{name}: {r['ticks_0_3']} spawn ticks in 0–3 s")
83 check(6 <= r["ticks_3_6"] <= 9, f"{name}: {r['ticks_3_6']} spawn ticks in 3–6 s")
84 check(r["spawned_0_3"] >= 25, f"{name}: {r['spawned_0_3']} blocks really spawned in 0–3 s")
85 check(not errors, f"{name}: no page errors")
86 br.close()
87(SHOTS / f"t1189-{TAG}-metrics.json").write_text(json.dumps(out, indent=1))
88print("ALL OK" if not fails else f"{len(fails)} FAIL")
89sys.exit(1 if fails else 0)