t1184-t1186: new and received blocks avoid columns of a departing rocket stack
@@ -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). */642
GameCore.DEPART_SHARE = 0.75;643
644
/**645
* Columns with a rising rocket stack that will certainly leave the646
* 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 apex648
* (y + vy^2 / (2 * decel)) is at or above the top, and nothing grounded649
* hangs above it in its columns. Every column that stack occupies is650
* departing: newly spawned blocks and received garbage pick another651
* 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 off703
// 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
GameCore.prototype.trySpawn = function ()716
GameCore.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). */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 at761
* SPAWN_INTERVAL_MIN. Starts at PlanetMod.SPAWN_INTERVAL (1 s) for every762
* 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
GameCore.prototype.integrateFalling = function (dt)772
GameCore.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; only2190
// 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;@@ -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 rocket4
// 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
});