BlueGit

projects-timfalken-com meteors

Merge branch 'feature/t1184-skip-departing'

timfa Grok Bot · pushed by timfa

Authored 2026-11-14 · 3 days ago

Hash
fe5a790e32618200a10b29b96ea7ebf900fedc18
Pipeline
Passed
7 files changed +571 −0
README.md +10 −0
@@ -196,6 +196,16 @@ op een stapel weer een kleur krijgt. Wie al zijn kolommen vol heeft, is toeschou
196 196 en geen doelwit meer. De laatste die overblijft wint; 1e/2e/3e staan 5 seconden
197 197 op het podium en daarna ga je terug naar de lobby.
198 198
199 ### Vallende blokken en vertrekkende raketten
200
201 - Vliegt een raketstapel omhoog, is het hoogste blok voorbij 75% van de
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
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.
208
199 209 ### Raketvlam
200 210
201 211 De vlam onder een raketblok wisselt 25 keer per seconde naar een willekeurig
@@ -196,6 +196,16 @@ op een stapel weer een kleur krijgt. Wie al zijn kolommen vol heeft, is toeschou
196en geen doelwit meer. De laatste die overblijft wint; 1e/2e/3e staan 5 seconden
196en geen doelwit meer. De laatste die overblijft wint; 1e/2e/3e staan 5 seconden
197op het podium en daarna ga je terug naar de lobby.
197op het podium en daarna ga je terug naar de lobby.
198
198
199### Vallende blokken en vertrekkende raketten
200
201- Vliegt een raketstapel omhoog, is het hoogste blok voorbij 75% van de
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
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.
208
199### Raketvlam
209### Raketvlam
200
210
201De vlam onder een raketblok wisselt 25 keer per seconde naar een willekeurig
211De vlam onder een raketblok wisselt 25 keer per seconde naar een willekeurig
build/game.js +109 −0
@@ -5730,17 +5730,96 @@ GameCore.prototype.step = function (seconds, dt)
5730 5730 }
5731 5731 };
5732 5732
5733 /** Share of the field height a rising stack must pass (t1184). */
5734 GameCore.DEPART_SHARE = 0.75;
5735
5736 /**
5737 * Columns with a rising rocket stack that will certainly leave the
5738 * screen (t1184). A flying cluster counts when it is still going up,
5739 * its highest block is past DEPART_SHARE of the field height, its apex
5740 * (y + vy^2 / (2 * decel)) is at or above the top, and nothing grounded
5741 * hangs above it in its columns. Every column that stack occupies is
5742 * departing: newly spawned blocks and received garbage pick another
5743 * column (t1185/t1186). Returns { col: true }.
5744 */
5745 GameCore.prototype.departingColumns = function ()
5746 {
5747 var out = Object.create(null);
5748 var H = this.height;
5749 var ids = Object.keys(this.clusters);
5750 for (var n = 0; n < ids.length; n++)
5751 {
5752 var cluster = this.clusters[ids[n]];
5753 if (!cluster || cluster.phase !== 'up' || !(cluster.vy > 1e-9))
5754 { continue; }
5755 var members = this.clusterMembers(cluster.id);
5756 if (!members.length)
5757 { continue; }
5758 var top = -Infinity;
5759 var lowest = Object.create(null);
5760 for (var i = 0; i < members.length; i++)
5761 {
5762 var m = members[i];
5763 if (m.state !== STATE_FLYING)
5764 { continue; }
5765 if (m.y > top)
5766 { top = m.y; }
5767 if (lowest[m.col] == null || m.y < lowest[m.col])
5768 { lowest[m.col] = m.y; }
5769 }
5770 if (top < this.DEPART_LINE())
5771 { continue; }
5772 var decel = cluster.decel || 0;
5773 var rise = decel > 1e-12 ? (cluster.vy * cluster.vy) / (2 * decel) : Infinity;
5774 if (top + rise < H - 1e-9)
5775 { continue; }
5776 var blocked = false;
5777 for (var col in lowest)
5778 {
5779 var c = col | 0;
5780 for (var j = 0; j < this.blocks.length; j++)
5781 {
5782 var b = this.blocks[j];
5783 if (b.col === c && b.clusterId !== cluster.id && this.isGrounded(b) && b.y > lowest[col])
5784 {
5785 blocked = true;
5786 break;
5787 }
5788 }
5789 if (blocked)
5790 { break; }
5791 }
5792 if (blocked)
5793 { continue; }
5794 // t1185/t1186: every column the departing stack occupies is off
5795 // limits; new and received blocks pick another column.
5796 for (var col2 in lowest)
5797 { out[col2 | 0] = true; }
5798 }
5799 return out;
5800 };
5801
5802 /** Height (tiles from the ground) a rising stack must pass: 75% of the field. */
5803 GameCore.prototype.DEPART_LINE = function ()
5804 {
5805 return this.height * GameCore.DEPART_SHARE;
5806 };
5807
5733 5808 GameCore.prototype.trySpawn = function ()
5734 5809 {
5735 5810 if (this.state !== 'playing')
5736 5811 { return null; }
5737 5812 var eligible = [];
5813 var departing = this.departingColumns();
5738 5814 for (var col = 0; col < this.width; col++)
5739 5815 {
5740 5816 if (this.isColumnLocked(col))
5741 5817 { continue; }
5742 5818 if (this.groundedCount(col) >= this.height)
5743 5819 { continue; }
5820 // t1184: never drop a new block onto a stack that is leaving.
5821 if (departing[col])
5822 { continue; }
5744 5823 var alreadyFalling = false;
5745 5824 var list = this.blocksInColumn(col);
5746 5825 for (var i = 0; i < list.length; i++)
@@ -5760,9 +5839,28 @@ GameCore.prototype.trySpawn = function ()
5760 5839 var color = this.randomColor();
5761 5840 var block = this.createBlock(col, this.height, color, STATE_FALLING);
5762 5841 block.vy = -this.planet.fallSpeed;
5842 this.speedUpSpawning();
5763 5843 return block;
5764 5844 };
5765 5845
5846 /** Each spawned block shrinks the spawn interval by 0.3% (t1187 / t1188). */
5847 GameCore.SPAWN_SPEEDUP = 0.997;
5848 /** The spawn interval never goes below this (seconds, t1187). */
5849 GameCore.SPAWN_INTERVAL_MIN = 0.1;
5850
5851 /**
5852 * After every real spawn: spawnInterval *= SPAWN_SPEEDUP, floored at
5853 * SPAWN_INTERVAL_MIN. Starts at PlanetMod.SPAWN_INTERVAL (1 s) for every
5854 * new core, i.e. every game and every round, for players and bots alike.
5855 * Reaches the floor after ~767 spawns (~5 min of continuous play).
5856 */
5857 GameCore.prototype.speedUpSpawning = function ()
5858 {
5859 var next = this.spawnInterval * GameCore.SPAWN_SPEEDUP;
5860 this.spawnInterval = Math.max(GameCore.SPAWN_INTERVAL_MIN, next);
5861 return this.spawnInterval;
5862 };
5863
5766 5864 GameCore.prototype.integrateFalling = function (dt)
5767 5865 {
5768 5866 var falling = [];
@@ -7180,6 +7278,17 @@ GameCore.prototype.pickGarbageColumn = function (preferred)
7180 7278 var eligible = this.eligibleGarbageColumns();
7181 7279 if (!eligible.length)
7182 7280 { return null; }
7281 // t1184: skip columns whose rocket stack is certainly leaving; only
7282 // if every open column is departing, fall back so no garbage is lost.
7283 var departing = this.departingColumns();
7284 var staying = [];
7285 for (var k = 0; k < eligible.length; k++)
7286 {
7287 if (!departing[eligible[k]])
7288 { staying.push(eligible[k]); }
7289 }
7290 if (staying.length)
7291 { eligible = staying; }
7183 7292 if (preferred != null && isFinite(preferred))
7184 7293 {
7185 7294 var want = preferred | 0;
@@ -5730,17 +5730,96 @@ GameCore.prototype.step = function (seconds, dt)
5730 }
5730 }
5731};
5731};
5732
5732
5733/** Share of the field height a rising stack must pass (t1184). */
5734GameCore.DEPART_SHARE = 0.75;
5735
5736/**
5737 * Columns with a rising rocket stack that will certainly leave the
5738 * screen (t1184). A flying cluster counts when it is still going up,
5739 * its highest block is past DEPART_SHARE of the field height, its apex
5740 * (y + vy^2 / (2 * decel)) is at or above the top, and nothing grounded
5741 * hangs above it in its columns. Every column that stack occupies is
5742 * departing: newly spawned blocks and received garbage pick another
5743 * column (t1185/t1186). Returns { col: true }.
5744 */
5745GameCore.prototype.departingColumns = function ()
5746{
5747 var out = Object.create(null);
5748 var H = this.height;
5749 var ids = Object.keys(this.clusters);
5750 for (var n = 0; n < ids.length; n++)
5751 {
5752 var cluster = this.clusters[ids[n]];
5753 if (!cluster || cluster.phase !== 'up' || !(cluster.vy > 1e-9))
5754 { continue; }
5755 var members = this.clusterMembers(cluster.id);
5756 if (!members.length)
5757 { continue; }
5758 var top = -Infinity;
5759 var lowest = Object.create(null);
5760 for (var i = 0; i < members.length; i++)
5761 {
5762 var m = members[i];
5763 if (m.state !== STATE_FLYING)
5764 { continue; }
5765 if (m.y > top)
5766 { top = m.y; }
5767 if (lowest[m.col] == null || m.y < lowest[m.col])
5768 { lowest[m.col] = m.y; }
5769 }
5770 if (top < this.DEPART_LINE())
5771 { continue; }
5772 var decel = cluster.decel || 0;
5773 var rise = decel > 1e-12 ? (cluster.vy * cluster.vy) / (2 * decel) : Infinity;
5774 if (top + rise < H - 1e-9)
5775 { continue; }
5776 var blocked = false;
5777 for (var col in lowest)
5778 {
5779 var c = col | 0;
5780 for (var j = 0; j < this.blocks.length; j++)
5781 {
5782 var b = this.blocks[j];
5783 if (b.col === c && b.clusterId !== cluster.id && this.isGrounded(b) && b.y > lowest[col])
5784 {
5785 blocked = true;
5786 break;
5787 }
5788 }
5789 if (blocked)
5790 { break; }
5791 }
5792 if (blocked)
5793 { continue; }
5794 // t1185/t1186: every column the departing stack occupies is off
5795 // limits; new and received blocks pick another column.
5796 for (var col2 in lowest)
5797 { out[col2 | 0] = true; }
5798 }
5799 return out;
5800};
5801
5802/** Height (tiles from the ground) a rising stack must pass: 75% of the field. */
5803GameCore.prototype.DEPART_LINE = function ()
5804{
5805 return this.height * GameCore.DEPART_SHARE;
5806};
5807
5733GameCore.prototype.trySpawn = function ()
5808GameCore.prototype.trySpawn = function ()
5734{
5809{
5735 if (this.state !== 'playing')
5810 if (this.state !== 'playing')
5736 { return null; }
5811 { return null; }
5737 var eligible = [];
5812 var eligible = [];
5813 var departing = this.departingColumns();
5738 for (var col = 0; col < this.width; col++)
5814 for (var col = 0; col < this.width; col++)
5739 {
5815 {
5740 if (this.isColumnLocked(col))
5816 if (this.isColumnLocked(col))
5741 { continue; }
5817 { continue; }
5742 if (this.groundedCount(col) >= this.height)
5818 if (this.groundedCount(col) >= this.height)
5743 { continue; }
5819 { continue; }
5820 // t1184: never drop a new block onto a stack that is leaving.
5821 if (departing[col])
5822 { continue; }
5744 var alreadyFalling = false;
5823 var alreadyFalling = false;
5745 var list = this.blocksInColumn(col);
5824 var list = this.blocksInColumn(col);
5746 for (var i = 0; i < list.length; i++)
5825 for (var i = 0; i < list.length; i++)
@@ -5760,9 +5839,28 @@ GameCore.prototype.trySpawn = function ()
5760 var color = this.randomColor();
5839 var color = this.randomColor();
5761 var block = this.createBlock(col, this.height, color, STATE_FALLING);
5840 var block = this.createBlock(col, this.height, color, STATE_FALLING);
5762 block.vy = -this.planet.fallSpeed;
5841 block.vy = -this.planet.fallSpeed;
5842 this.speedUpSpawning();
5763 return block;
5843 return block;
5764};
5844};
5765
5845
5846/** Each spawned block shrinks the spawn interval by 0.3% (t1187 / t1188). */
5847GameCore.SPAWN_SPEEDUP = 0.997;
5848/** The spawn interval never goes below this (seconds, t1187). */
5849GameCore.SPAWN_INTERVAL_MIN = 0.1;
5850
5851/**
5852 * After every real spawn: spawnInterval *= SPAWN_SPEEDUP, floored at
5853 * SPAWN_INTERVAL_MIN. Starts at PlanetMod.SPAWN_INTERVAL (1 s) for every
5854 * new core, i.e. every game and every round, for players and bots alike.
5855 * Reaches the floor after ~767 spawns (~5 min of continuous play).
5856 */
5857GameCore.prototype.speedUpSpawning = function ()
5858{
5859 var next = this.spawnInterval * GameCore.SPAWN_SPEEDUP;
5860 this.spawnInterval = Math.max(GameCore.SPAWN_INTERVAL_MIN, next);
5861 return this.spawnInterval;
5862};
5863
5766GameCore.prototype.integrateFalling = function (dt)
5864GameCore.prototype.integrateFalling = function (dt)
5767{
5865{
5768 var falling = [];
5866 var falling = [];
@@ -7180,6 +7278,17 @@ GameCore.prototype.pickGarbageColumn = function (preferred)
7180 var eligible = this.eligibleGarbageColumns();
7278 var eligible = this.eligibleGarbageColumns();
7181 if (!eligible.length)
7279 if (!eligible.length)
7182 { return null; }
7280 { return null; }
7281 // t1184: skip columns whose rocket stack is certainly leaving; only
7282 // if every open column is departing, fall back so no garbage is lost.
7283 var departing = this.departingColumns();
7284 var staying = [];
7285 for (var k = 0; k < eligible.length; k++)
7286 {
7287 if (!departing[eligible[k]])
7288 { staying.push(eligible[k]); }
7289 }
7290 if (staying.length)
7291 { eligible = staying; }
7183 if (preferred != null && isFinite(preferred))
7292 if (preferred != null && isFinite(preferred))
7184 {
7293 {
7185 var want = preferred | 0;
7294 var want = preferred | 0;
docs/ASSUMPTIONS.md +51 −0
@@ -1025,3 +1025,54 @@ Tests: `test/mini-predict.test.js`, plus de mini-meting in
1025 1025
1026 1026 Tests: `test/flame-fx.test.js`; browser: `test/t1183-flame-playwright.py URL TAG`.
1027 1027
1028 ## t1184 / t1185 / t1186 — niet laten vallen op een vertrekkende raket
1029
1030 Tims woorden: "blokjes niet laten vallen op rijen waarvan nu blokken omhoog
1031 vliegen waarvan de hoogste voorbij 75% vanaf de grond is die zeker het
1032 scherm gaan verlaten".
1033
1034 - **"Rijen" = kolommen.** Blokken vallen per kolom (10 breed, 13 hoog) en
1035 een raket (vliegend cluster) stijgt in de kolommen waarin hij zit.
1036 - **Vertrekkende stapel** (`GameCore.departingColumns`): een vliegend
1037 cluster dat nog stijgt (`phase 'up'`), waarvan het hoogste blok op of
1038 boven `0,75 × 13 = 9,75` staat (`GameCore.DEPART_SHARE`), waarvan de
1039 top (y + vy²/(2·decel)) de bovenrand haalt ("zeker het scherm uit"), en
1040 waar in zijn kolommen geen vast blok boven hangt. Alle kolommen waarin
1041 dat cluster blokken heeft tellen als vertrekkend.
1042 - **Nieuwe blokken** (`trySpawn`) slaan die kolommen over. Zijn alle open
1043 kolommen vertrekkend, dan valt er die tik niets (de volgende spawn-tik
1044 probeert opnieuw).
1045 - **Ontvangen blokken** (garbage van een tegenstander of bot,
1046 `ingestGarbage` / `pickGarbageColumn`): de gewenste kolom (`land_col` van
1047 de server) wint alleen als die niet vertrekkend is; anders een
1048 willekeurige andere open kolom. Zijn alle open kolommen vertrekkend, dan
1049 valt het blok toch (in de gewenste kolom), zodat er nooit garbage
1050 verdwijnt.
1051 - Ze vallen dus niet door de raket heen en ook niet erop: ze kiezen een
1052 andere kolom. Blokken die al vielen voordat de stapel de 75% passeerde
1053 houden de bestaande regels (ze kunnen als lading meeliften).
1054 - **Online consistent:** elk veld wordt door de eigen client gesimuleerd
1055 met dezelfde gedeelde `GameCore` (solo, offline met bots en online). De
1056 server kiest alleen een voorkeurskolom (`land_col`, willekeurig 0–9) en
1057 hoeft niets te weten van raketten; de client wijkt uit zoals bij volle
1058 of geblokkeerde kolommen (t1126). De vluchtanimatie mikt nog op
1059 `land_col`; het blok verschijnt dan in de gekozen kolom.
1060
1061 Tests: `test/departing.test.js`; browser:
1062 `test/t1184-departing-playwright.py URL TAG` (desktop + mobiel).
1063
1064 ## t1187 / t1188 — spawn-tempo loopt op
1065
1066 - Na elk echt gespawnd blok (`trySpawn` die een blok maakt):
1067 `spawnInterval *= GameCore.SPAWN_SPEEDUP` (0,997 = 0,3% korter; eerst
1068 3% gevraagd, door Tim aangepast naar 0,3%).
1069 - Start `PlanetMod.SPAWN_INTERVAL` = 1 s; minimum
1070 `GameCore.SPAWN_INTERVAL_MIN` = 0,1 s (aanname, Tim kan dit aanpassen).
1071 - Het minimum wordt bereikt na ca. 767 blokken, ongeveer 300 s (5 min).
1072 - Geen spawn (alle kolommen dicht of vertrekkend) = geen versnelling.
1073 - Elk spel en elke ronde maakt een nieuwe `GameCore`, dus het tempo begint
1074 steeds weer op 1 s. Spelers en bots (offline) en online velden gebruiken
1075 dezelfde code.
1076
1077 Tests: `test/spawn-speedup.test.js`.
1078
@@ -1025,3 +1025,54 @@ Tests: `test/mini-predict.test.js`, plus de mini-meting in
1025
1025
1026Tests: `test/flame-fx.test.js`; browser: `test/t1183-flame-playwright.py URL TAG`.
1026Tests: `test/flame-fx.test.js`; browser: `test/t1183-flame-playwright.py URL TAG`.
1027
1027
1028## t1184 / t1185 / t1186 — niet laten vallen op een vertrekkende raket
1029
1030Tims woorden: "blokjes niet laten vallen op rijen waarvan nu blokken omhoog
1031vliegen waarvan de hoogste voorbij 75% vanaf de grond is die zeker het
1032scherm gaan verlaten".
1033
1034- **"Rijen" = kolommen.** Blokken vallen per kolom (10 breed, 13 hoog) en
1035 een raket (vliegend cluster) stijgt in de kolommen waarin hij zit.
1036- **Vertrekkende stapel** (`GameCore.departingColumns`): een vliegend
1037 cluster dat nog stijgt (`phase 'up'`), waarvan het hoogste blok op of
1038 boven `0,75 × 13 = 9,75` staat (`GameCore.DEPART_SHARE`), waarvan de
1039 top (y + vy²/(2·decel)) de bovenrand haalt ("zeker het scherm uit"), en
1040 waar in zijn kolommen geen vast blok boven hangt. Alle kolommen waarin
1041 dat cluster blokken heeft tellen als vertrekkend.
1042- **Nieuwe blokken** (`trySpawn`) slaan die kolommen over. Zijn alle open
1043 kolommen vertrekkend, dan valt er die tik niets (de volgende spawn-tik
1044 probeert opnieuw).
1045- **Ontvangen blokken** (garbage van een tegenstander of bot,
1046 `ingestGarbage` / `pickGarbageColumn`): de gewenste kolom (`land_col` van
1047 de server) wint alleen als die niet vertrekkend is; anders een
1048 willekeurige andere open kolom. Zijn alle open kolommen vertrekkend, dan
1049 valt het blok toch (in de gewenste kolom), zodat er nooit garbage
1050 verdwijnt.
1051- Ze vallen dus niet door de raket heen en ook niet erop: ze kiezen een
1052 andere kolom. Blokken die al vielen voordat de stapel de 75% passeerde
1053 houden de bestaande regels (ze kunnen als lading meeliften).
1054- **Online consistent:** elk veld wordt door de eigen client gesimuleerd
1055 met dezelfde gedeelde `GameCore` (solo, offline met bots en online). De
1056 server kiest alleen een voorkeurskolom (`land_col`, willekeurig 0–9) en
1057 hoeft niets te weten van raketten; de client wijkt uit zoals bij volle
1058 of geblokkeerde kolommen (t1126). De vluchtanimatie mikt nog op
1059 `land_col`; het blok verschijnt dan in de gekozen kolom.
1060
1061Tests: `test/departing.test.js`; browser:
1062`test/t1184-departing-playwright.py URL TAG` (desktop + mobiel).
1063
1064## t1187 / t1188 — spawn-tempo loopt op
1065
1066- Na elk echt gespawnd blok (`trySpawn` die een blok maakt):
1067 `spawnInterval *= GameCore.SPAWN_SPEEDUP` (0,997 = 0,3% korter; eerst
1068 3% gevraagd, door Tim aangepast naar 0,3%).
1069- Start `PlanetMod.SPAWN_INTERVAL` = 1 s; minimum
1070 `GameCore.SPAWN_INTERVAL_MIN` = 0,1 s (aanname, Tim kan dit aanpassen).
1071- Het minimum wordt bereikt na ca. 767 blokken, ongeveer 300 s (5 min).
1072- Geen spawn (alle kolommen dicht of vertrekkend) = geen versnelling.
1073- Elk spel en elke ronde maakt een nieuwe `GameCore`, dus het tempo begint
1074 steeds weer op 1 s. Spelers en bots (offline) en online velden gebruiken
1075 dezelfde code.
1076
1077Tests: `test/spawn-speedup.test.js`.
1078
src/gameCore.js +109 −0
@@ -638,17 +638,96 @@ GameCore.prototype.step = function (seconds, dt)
638 638 }
639 639 };
640 640
641 /** Share of the field height a rising stack must pass (t1184). */
642 GameCore.DEPART_SHARE = 0.75;
643
644 /**
645 * Columns with a rising rocket stack that will certainly leave the
646 * screen (t1184). A flying cluster counts when it is still going up,
647 * its highest block is past DEPART_SHARE of the field height, its apex
648 * (y + vy^2 / (2 * decel)) is at or above the top, and nothing grounded
649 * hangs above it in its columns. Every column that stack occupies is
650 * departing: newly spawned blocks and received garbage pick another
651 * column (t1185/t1186). Returns { col: true }.
652 */
653 GameCore.prototype.departingColumns = function ()
654 {
655 var out = Object.create(null);
656 var H = this.height;
657 var ids = Object.keys(this.clusters);
658 for (var n = 0; n < ids.length; n++)
659 {
660 var cluster = this.clusters[ids[n]];
661 if (!cluster || cluster.phase !== 'up' || !(cluster.vy > 1e-9))
662 { continue; }
663 var members = this.clusterMembers(cluster.id);
664 if (!members.length)
665 { continue; }
666 var top = -Infinity;
667 var lowest = Object.create(null);
668 for (var i = 0; i < members.length; i++)
669 {
670 var m = members[i];
671 if (m.state !== STATE_FLYING)
672 { continue; }
673 if (m.y > top)
674 { top = m.y; }
675 if (lowest[m.col] == null || m.y < lowest[m.col])
676 { lowest[m.col] = m.y; }
677 }
678 if (top < this.DEPART_LINE())
679 { continue; }
680 var decel = cluster.decel || 0;
681 var rise = decel > 1e-12 ? (cluster.vy * cluster.vy) / (2 * decel) : Infinity;
682 if (top + rise < H - 1e-9)
683 { continue; }
684 var blocked = false;
685 for (var col in lowest)
686 {
687 var c = col | 0;
688 for (var j = 0; j < this.blocks.length; j++)
689 {
690 var b = this.blocks[j];
691 if (b.col === c && b.clusterId !== cluster.id && this.isGrounded(b) && b.y > lowest[col])
692 {
693 blocked = true;
694 break;
695 }
696 }
697 if (blocked)
698 { break; }
699 }
700 if (blocked)
701 { continue; }
702 // t1185/t1186: every column the departing stack occupies is off
703 // limits; new and received blocks pick another column.
704 for (var col2 in lowest)
705 { out[col2 | 0] = true; }
706 }
707 return out;
708 };
709
710 /** Height (tiles from the ground) a rising stack must pass: 75% of the field. */
711 GameCore.prototype.DEPART_LINE = function ()
712 {
713 return this.height * GameCore.DEPART_SHARE;
714 };
715
641 716 GameCore.prototype.trySpawn = function ()
642 717 {
643 718 if (this.state !== 'playing')
644 719 { return null; }
645 720 var eligible = [];
721 var departing = this.departingColumns();
646 722 for (var col = 0; col < this.width; col++)
647 723 {
648 724 if (this.isColumnLocked(col))
649 725 { continue; }
650 726 if (this.groundedCount(col) >= this.height)
651 727 { continue; }
728 // t1184: never drop a new block onto a stack that is leaving.
729 if (departing[col])
730 { continue; }
652 731 var alreadyFalling = false;
653 732 var list = this.blocksInColumn(col);
654 733 for (var i = 0; i < list.length; i++)
@@ -668,9 +747,28 @@ GameCore.prototype.trySpawn = function ()
668 747 var color = this.randomColor();
669 748 var block = this.createBlock(col, this.height, color, STATE_FALLING);
670 749 block.vy = -this.planet.fallSpeed;
750 this.speedUpSpawning();
671 751 return block;
672 752 };
673 753
754 /** Each spawned block shrinks the spawn interval by 0.3% (t1187 / t1188). */
755 GameCore.SPAWN_SPEEDUP = 0.997;
756 /** The spawn interval never goes below this (seconds, t1187). */
757 GameCore.SPAWN_INTERVAL_MIN = 0.1;
758
759 /**
760 * After every real spawn: spawnInterval *= SPAWN_SPEEDUP, floored at
761 * SPAWN_INTERVAL_MIN. Starts at PlanetMod.SPAWN_INTERVAL (1 s) for every
762 * new core, i.e. every game and every round, for players and bots alike.
763 * Reaches the floor after ~767 spawns (~5 min of continuous play).
764 */
765 GameCore.prototype.speedUpSpawning = function ()
766 {
767 var next = this.spawnInterval * GameCore.SPAWN_SPEEDUP;
768 this.spawnInterval = Math.max(GameCore.SPAWN_INTERVAL_MIN, next);
769 return this.spawnInterval;
770 };
771
674 772 GameCore.prototype.integrateFalling = function (dt)
675 773 {
676 774 var falling = [];
@@ -2088,6 +2186,17 @@ GameCore.prototype.pickGarbageColumn = function (preferred)
2088 2186 var eligible = this.eligibleGarbageColumns();
2089 2187 if (!eligible.length)
2090 2188 { return null; }
2189 // t1184: skip columns whose rocket stack is certainly leaving; only
2190 // if every open column is departing, fall back so no garbage is lost.
2191 var departing = this.departingColumns();
2192 var staying = [];
2193 for (var k = 0; k < eligible.length; k++)
2194 {
2195 if (!departing[eligible[k]])
2196 { staying.push(eligible[k]); }
2197 }
2198 if (staying.length)
2199 { eligible = staying; }
2091 2200 if (preferred != null && isFinite(preferred))
2092 2201 {
2093 2202 var want = preferred | 0;
@@ -638,17 +638,96 @@ GameCore.prototype.step = function (seconds, dt)
638 }
638 }
639};
639};
640
640
641/** Share of the field height a rising stack must pass (t1184). */
642GameCore.DEPART_SHARE = 0.75;
643
644/**
645 * Columns with a rising rocket stack that will certainly leave the
646 * screen (t1184). A flying cluster counts when it is still going up,
647 * its highest block is past DEPART_SHARE of the field height, its apex
648 * (y + vy^2 / (2 * decel)) is at or above the top, and nothing grounded
649 * hangs above it in its columns. Every column that stack occupies is
650 * departing: newly spawned blocks and received garbage pick another
651 * column (t1185/t1186). Returns { col: true }.
652 */
653GameCore.prototype.departingColumns = function ()
654{
655 var out = Object.create(null);
656 var H = this.height;
657 var ids = Object.keys(this.clusters);
658 for (var n = 0; n < ids.length; n++)
659 {
660 var cluster = this.clusters[ids[n]];
661 if (!cluster || cluster.phase !== 'up' || !(cluster.vy > 1e-9))
662 { continue; }
663 var members = this.clusterMembers(cluster.id);
664 if (!members.length)
665 { continue; }
666 var top = -Infinity;
667 var lowest = Object.create(null);
668 for (var i = 0; i < members.length; i++)
669 {
670 var m = members[i];
671 if (m.state !== STATE_FLYING)
672 { continue; }
673 if (m.y > top)
674 { top = m.y; }
675 if (lowest[m.col] == null || m.y < lowest[m.col])
676 { lowest[m.col] = m.y; }
677 }
678 if (top < this.DEPART_LINE())
679 { continue; }
680 var decel = cluster.decel || 0;
681 var rise = decel > 1e-12 ? (cluster.vy * cluster.vy) / (2 * decel) : Infinity;
682 if (top + rise < H - 1e-9)
683 { continue; }
684 var blocked = false;
685 for (var col in lowest)
686 {
687 var c = col | 0;
688 for (var j = 0; j < this.blocks.length; j++)
689 {
690 var b = this.blocks[j];
691 if (b.col === c && b.clusterId !== cluster.id && this.isGrounded(b) && b.y > lowest[col])
692 {
693 blocked = true;
694 break;
695 }
696 }
697 if (blocked)
698 { break; }
699 }
700 if (blocked)
701 { continue; }
702 // t1185/t1186: every column the departing stack occupies is off
703 // limits; new and received blocks pick another column.
704 for (var col2 in lowest)
705 { out[col2 | 0] = true; }
706 }
707 return out;
708};
709
710/** Height (tiles from the ground) a rising stack must pass: 75% of the field. */
711GameCore.prototype.DEPART_LINE = function ()
712{
713 return this.height * GameCore.DEPART_SHARE;
714};
715
641GameCore.prototype.trySpawn = function ()
716GameCore.prototype.trySpawn = function ()
642{
717{
643 if (this.state !== 'playing')
718 if (this.state !== 'playing')
644 { return null; }
719 { return null; }
645 var eligible = [];
720 var eligible = [];
721 var departing = this.departingColumns();
646 for (var col = 0; col < this.width; col++)
722 for (var col = 0; col < this.width; col++)
647 {
723 {
648 if (this.isColumnLocked(col))
724 if (this.isColumnLocked(col))
649 { continue; }
725 { continue; }
650 if (this.groundedCount(col) >= this.height)
726 if (this.groundedCount(col) >= this.height)
651 { continue; }
727 { continue; }
728 // t1184: never drop a new block onto a stack that is leaving.
729 if (departing[col])
730 { continue; }
652 var alreadyFalling = false;
731 var alreadyFalling = false;
653 var list = this.blocksInColumn(col);
732 var list = this.blocksInColumn(col);
654 for (var i = 0; i < list.length; i++)
733 for (var i = 0; i < list.length; i++)
@@ -668,9 +747,28 @@ GameCore.prototype.trySpawn = function ()
668 var color = this.randomColor();
747 var color = this.randomColor();
669 var block = this.createBlock(col, this.height, color, STATE_FALLING);
748 var block = this.createBlock(col, this.height, color, STATE_FALLING);
670 block.vy = -this.planet.fallSpeed;
749 block.vy = -this.planet.fallSpeed;
750 this.speedUpSpawning();
671 return block;
751 return block;
672};
752};
673
753
754/** Each spawned block shrinks the spawn interval by 0.3% (t1187 / t1188). */
755GameCore.SPAWN_SPEEDUP = 0.997;
756/** The spawn interval never goes below this (seconds, t1187). */
757GameCore.SPAWN_INTERVAL_MIN = 0.1;
758
759/**
760 * After every real spawn: spawnInterval *= SPAWN_SPEEDUP, floored at
761 * SPAWN_INTERVAL_MIN. Starts at PlanetMod.SPAWN_INTERVAL (1 s) for every
762 * new core, i.e. every game and every round, for players and bots alike.
763 * Reaches the floor after ~767 spawns (~5 min of continuous play).
764 */
765GameCore.prototype.speedUpSpawning = function ()
766{
767 var next = this.spawnInterval * GameCore.SPAWN_SPEEDUP;
768 this.spawnInterval = Math.max(GameCore.SPAWN_INTERVAL_MIN, next);
769 return this.spawnInterval;
770};
771
674GameCore.prototype.integrateFalling = function (dt)
772GameCore.prototype.integrateFalling = function (dt)
675{
773{
676 var falling = [];
774 var falling = [];
@@ -2088,6 +2186,17 @@ GameCore.prototype.pickGarbageColumn = function (preferred)
2088 var eligible = this.eligibleGarbageColumns();
2186 var eligible = this.eligibleGarbageColumns();
2089 if (!eligible.length)
2187 if (!eligible.length)
2090 { return null; }
2188 { return null; }
2189 // t1184: skip columns whose rocket stack is certainly leaving; only
2190 // if every open column is departing, fall back so no garbage is lost.
2191 var departing = this.departingColumns();
2192 var staying = [];
2193 for (var k = 0; k < eligible.length; k++)
2194 {
2195 if (!departing[eligible[k]])
2196 { staying.push(eligible[k]); }
2197 }
2198 if (staying.length)
2199 { eligible = staying; }
2091 if (preferred != null && isFinite(preferred))
2200 if (preferred != null && isFinite(preferred))
2092 {
2201 {
2093 var want = preferred | 0;
2202 var want = preferred | 0;
test/departing.test.js added +132 −0
@@ -0,0 +1,132 @@
1 'use strict';
2
3 // t1184/t1185/t1186: no new or received blocks in columns of a rocket
4 // stack that is certainly leaving (highest block past 75% of the field).
5
6 const { describe, it } = require('node:test');
7 const assert = require('node:assert/strict');
8 const { makeGame, placeRow } = require('./helpers.js');
9
10 function launchedRocket (g, cols, height)
11 {
12 const row = placeRow(g, 0, cols, 1);
13 const cluster = g.launchCluster(row, height);
14 return { cluster, row };
15 }
16
17 function riseUntil (g, row, cluster, minTop)
18 {
19 for (let i = 0; i < 2000; i++)
20 {
21 const top = Math.max(...row.filter((b) => g.blocks.includes(b)).map((b) => b.y));
22 if (top >= minTop || cluster.phase !== 'up')
23 { return top; }
24 g.step(1 / 120, 1 / 120);
25 }
26 throw new Error('never rose');
27 }
28
29 describe('Departing rocket columns (t1184)', () =>
30 {
31 it('threshold is 75% of the field height', () =>
32 {
33 const g = makeGame({ noSpawn: true });
34 assert.equal(g.DEPART_LINE(), 13 * 0.75);
35 });
36
37 it('a rising stack below 75% does not block its columns', () =>
38 {
39 const g = makeGame({ noSpawn: true });
40 const { cluster, row } = launchedRocket(g, [2, 3, 4], 30);
41 riseUntil(g, row, cluster, 5);
42 assert.deepEqual(Object.keys(g.departingColumns()), []);
43 });
44
45 it('past 75% and certain to leave: all its columns are skipped by new blocks', () =>
46 {
47 const g = makeGame({ noSpawn: true, seed: 11 });
48 const { cluster, row } = launchedRocket(g, [2, 3, 4], 30);
49 const top = riseUntil(g, row, cluster, 10);
50 assert.ok(top >= 9.75 && top < 13, 'top=' + top);
51 assert.deepEqual(Object.keys(g.departingColumns()).map(Number).sort(), [2, 3, 4]);
52 const seen = new Set();
53 for (let i = 0; i < 300; i++)
54 {
55 const b = g.trySpawn();
56 assert.ok(b, 'spawned');
57 seen.add(b.col);
58 g.removeBlock(b);
59 }
60 for (const c of [2, 3, 4])
61 { assert.ok(!seen.has(c), 'spawned in departing column ' + c); }
62 assert.ok(seen.size >= 6, 'other columns still used: ' + [...seen]);
63 });
64
65 it('received garbage aimed at a departing column drops in another column', () =>
66 {
67 const g = makeGame({ noSpawn: true, seed: 5 });
68 const { cluster, row } = launchedRocket(g, [5, 6], 30);
69 riseUntil(g, row, cluster, 10);
70 for (let i = 0; i < 50; i++)
71 {
72 const want = 5 + (i % 2);
73 const b = g.ingestGarbage(want);
74 assert.ok(b);
75 assert.ok(b.col !== 5 && b.col !== 6, 'garbage col ' + b.col);
76 g.removeBlock(b);
77 }
78 // Open preferred columns are still honoured.
79 const ok = g.ingestGarbage(1);
80 assert.equal(ok.col, 1);
81 // pickGarbageColumn (used by bots / previews) also avoids them.
82 for (let i = 0; i < 50; i++)
83 {
84 const c = g.pickGarbageColumn();
85 assert.ok(c !== 5 && c !== 6);
86 }
87 });
88
89 it('a stack whose apex stays below the top is not departing', () =>
90 {
91 const g = makeGame({ noSpawn: true });
92 const { cluster, row } = launchedRocket(g, [3], 10.5);
93 const top = riseUntil(g, row, cluster, 9.8);
94 assert.ok(top >= 9.75, 'top=' + top);
95 assert.deepEqual(Object.keys(g.departingColumns()), []);
96 });
97
98 it('a stack that is coming back down is not departing', () =>
99 {
100 const g = makeGame({ noSpawn: true });
101 const { cluster, row } = launchedRocket(g, [3], 30);
102 riseUntil(g, row, cluster, 10);
103 cluster.phase = 'down';
104 cluster.vy = -1;
105 assert.deepEqual(Object.keys(g.departingColumns()), []);
106 });
107
108 it('if every open column is departing, garbage still arrives (never lost)', () =>
109 {
110 const g = makeGame({ noSpawn: true });
111 const all = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
112 const { cluster, row } = launchedRocket(g, all, 30);
113 riseUntil(g, row, cluster, 10);
114 assert.equal(Object.keys(g.departingColumns()).length, 10);
115 assert.equal(g.trySpawn(), null, 'no new block while every column is departing');
116 const b = g.ingestGarbage(4);
117 assert.ok(b, 'garbage kept');
118 assert.equal(b.col, 4);
119 });
120
121 it('the stack really leaves and the columns open up again', () =>
122 {
123 const g = makeGame({ noSpawn: true });
124 const { cluster, row } = launchedRocket(g, [2, 3], 30);
125 riseUntil(g, row, cluster, 10);
126 assert.ok(g.departingColumns()[2]);
127 for (let i = 0; i < 600 && row.some((b) => g.blocks.includes(b)); i++)
128 { g.step(1 / 120, 1 / 120); }
129 assert.ok(!row.some((b) => g.blocks.includes(b)), 'rocket left the field');
130 assert.deepEqual(Object.keys(g.departingColumns()), []);
131 });
132 });
@@ -0,0 +1,132 @@
1'use strict';
2
3// t1184/t1185/t1186: no new or received blocks in columns of a rocket
4// stack that is certainly leaving (highest block past 75% of the field).
5
6const { describe, it } = require('node:test');
7const assert = require('node:assert/strict');
8const { makeGame, placeRow } = require('./helpers.js');
9
10function launchedRocket (g, cols, height)
11{
12 const row = placeRow(g, 0, cols, 1);
13 const cluster = g.launchCluster(row, height);
14 return { cluster, row };
15}
16
17function riseUntil (g, row, cluster, minTop)
18{
19 for (let i = 0; i < 2000; i++)
20 {
21 const top = Math.max(...row.filter((b) => g.blocks.includes(b)).map((b) => b.y));
22 if (top >= minTop || cluster.phase !== 'up')
23 { return top; }
24 g.step(1 / 120, 1 / 120);
25 }
26 throw new Error('never rose');
27}
28
29describe('Departing rocket columns (t1184)', () =>
30{
31 it('threshold is 75% of the field height', () =>
32 {
33 const g = makeGame({ noSpawn: true });
34 assert.equal(g.DEPART_LINE(), 13 * 0.75);
35 });
36
37 it('a rising stack below 75% does not block its columns', () =>
38 {
39 const g = makeGame({ noSpawn: true });
40 const { cluster, row } = launchedRocket(g, [2, 3, 4], 30);
41 riseUntil(g, row, cluster, 5);
42 assert.deepEqual(Object.keys(g.departingColumns()), []);
43 });
44
45 it('past 75% and certain to leave: all its columns are skipped by new blocks', () =>
46 {
47 const g = makeGame({ noSpawn: true, seed: 11 });
48 const { cluster, row } = launchedRocket(g, [2, 3, 4], 30);
49 const top = riseUntil(g, row, cluster, 10);
50 assert.ok(top >= 9.75 && top < 13, 'top=' + top);
51 assert.deepEqual(Object.keys(g.departingColumns()).map(Number).sort(), [2, 3, 4]);
52 const seen = new Set();
53 for (let i = 0; i < 300; i++)
54 {
55 const b = g.trySpawn();
56 assert.ok(b, 'spawned');
57 seen.add(b.col);
58 g.removeBlock(b);
59 }
60 for (const c of [2, 3, 4])
61 { assert.ok(!seen.has(c), 'spawned in departing column ' + c); }
62 assert.ok(seen.size >= 6, 'other columns still used: ' + [...seen]);
63 });
64
65 it('received garbage aimed at a departing column drops in another column', () =>
66 {
67 const g = makeGame({ noSpawn: true, seed: 5 });
68 const { cluster, row } = launchedRocket(g, [5, 6], 30);
69 riseUntil(g, row, cluster, 10);
70 for (let i = 0; i < 50; i++)
71 {
72 const want = 5 + (i % 2);
73 const b = g.ingestGarbage(want);
74 assert.ok(b);
75 assert.ok(b.col !== 5 && b.col !== 6, 'garbage col ' + b.col);
76 g.removeBlock(b);
77 }
78 // Open preferred columns are still honoured.
79 const ok = g.ingestGarbage(1);
80 assert.equal(ok.col, 1);
81 // pickGarbageColumn (used by bots / previews) also avoids them.
82 for (let i = 0; i < 50; i++)
83 {
84 const c = g.pickGarbageColumn();
85 assert.ok(c !== 5 && c !== 6);
86 }
87 });
88
89 it('a stack whose apex stays below the top is not departing', () =>
90 {
91 const g = makeGame({ noSpawn: true });
92 const { cluster, row } = launchedRocket(g, [3], 10.5);
93 const top = riseUntil(g, row, cluster, 9.8);
94 assert.ok(top >= 9.75, 'top=' + top);
95 assert.deepEqual(Object.keys(g.departingColumns()), []);
96 });
97
98 it('a stack that is coming back down is not departing', () =>
99 {
100 const g = makeGame({ noSpawn: true });
101 const { cluster, row } = launchedRocket(g, [3], 30);
102 riseUntil(g, row, cluster, 10);
103 cluster.phase = 'down';
104 cluster.vy = -1;
105 assert.deepEqual(Object.keys(g.departingColumns()), []);
106 });
107
108 it('if every open column is departing, garbage still arrives (never lost)', () =>
109 {
110 const g = makeGame({ noSpawn: true });
111 const all = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
112 const { cluster, row } = launchedRocket(g, all, 30);
113 riseUntil(g, row, cluster, 10);
114 assert.equal(Object.keys(g.departingColumns()).length, 10);
115 assert.equal(g.trySpawn(), null, 'no new block while every column is departing');
116 const b = g.ingestGarbage(4);
117 assert.ok(b, 'garbage kept');
118 assert.equal(b.col, 4);
119 });
120
121 it('the stack really leaves and the columns open up again', () =>
122 {
123 const g = makeGame({ noSpawn: true });
124 const { cluster, row } = launchedRocket(g, [2, 3], 30);
125 riseUntil(g, row, cluster, 10);
126 assert.ok(g.departingColumns()[2]);
127 for (let i = 0; i < 600 && row.some((b) => g.blocks.includes(b)); i++)
128 { g.step(1 / 120, 1 / 120); }
129 assert.ok(!row.some((b) => g.blocks.includes(b)), 'rocket left the field');
130 assert.deepEqual(Object.keys(g.departingColumns()), []);
131 });
132});
test/spawn-speedup.test.js added +76 −0
@@ -0,0 +1,76 @@
1 'use strict';
2
3 // t1187 / t1188: spawn interval shrinks 0.3% per spawned block, floor 0.1 s.
4
5 const { describe, it } = require('node:test');
6 const assert = require('node:assert/strict');
7 const { makeGame, almost, Planet } = require('./helpers.js');
8 const { GameCore } = require('../src/gameCore.js');
9
10 describe('Spawn speed-up (t1187/t1188)', () =>
11 {
12 it('constants: start 1 s, factor 0.997, floor 0.1 s', () =>
13 {
14 assert.equal(Planet.SPAWN_INTERVAL, 1);
15 assert.equal(GameCore.SPAWN_SPEEDUP, 0.997);
16 assert.equal(GameCore.SPAWN_INTERVAL_MIN, 0.1);
17 const g = makeGame({ seed: 1 });
18 assert.equal(g.spawnInterval, 1);
19 });
20
21 it('every spawned block multiplies the interval by 0.997', () =>
22 {
23 const g = makeGame({ seed: 2 });
24 const b1 = g.trySpawn();
25 assert.ok(b1);
26 assert.ok(almost(g.spawnInterval, 0.997, 1e-12));
27 g.trySpawn();
28 assert.ok(almost(g.spawnInterval, 0.997 * 0.997, 1e-12));
29 });
30
31 it('no spawn (no open column) → no speed-up', () =>
32 {
33 const g = makeGame({ seed: 3 });
34 for (let c = 0; c < g.width; c++)
35 { g.createBlock(c, 12, 0, 'falling'); }
36 assert.equal(g.trySpawn(), null);
37 assert.equal(g.spawnInterval, 1);
38 });
39
40 it('floors at 0.1 s after ~767 spawns', () =>
41 {
42 const g = makeGame({ seed: 4 });
43 let n = 0;
44 while (g.spawnInterval > GameCore.SPAWN_INTERVAL_MIN + 1e-12 && n < 5000)
45 {
46 g.speedUpSpawning();
47 n++;
48 }
49 assert.equal(g.spawnInterval, 0.1);
50 assert.ok(n >= 766 && n <= 768, 'spawns to floor: ' + n);
51 g.speedUpSpawning();
52 assert.equal(g.spawnInterval, 0.1, 'never below the floor');
53 // Total time to the floor ≈ sum of intervals ≈ 300 s.
54 let total = 0, iv = 1;
55 for (let i = 0; i < n; i++) { total += iv; iv = Math.max(0.1, iv * 0.997); }
56 assert.ok(total > 290 && total < 310, 'seconds to floor ' + total.toFixed(1));
57 });
58
59 it('the game tick spawns faster over time (driven by the same logic)', () =>
60 {
61 const g = makeGame({ seed: 5 });
62 g.trySpawn = (function (orig) { let count = 0; const f = function () { const b = orig.call(this); if (b) { count++; this.removeBlock(b); } return b; }; f.count = () => count; return f; })(g.trySpawn);
63 for (let i = 0; i < 60 * 120; i++) g.tick(1 / 60);
64 const spawned = g.trySpawn.count();
65 assert.ok(spawned >= 140 && spawned <= 155, '120 s gives ~149 spawns instead of 120: ' + spawned);
66 assert.ok(almost(g.spawnInterval, Math.max(0.1, Math.pow(0.997, spawned)), 1e-9));
67 });
68
69 it('a new game (new core) starts again at 1 s', () =>
70 {
71 const g = makeGame({ seed: 6 });
72 for (let i = 0; i < 100; i++) g.speedUpSpawning();
73 assert.ok(g.spawnInterval < 0.75);
74 assert.equal(makeGame({ seed: 6 }).spawnInterval, 1);
75 });
76 });
@@ -0,0 +1,76 @@
1'use strict';
2
3// t1187 / t1188: spawn interval shrinks 0.3% per spawned block, floor 0.1 s.
4
5const { describe, it } = require('node:test');
6const assert = require('node:assert/strict');
7const { makeGame, almost, Planet } = require('./helpers.js');
8const { GameCore } = require('../src/gameCore.js');
9
10describe('Spawn speed-up (t1187/t1188)', () =>
11{
12 it('constants: start 1 s, factor 0.997, floor 0.1 s', () =>
13 {
14 assert.equal(Planet.SPAWN_INTERVAL, 1);
15 assert.equal(GameCore.SPAWN_SPEEDUP, 0.997);
16 assert.equal(GameCore.SPAWN_INTERVAL_MIN, 0.1);
17 const g = makeGame({ seed: 1 });
18 assert.equal(g.spawnInterval, 1);
19 });
20
21 it('every spawned block multiplies the interval by 0.997', () =>
22 {
23 const g = makeGame({ seed: 2 });
24 const b1 = g.trySpawn();
25 assert.ok(b1);
26 assert.ok(almost(g.spawnInterval, 0.997, 1e-12));
27 g.trySpawn();
28 assert.ok(almost(g.spawnInterval, 0.997 * 0.997, 1e-12));
29 });
30
31 it('no spawn (no open column) → no speed-up', () =>
32 {
33 const g = makeGame({ seed: 3 });
34 for (let c = 0; c < g.width; c++)
35 { g.createBlock(c, 12, 0, 'falling'); }
36 assert.equal(g.trySpawn(), null);
37 assert.equal(g.spawnInterval, 1);
38 });
39
40 it('floors at 0.1 s after ~767 spawns', () =>
41 {
42 const g = makeGame({ seed: 4 });
43 let n = 0;
44 while (g.spawnInterval > GameCore.SPAWN_INTERVAL_MIN + 1e-12 && n < 5000)
45 {
46 g.speedUpSpawning();
47 n++;
48 }
49 assert.equal(g.spawnInterval, 0.1);
50 assert.ok(n >= 766 && n <= 768, 'spawns to floor: ' + n);
51 g.speedUpSpawning();
52 assert.equal(g.spawnInterval, 0.1, 'never below the floor');
53 // Total time to the floor ≈ sum of intervals ≈ 300 s.
54 let total = 0, iv = 1;
55 for (let i = 0; i < n; i++) { total += iv; iv = Math.max(0.1, iv * 0.997); }
56 assert.ok(total > 290 && total < 310, 'seconds to floor ' + total.toFixed(1));
57 });
58
59 it('the game tick spawns faster over time (driven by the same logic)', () =>
60 {
61 const g = makeGame({ seed: 5 });
62 g.trySpawn = (function (orig) { let count = 0; const f = function () { const b = orig.call(this); if (b) { count++; this.removeBlock(b); } return b; }; f.count = () => count; return f; })(g.trySpawn);
63 for (let i = 0; i < 60 * 120; i++) g.tick(1 / 60);
64 const spawned = g.trySpawn.count();
65 assert.ok(spawned >= 140 && spawned <= 155, '120 s gives ~149 spawns instead of 120: ' + spawned);
66 assert.ok(almost(g.spawnInterval, Math.max(0.1, Math.pow(0.997, spawned)), 1e-9));
67 });
68
69 it('a new game (new core) starts again at 1 s', () =>
70 {
71 const g = makeGame({ seed: 6 });
72 for (let i = 0; i < 100; i++) g.speedUpSpawning();
73 assert.ok(g.spawnInterval < 0.75);
74 assert.equal(makeGame({ seed: 6 }).spawnInterval, 1);
75 });
76});
test/t1184-departing-playwright.py added +84 −0
@@ -0,0 +1,84 @@
1 #!/usr/bin/env python3
2 """t1184: new and received blocks avoid a departing rocket stack.
3
4 Usage: python3 test/t1184-departing-playwright.py URL TAG
5 Logged-out solo game: launch a 3-wide rocket in columns 3-5, let it rise
6 past 75% of the field, then (game clock paused, rendering live) spawn
7 blocks and ingest garbage aimed at the rocket columns. Screenshots the
8 moment and checks every new block is outside the rocket columns.
9 """
10 import json, sys
11 from pathlib import Path
12 from playwright.sync_api import sync_playwright
13
14 URL = sys.argv[1] if len(sys.argv) > 1 else "https://projects.timfalken.com/meteors/"
15 TAG = sys.argv[2] if len(sys.argv) > 2 else "live"
16 SHOTS = Path("/workspace/meteors-shots")
17 fails = []
18
19 def check(c, m):
20 print(("OK " if c else "FAIL ") + m)
21 if not c: fails.append(m)
22
23 with sync_playwright() as pw:
24 br = pw.chromium.launch(args=["--use-gl=angle", "--use-angle=swiftshader"])
25 for name, vp, mobile in (("desktop", {"width": 1280, "height": 800}, False), ("mobile", {"width": 390, "height": 844}, True)):
26 ctx = br.new_context(viewport=vp, is_mobile=mobile, has_touch=mobile, device_scale_factor=3 if mobile else 1)
27 page = ctx.new_page()
28 errors = []
29 page.on("pageerror", lambda e: errors.append(str(e)))
30 page.goto(URL + ("" if URL.endswith("/") else "/") + "index.html?t1184=" + TAG, wait_until="networkidle")
31 check(page.evaluate("() => typeof GameCore.prototype.departingColumns === 'function'"), f"{name}: departingColumns in served game.js")
32 page.locator("#btn-play").click()
33 page.wait_for_selector("#planet-select:not([hidden])", timeout=8000)
34 page.wait_for_timeout(200)
35 page.locator("#btn-planet-go").click()
36 page.wait_for_function("() => window.app && app.mode === 'playing' && app.core", timeout=10000)
37 page.wait_for_timeout(300)
38 # t1187/t1188: spawning speeds up 0.3% per block, from 1 s.
39 page.wait_for_timeout(3200)
40 sp = page.evaluate("() => ({ f: GameCore.SPAWN_SPEEDUP, min: GameCore.SPAWN_INTERVAL_MIN, iv: app.core.spawnInterval })")
41 n = round(__import__("math").log(sp["iv"]) / __import__("math").log(0.997)) if sp["iv"] < 1 else 0
42 check(sp["f"] == 0.997 and sp["min"] == 0.1 and 0.97 < sp["iv"] < 1, f"{name}: spawn interval {sp['iv']:.4f} s after ~3.5 s of play ({n} spawns × 0.997)")
43 page.evaluate("""() => {
44 const g = app.core;
45 g.spawnInterval = 1e9;
46 for (const b of g.blocks.slice()) g.removeBlock(b);
47 [[0, 2], [1, 3]].forEach(([c, k]) => g.place(c, 0, k));
48 const row = [3, 4, 5].map(c => g.place(c, 0, 1));
49 window.__rocket = { row, cluster: g.launchCluster(row, 30) };
50 }""")
51 page.wait_for_function("""() => { const r = window.__rocket; const live = r.row.filter(b => app.core.blocks.includes(b));
52 return live.length && Math.max(...live.map(b => b.y)) >= 10.0; }""", timeout=10000, polling="raf")
53 res = page.evaluate("""() => {
54 const g = app.core;
55 g.__tick = g.tick; g.tick = function () {};
56 const top = Math.max(...window.__rocket.row.map(b => b.y));
57 const dep = Object.keys(g.departingColumns()).map(Number).sort();
58 const spawned = [];
59 for (let i = 0; i < 6; i++) { const b = g.trySpawn(); if (b) { b.y = 12 - (i % 3) * 0.2; spawned.push(b.col); } }
60 const garbage = [];
61 for (const c of [3, 4, 5, 4]) { const b = g.ingestGarbage(c); if (b) { b.y = 11; garbage.push(b.col); } }
62 return { top, dep, spawned, garbage, line: g.DEPART_LINE() };
63 }""")
64 page.wait_for_timeout(120)
65 shot = SHOTS / f"t1184-{TAG}-{name}-departing.png"
66 page.screenshot(path=str(shot))
67 # Resume: rocket leaves, spawning into those columns is allowed again.
68 after = page.evaluate("""async () => {
69 const g = app.core; g.tick = g.__tick;
70 await new Promise(r => setTimeout(r, 1500));
71 const left = !window.__rocket.row.some(b => g.blocks.includes(b));
72 return { left, dep: Object.keys(g.departingColumns()).length };
73 }""")
74 page.screenshot(path=str(SHOTS / f"t1184-{TAG}-{name}-after-leaving.png"))
75 print(name, json.dumps(res), json.dumps(after))
76 check(res["top"] >= res["line"] and res["dep"] == [3, 4, 5], f"{name}: rocket top {res['top']:.2f} past 75% ({res['line']}), departing cols {res['dep']}")
77 check(len(res["spawned"]) == 6 and not set(res["spawned"]) & {3, 4, 5}, f"{name}: spawned in {res['spawned']} (not 3-5)")
78 check(len(res["garbage"]) == 4 and not set(res["garbage"]) & {3, 4, 5}, f"{name}: garbage aimed at 3/4/5 landed in {res['garbage']}")
79 check(after["left"] and after["dep"] == 0, f"{name}: rocket left the screen, columns open again")
80 check(not errors, f"{name}: no page errors {errors[:2]}")
81 ctx.close()
82 br.close()
83 print("ALL OK" if not fails else f"{len(fails)} FAIL")
84 sys.exit(1 if fails else 0)
@@ -0,0 +1,84 @@
1#!/usr/bin/env python3
2"""t1184: new and received blocks avoid a departing rocket stack.
3
4Usage: python3 test/t1184-departing-playwright.py URL TAG
5Logged-out solo game: launch a 3-wide rocket in columns 3-5, let it rise
6past 75% of the field, then (game clock paused, rendering live) spawn
7blocks and ingest garbage aimed at the rocket columns. Screenshots the
8moment and checks every new block is outside the rocket columns.
9"""
10import json, sys
11from pathlib import Path
12from playwright.sync_api import sync_playwright
13
14URL = sys.argv[1] if len(sys.argv) > 1 else "https://projects.timfalken.com/meteors/"
15TAG = sys.argv[2] if len(sys.argv) > 2 else "live"
16SHOTS = Path("/workspace/meteors-shots")
17fails = []
18
19def check(c, m):
20 print(("OK " if c else "FAIL ") + m)
21 if not c: fails.append(m)
22
23with sync_playwright() as pw:
24 br = pw.chromium.launch(args=["--use-gl=angle", "--use-angle=swiftshader"])
25 for name, vp, mobile in (("desktop", {"width": 1280, "height": 800}, False), ("mobile", {"width": 390, "height": 844}, True)):
26 ctx = br.new_context(viewport=vp, is_mobile=mobile, has_touch=mobile, device_scale_factor=3 if mobile else 1)
27 page = ctx.new_page()
28 errors = []
29 page.on("pageerror", lambda e: errors.append(str(e)))
30 page.goto(URL + ("" if URL.endswith("/") else "/") + "index.html?t1184=" + TAG, wait_until="networkidle")
31 check(page.evaluate("() => typeof GameCore.prototype.departingColumns === 'function'"), f"{name}: departingColumns in served game.js")
32 page.locator("#btn-play").click()
33 page.wait_for_selector("#planet-select:not([hidden])", timeout=8000)
34 page.wait_for_timeout(200)
35 page.locator("#btn-planet-go").click()
36 page.wait_for_function("() => window.app && app.mode === 'playing' && app.core", timeout=10000)
37 page.wait_for_timeout(300)
38 # t1187/t1188: spawning speeds up 0.3% per block, from 1 s.
39 page.wait_for_timeout(3200)
40 sp = page.evaluate("() => ({ f: GameCore.SPAWN_SPEEDUP, min: GameCore.SPAWN_INTERVAL_MIN, iv: app.core.spawnInterval })")
41 n = round(__import__("math").log(sp["iv"]) / __import__("math").log(0.997)) if sp["iv"] < 1 else 0
42 check(sp["f"] == 0.997 and sp["min"] == 0.1 and 0.97 < sp["iv"] < 1, f"{name}: spawn interval {sp['iv']:.4f} s after ~3.5 s of play ({n} spawns × 0.997)")
43 page.evaluate("""() => {
44 const g = app.core;
45 g.spawnInterval = 1e9;
46 for (const b of g.blocks.slice()) g.removeBlock(b);
47 [[0, 2], [1, 3]].forEach(([c, k]) => g.place(c, 0, k));
48 const row = [3, 4, 5].map(c => g.place(c, 0, 1));
49 window.__rocket = { row, cluster: g.launchCluster(row, 30) };
50 }""")
51 page.wait_for_function("""() => { const r = window.__rocket; const live = r.row.filter(b => app.core.blocks.includes(b));
52 return live.length && Math.max(...live.map(b => b.y)) >= 10.0; }""", timeout=10000, polling="raf")
53 res = page.evaluate("""() => {
54 const g = app.core;
55 g.__tick = g.tick; g.tick = function () {};
56 const top = Math.max(...window.__rocket.row.map(b => b.y));
57 const dep = Object.keys(g.departingColumns()).map(Number).sort();
58 const spawned = [];
59 for (let i = 0; i < 6; i++) { const b = g.trySpawn(); if (b) { b.y = 12 - (i % 3) * 0.2; spawned.push(b.col); } }
60 const garbage = [];
61 for (const c of [3, 4, 5, 4]) { const b = g.ingestGarbage(c); if (b) { b.y = 11; garbage.push(b.col); } }
62 return { top, dep, spawned, garbage, line: g.DEPART_LINE() };
63 }""")
64 page.wait_for_timeout(120)
65 shot = SHOTS / f"t1184-{TAG}-{name}-departing.png"
66 page.screenshot(path=str(shot))
67 # Resume: rocket leaves, spawning into those columns is allowed again.
68 after = page.evaluate("""async () => {
69 const g = app.core; g.tick = g.__tick;
70 await new Promise(r => setTimeout(r, 1500));
71 const left = !window.__rocket.row.some(b => g.blocks.includes(b));
72 return { left, dep: Object.keys(g.departingColumns()).length };
73 }""")
74 page.screenshot(path=str(SHOTS / f"t1184-{TAG}-{name}-after-leaving.png"))
75 print(name, json.dumps(res), json.dumps(after))
76 check(res["top"] >= res["line"] and res["dep"] == [3, 4, 5], f"{name}: rocket top {res['top']:.2f} past 75% ({res['line']}), departing cols {res['dep']}")
77 check(len(res["spawned"]) == 6 and not set(res["spawned"]) & {3, 4, 5}, f"{name}: spawned in {res['spawned']} (not 3-5)")
78 check(len(res["garbage"]) == 4 and not set(res["garbage"]) & {3, 4, 5}, f"{name}: garbage aimed at 3/4/5 landed in {res['garbage']}")
79 check(after["left"] and after["dep"] == 0, f"{name}: rocket left the screen, columns open again")
80 check(not errors, f"{name}: no page errors {errors[:2]}")
81 ctx.close()
82 br.close()
83print("ALL OK" if not fails else f"{len(fails)} FAIL")
84sys.exit(1 if fails else 0)