t1192: queue received garbage, drop only when the spawn cell is clear; never lose blocks
@@ -87,6 +87,8 @@ function GameCore (planet, rng)
87
87
this.drag = null;
88
88
this.gameOverTime = 0;
89
89
this.outgoingShots = [];
90
/** Received garbage waiting for room (t1192). */
91
this.garbageQueue = [];
90
92
// Stage-2 default; stage 3 replaces this with Planet.missChance (Power).
91
93
this.missChance = optsMissChance(arguments);
92
94
// t1112: invariant checker. strictInvariants throws (tests);
@@ -591,6 +593,9 @@ GameCore.prototype.tick = function (dt)
591
593
592
594
// t1189: spawn timeline by elapsed play time (intro burst, ramp, then
593
595
// the per-spawn speed-up). Interval is re-read after every spawn.
596
// t1192: waiting received blocks drop first, as soon as there is room.
597
if (this.garbageQueue.length)
598
{ this.drainGarbageQueue(); }
594
599
this.spawnTimer += dt;
595
600
var iv = this.currentSpawnInterval();
596
601
while (this.spawnTimer >= iv)
@@ -2295,17 +2300,98 @@ GameCore.prototype.pickGarbageColumn = function (preferred)
2295
2300
return eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
2296
2301
};
2297
2302
2303
/**
2304
* Receive one garbage block (t1192). It is queued and dropped as soon as
2305
* there is room; received blocks are never lost. Returns the block when
2306
* it could drop right away, otherwise null (it waits in garbageQueue).
2307
*
2308
* Before t1192 every received block was created at once at the spawn
2309
* row of its column. Several blocks aimed at the same column overlapped
2310
* there: the second one "landed" on the first at y ≥ 13, was culled off
2311
* the top and even counted as the receiver's own shot.
2312
*/
2298
2313
GameCore.prototype.ingestGarbage = function (col)
2299
2314
{
2300
2315
if (this.state !== 'playing')
2301
2316
{ return null; }
2302
var chosen = this.pickGarbageColumn(col);
2303
if (chosen == null)
2304
{ return null; }
2305
var block = this.createBlock(chosen, this.height, COLOR_GRAY, STATE_FALLING);
2306
block.vy = -this.planet.fallSpeed;
2307
block.flame = false;
2308
return block;
2317
var want = (col != null && isFinite(col)) ? (col | 0) : null;
2318
var item = { col: want, block: null };
2319
this.garbageQueue.push(item);
2320
this.drainGarbageQueue();
2321
return item.block;
2322
};
2323
2324
/**
2325
* Can a block enter `col` at the spawn row now? Same rule as the opening
2326
* burst: every block already in the column must be at least a full cell
2327
* below the spawn row (no overlap).
2328
*/
2329
GameCore.prototype.spawnCellClear = function (col)
2330
{
2331
for (var i = 0; i < this.blocks.length; i++)
2332
{
2333
var b = this.blocks[i];
2334
if (b.col === col && b.y > this.height - 1 + 1e-9)
2335
{ return false; }
2336
}
2337
return true;
2338
};
2339
2340
/** Columns a queued garbage block can drop into right now (t1192). */
2341
GameCore.prototype.garbageDropColumns = function ()
2342
{
2343
var open = this.eligibleGarbageColumns();
2344
var departing = this.departingColumns();
2345
var out = [];
2346
for (var i = 0; i < open.length; i++)
2347
{
2348
var c = open[i];
2349
if (departing[c])
2350
{ continue; }
2351
// Room left for one more block once everything in flight lands.
2352
if (this.groundedCount(c) + this.fallingCount(c) >= this.height)
2353
{ continue; }
2354
if (!this.spawnCellClear(c))
2355
{ continue; }
2356
out.push(c);
2357
}
2358
return out;
2359
};
2360
2361
/**
2362
* Drop queued garbage in arrival order while there is room. The wanted
2363
* column (server land_col / bot pick) wins when it can take a block,
2364
* otherwise a random open one. When nothing is open the rest waits.
2365
* Returns how many blocks dropped.
2366
*/
2367
GameCore.prototype.drainGarbageQueue = function ()
2368
{
2369
var dropped = 0;
2370
while (this.garbageQueue.length && this.state === 'playing')
2371
{
2372
var cols = this.garbageDropColumns();
2373
if (!cols.length)
2374
{ break; }
2375
var item = this.garbageQueue[0];
2376
var chosen = null;
2377
if (item.col != null && cols.indexOf(item.col) >= 0)
2378
{ chosen = item.col; }
2379
else
2380
{ chosen = cols[Math.floor(this.rng() * cols.length) % cols.length]; }
2381
this.garbageQueue.shift();
2382
var block = this.createBlock(chosen, this.height, COLOR_GRAY, STATE_FALLING);
2383
block.vy = -this.planet.fallSpeed;
2384
block.flame = false;
2385
item.block = block;
2386
dropped++;
2387
}
2388
return dropped;
2389
};
2390
2391
/** Received blocks still waiting for room (t1192). */
2392
GameCore.prototype.pendingGarbage = function ()
2393
{
2394
return this.garbageQueue.length;
2309
2395
};
2310
2396
2311
2397
GameCore.prototype.advanceSettle = function (dt)
@@ -87,6 +87,8 @@ function GameCore (planet, rng)87
this.drag = null;87
this.drag = null;88
this.gameOverTime = 0;88
this.gameOverTime = 0;89
this.outgoingShots = [];89
this.outgoingShots = [];90
/** Received garbage waiting for room (t1192). */91
this.garbageQueue = [];90
// Stage-2 default; stage 3 replaces this with Planet.missChance (Power).92
// Stage-2 default; stage 3 replaces this with Planet.missChance (Power).91
this.missChance = optsMissChance(arguments);93
this.missChance = optsMissChance(arguments);92
// t1112: invariant checker. strictInvariants throws (tests);94
// t1112: invariant checker. strictInvariants throws (tests);@@ -591,6 +593,9 @@ GameCore.prototype.tick = function (dt)591
593
592
// t1189: spawn timeline by elapsed play time (intro burst, ramp, then594
// t1189: spawn timeline by elapsed play time (intro burst, ramp, then593
// the per-spawn speed-up). Interval is re-read after every spawn.595
// the per-spawn speed-up). Interval is re-read after every spawn.596
// t1192: waiting received blocks drop first, as soon as there is room.597
if (this.garbageQueue.length)598
{ this.drainGarbageQueue(); }594
this.spawnTimer += dt;599
this.spawnTimer += dt;595
var iv = this.currentSpawnInterval();600
var iv = this.currentSpawnInterval();596
while (this.spawnTimer >= iv)601
while (this.spawnTimer >= iv)@@ -2295,17 +2300,98 @@ GameCore.prototype.pickGarbageColumn = function (preferred)2295
return eligible[Math.floor(this.rng() * eligible.length) % eligible.length];2300
return eligible[Math.floor(this.rng() * eligible.length) % eligible.length];2296
};2301
};2297
2302
2303
/**2304
* Receive one garbage block (t1192). It is queued and dropped as soon as2305
* there is room; received blocks are never lost. Returns the block when2306
* it could drop right away, otherwise null (it waits in garbageQueue).2307
*2308
* Before t1192 every received block was created at once at the spawn2309
* row of its column. Several blocks aimed at the same column overlapped2310
* there: the second one "landed" on the first at y ≥ 13, was culled off2311
* the top and even counted as the receiver's own shot.2312
*/2298
GameCore.prototype.ingestGarbage = function (col)2313
GameCore.prototype.ingestGarbage = function (col)2299
{2314
{2300
if (this.state !== 'playing')2315
if (this.state !== 'playing')2301
{ return null; }2316
{ return null; }2302
var chosen = this.pickGarbageColumn(col);2317
var want = (col != null && isFinite(col)) ? (col | 0) : null;2303
if (chosen == null)2318
var item = { col: want, block: null };2304
{ return null; }2319
this.garbageQueue.push(item);2305
var block = this.createBlock(chosen, this.height, COLOR_GRAY, STATE_FALLING);2320
this.drainGarbageQueue();2306
block.vy = -this.planet.fallSpeed;2321
return item.block;2307
block.flame = false;2322
};2308
return block;2323
2324
/**2325
* Can a block enter `col` at the spawn row now? Same rule as the opening2326
* burst: every block already in the column must be at least a full cell2327
* below the spawn row (no overlap).2328
*/2329
GameCore.prototype.spawnCellClear = function (col)2330
{2331
for (var i = 0; i < this.blocks.length; i++)2332
{2333
var b = this.blocks[i];2334
if (b.col === col && b.y > this.height - 1 + 1e-9)2335
{ return false; }2336
}2337
return true;2338
};2339
2340
/** Columns a queued garbage block can drop into right now (t1192). */2341
GameCore.prototype.garbageDropColumns = function ()2342
{2343
var open = this.eligibleGarbageColumns();2344
var departing = this.departingColumns();2345
var out = [];2346
for (var i = 0; i < open.length; i++)2347
{2348
var c = open[i];2349
if (departing[c])2350
{ continue; }2351
// Room left for one more block once everything in flight lands.2352
if (this.groundedCount(c) + this.fallingCount(c) >= this.height)2353
{ continue; }2354
if (!this.spawnCellClear(c))2355
{ continue; }2356
out.push(c);2357
}2358
return out;2359
};2360
2361
/**2362
* Drop queued garbage in arrival order while there is room. The wanted2363
* column (server land_col / bot pick) wins when it can take a block,2364
* otherwise a random open one. When nothing is open the rest waits.2365
* Returns how many blocks dropped.2366
*/2367
GameCore.prototype.drainGarbageQueue = function ()2368
{2369
var dropped = 0;2370
while (this.garbageQueue.length && this.state === 'playing')2371
{2372
var cols = this.garbageDropColumns();2373
if (!cols.length)2374
{ break; }2375
var item = this.garbageQueue[0];2376
var chosen = null;2377
if (item.col != null && cols.indexOf(item.col) >= 0)2378
{ chosen = item.col; }2379
else2380
{ chosen = cols[Math.floor(this.rng() * cols.length) % cols.length]; }2381
this.garbageQueue.shift();2382
var block = this.createBlock(chosen, this.height, COLOR_GRAY, STATE_FALLING);2383
block.vy = -this.planet.fallSpeed;2384
block.flame = false;2385
item.block = block;2386
dropped++;2387
}2388
return dropped;2389
};2390
2391
/** Received blocks still waiting for room (t1192). */2392
GameCore.prototype.pendingGarbage = function ()2393
{2394
return this.garbageQueue.length;2309
};2395
};2310
2396
2311
GameCore.prototype.advanceSettle = function (dt)2397
GameCore.prototype.advanceSettle = function (dt)@@ -105,7 +105,7 @@ describe('Departing rocket columns (t1184)', () =>
105
105
assert.deepEqual(Object.keys(g.departingColumns()), []);
106
106
});
107
107
108
it('if every open column is departing, garbage still arrives (never lost)', () =>
108
it('if every open column is departing, garbage waits and arrives later (never lost)', () =>
109
109
{
110
110
const g = makeGame({ noSpawn: true });
111
111
const all = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
@@ -113,9 +113,12 @@ describe('Departing rocket columns (t1184)', () =>
113
113
riseUntil(g, row, cluster, 10);
114
114
assert.equal(Object.keys(g.departingColumns()).length, 10);
115
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);
116
// t1192: it waits in the queue (not dropped into the rocket, not lost).
117
assert.equal(g.ingestGarbage(4), null);
118
assert.equal(g.pendingGarbage(), 1);
119
for (let i = 0; i < 600 && g.pendingGarbage(); i++) g.step(1 / 120, 1 / 120);
120
assert.equal(g.pendingGarbage(), 0, 'dropped once the rocket left');
121
assert.ok(g.blocks.some((x) => x.color === -1 && x.state === 'falling' && x.col === 4), 'in the wanted column');
119
122
});
120
123
121
124
it('the stack really leaves and the columns open up again', () =>
@@ -105,7 +105,7 @@ describe('Departing rocket columns (t1184)', () =>105
assert.deepEqual(Object.keys(g.departingColumns()), []);105
assert.deepEqual(Object.keys(g.departingColumns()), []);106
});106
});107
107
108
it('if every open column is departing, garbage still arrives (never lost)', () =>108
it('if every open column is departing, garbage waits and arrives later (never lost)', () =>109
{109
{110
const g = makeGame({ noSpawn: true });110
const g = makeGame({ noSpawn: true });111
const all = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];111
const all = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];@@ -113,9 +113,12 @@ describe('Departing rocket columns (t1184)', () =>113
riseUntil(g, row, cluster, 10);113
riseUntil(g, row, cluster, 10);114
assert.equal(Object.keys(g.departingColumns()).length, 10);114
assert.equal(Object.keys(g.departingColumns()).length, 10);115
assert.equal(g.trySpawn(), null, 'no new block while every column is departing');115
assert.equal(g.trySpawn(), null, 'no new block while every column is departing');116
const b = g.ingestGarbage(4);116
// t1192: it waits in the queue (not dropped into the rocket, not lost).117
assert.ok(b, 'garbage kept');117
assert.equal(g.ingestGarbage(4), null);118
assert.equal(b.col, 4);118
assert.equal(g.pendingGarbage(), 1);119
for (let i = 0; i < 600 && g.pendingGarbage(); i++) g.step(1 / 120, 1 / 120);120
assert.equal(g.pendingGarbage(), 0, 'dropped once the rocket left');121
assert.ok(g.blocks.some((x) => x.color === -1 && x.state === 'falling' && x.col === 4), 'in the wanted column');119
});122
});120
123
121
it('the stack really leaves and the columns open up again', () =>124
it('the stack really leaves and the columns open up again', () =>@@ -0,0 +1,166 @@
1
'use strict';
2
3
// t1192: received blocks queue and are never lost.
4
5
const { describe, it } = require('node:test');
6
const assert = require('node:assert/strict');
7
const { makeGame } = require('./helpers.js');
8
const { GameCore } = require('../src/gameCore.js');
9
10
const GRAY = GameCore.COLOR_GRAY;
11
12
function lockedExcept (g, open)
13
{
14
for (let c = 0; c < g.width; c++)
15
{
16
if (open.includes(c)) continue;
17
for (let r = 0; r < g.height; r++) g.place(c, r, (r + c) % 5, 'locked');
18
}
19
}
20
21
function run (g, seconds, onShot)
22
{
23
let shots = 0;
24
for (let i = 0; i < Math.round(seconds * 120); i++)
25
{
26
g.step(1 / 120, 1 / 120);
27
shots += g.consumeOutgoingShots().length;
28
}
29
return shots;
30
}
31
32
function grayCount (g, cols)
33
{
34
return g.blocks.filter((b) => cols.includes(b.col) && (b.color === GRAY || b.garbage)).length;
35
}
36
37
describe('Received garbage queue (t1192)', () =>
38
{
39
it('exact scenario: 5 blocks at once, 2 open columns, all aimed at one → all 5 land', () =>
40
{
41
for (const seed of [1, 2, 3, 4, 5, 6])
42
{
43
const g = makeGame({ noSpawn: true, seed });
44
lockedExcept(g, [3, 7]);
45
const before = g.blocks.length;
46
for (let i = 0; i < 5; i++) g.ingestGarbage(3);
47
const shots = run(g, 8);
48
assert.equal(g.pendingGarbage(), 0, 'queue drained (seed ' + seed + ')');
49
assert.equal(g.blocks.length - before, 5, 'all 5 on the field (seed ' + seed + ')');
50
assert.equal(shots, 0, 'none culled off the top / sent back');
51
assert.equal(g.score, 0, 'receiver gains no points from them');
52
// Stacked without overlap in columns 3 and 7.
53
for (const c of [3, 7])
54
{
55
const ys = g.blocksInColumn(c).map((b) => b.y);
56
ys.forEach((y, k) => assert.equal(y, k, 'col ' + c + ' row ' + k));
57
}
58
}
59
});
60
61
it('random aims with 2 open columns: still all 5 land', () =>
62
{
63
const g = makeGame({ noSpawn: true, seed: 9 });
64
lockedExcept(g, [0, 9]);
65
const before = g.blocks.length;
66
for (const c of [0, 9, 0, 4, 9]) g.ingestGarbage(c);
67
run(g, 8);
68
assert.equal(g.blocks.length - before, 5);
69
assert.equal(g.pendingGarbage(), 0);
70
});
71
72
it('blocks in one column never overlap and drop only after a full cell of clearance', () =>
73
{
74
const g = makeGame({ noSpawn: true, seed: 2 });
75
lockedExcept(g, [5]);
76
for (let i = 0; i < 3; i++) g.ingestGarbage(5);
77
assert.equal(g.pendingGarbage(), 2, 'one drops now, two wait');
78
let minGap = Infinity;
79
for (let i = 0; i < 120 * 6; i++)
80
{
81
g.step(1 / 120, 1 / 120);
82
const col = g.blocksInColumn(5);
83
for (let k = 1; k < col.length; k++) minGap = Math.min(minGap, col[k].y - col[k - 1].y);
84
}
85
assert.ok(minGap >= 1 - 1e-6, 'min gap ' + minGap);
86
assert.equal(g.blocksInColumn(5).length, 3);
87
});
88
89
it('no open column: garbage waits (not dropped, not lost) and lands when room appears', () =>
90
{
91
const g = makeGame({ noSpawn: true, seed: 3 });
92
lockedExcept(g, [2]);
93
// The only open column holds a rocket that is leaving (t1184).
94
const r = g.place(2, 0, 1);
95
const cluster = g.launchCluster([r], 30);
96
for (let i = 0; i < 400 && r.y < 10; i++) g.step(1 / 120, 1 / 120);
97
assert.ok(g.departingColumns()[2]);
98
assert.equal(g.ingestGarbage(2), null);
99
assert.equal(g.ingestGarbage(7), null);
100
assert.equal(g.pendingGarbage(), 2, 'both wait');
101
run(g, 5);
102
assert.equal(g.state, 'playing');
103
assert.equal(g.pendingGarbage(), 0, 'dropped after the rocket left');
104
assert.equal(g.blocksInColumn(2).filter((b) => b.color === GRAY).length, 2);
105
assert.ok(cluster);
106
});
107
108
it('a full column (counting blocks still falling) is skipped for another open one', () =>
109
{
110
const g = makeGame({ noSpawn: true, seed: 4 });
111
lockedExcept(g, [1, 6]);
112
for (let r = 0; r < 12; r++) g.place(1, r, r % 5, 'still'); // one cell left in col 1
113
const before = g.blocks.length;
114
for (let i = 0; i < 4; i++) g.ingestGarbage(1);
115
run(g, 10);
116
assert.equal(g.blocks.length - before, 4);
117
assert.equal(g.blocksInColumn(1).length, 13, 'col 1 filled to the top, not beyond');
118
assert.equal(g.blocksInColumn(6).length, 3, 'rest went to col 6');
119
assert.equal(g.pendingGarbage(), 0);
120
});
121
122
it('open wanted column wins; a free field takes all at once in distinct columns', () =>
123
{
124
const g = makeGame({ noSpawn: true, seed: 5 });
125
const a = g.ingestGarbage(4);
126
assert.equal(a.col, 4);
127
const b = g.ingestGarbage(4);
128
assert.ok(b && b.col !== 4, 'second picks another column instead of overlapping');
129
assert.equal(g.pendingGarbage(), 0);
130
});
131
132
it('garbage is not accepted after game over (as before)', () =>
133
{
134
const g = makeGame({ noSpawn: true });
135
g.state = 'gameover';
136
assert.equal(g.ingestGarbage(1), null);
137
assert.equal(g.pendingGarbage(), 0);
138
});
139
});
140
141
describe('Received garbage queue — offline bots (t1192)', () =>
142
{
143
it('5 shots at once to a bot with 2 open columns: all 5 land on the bot', () =>
144
{
145
const { Planet, Rng } = require('./helpers.js');
146
const Offline = require('../src/offline.js');
147
const battle = Offline.createBattle({ playerPlanet: Planet.defaultPlanet(), rng: Rng.create(7), round: 1 });
148
const bot = battle.bots[0];
149
const core = bot.core;
150
core.spawnInterval = 1e9;
151
lockedExcept(core, [2, 8]);
152
const before = core.blocks.length;
153
for (let i = 0; i < 5; i++)
154
{ battle.pending.push({ at: battle.clock, targetId: bot.id, color: 1, fromId: 'me', landCol: 2 }); }
155
const player = makeGame({ noSpawn: true });
156
for (let i = 0; i < 120 * 8; i++)
157
{
158
battle.clock += 1 / 120;
159
battle._deliver(player);
160
core.step(1 / 120, 1 / 120);
161
core.consumeOutgoingShots();
162
}
163
assert.equal(core.pendingGarbage(), 0);
164
assert.equal(core.blocks.length - before, 5, 'all 5 on the bot field');
165
});
166
});
@@ -0,0 +1,166 @@1
'use strict';2
3
// t1192: received blocks queue and are never lost.4
5
const { describe, it } = require('node:test');6
const assert = require('node:assert/strict');7
const { makeGame } = require('./helpers.js');8
const { GameCore } = require('../src/gameCore.js');9
10
const GRAY = GameCore.COLOR_GRAY;11
12
function lockedExcept (g, open)13
{14
for (let c = 0; c < g.width; c++)15
{16
if (open.includes(c)) continue;17
for (let r = 0; r < g.height; r++) g.place(c, r, (r + c) % 5, 'locked');18
}19
}20
21
function run (g, seconds, onShot)22
{23
let shots = 0;24
for (let i = 0; i < Math.round(seconds * 120); i++)25
{26
g.step(1 / 120, 1 / 120);27
shots += g.consumeOutgoingShots().length;28
}29
return shots;30
}31
32
function grayCount (g, cols)33
{34
return g.blocks.filter((b) => cols.includes(b.col) && (b.color === GRAY || b.garbage)).length;35
}36
37
describe('Received garbage queue (t1192)', () =>38
{39
it('exact scenario: 5 blocks at once, 2 open columns, all aimed at one → all 5 land', () =>40
{41
for (const seed of [1, 2, 3, 4, 5, 6])42
{43
const g = makeGame({ noSpawn: true, seed });44
lockedExcept(g, [3, 7]);45
const before = g.blocks.length;46
for (let i = 0; i < 5; i++) g.ingestGarbage(3);47
const shots = run(g, 8);48
assert.equal(g.pendingGarbage(), 0, 'queue drained (seed ' + seed + ')');49
assert.equal(g.blocks.length - before, 5, 'all 5 on the field (seed ' + seed + ')');50
assert.equal(shots, 0, 'none culled off the top / sent back');51
assert.equal(g.score, 0, 'receiver gains no points from them');52
// Stacked without overlap in columns 3 and 7.53
for (const c of [3, 7])54
{55
const ys = g.blocksInColumn(c).map((b) => b.y);56
ys.forEach((y, k) => assert.equal(y, k, 'col ' + c + ' row ' + k));57
}58
}59
});60
61
it('random aims with 2 open columns: still all 5 land', () =>62
{63
const g = makeGame({ noSpawn: true, seed: 9 });64
lockedExcept(g, [0, 9]);65
const before = g.blocks.length;66
for (const c of [0, 9, 0, 4, 9]) g.ingestGarbage(c);67
run(g, 8);68
assert.equal(g.blocks.length - before, 5);69
assert.equal(g.pendingGarbage(), 0);70
});71
72
it('blocks in one column never overlap and drop only after a full cell of clearance', () =>73
{74
const g = makeGame({ noSpawn: true, seed: 2 });75
lockedExcept(g, [5]);76
for (let i = 0; i < 3; i++) g.ingestGarbage(5);77
assert.equal(g.pendingGarbage(), 2, 'one drops now, two wait');78
let minGap = Infinity;79
for (let i = 0; i < 120 * 6; i++)80
{81
g.step(1 / 120, 1 / 120);82
const col = g.blocksInColumn(5);83
for (let k = 1; k < col.length; k++) minGap = Math.min(minGap, col[k].y - col[k - 1].y);84
}85
assert.ok(minGap >= 1 - 1e-6, 'min gap ' + minGap);86
assert.equal(g.blocksInColumn(5).length, 3);87
});88
89
it('no open column: garbage waits (not dropped, not lost) and lands when room appears', () =>90
{91
const g = makeGame({ noSpawn: true, seed: 3 });92
lockedExcept(g, [2]);93
// The only open column holds a rocket that is leaving (t1184).94
const r = g.place(2, 0, 1);95
const cluster = g.launchCluster([r], 30);96
for (let i = 0; i < 400 && r.y < 10; i++) g.step(1 / 120, 1 / 120);97
assert.ok(g.departingColumns()[2]);98
assert.equal(g.ingestGarbage(2), null);99
assert.equal(g.ingestGarbage(7), null);100
assert.equal(g.pendingGarbage(), 2, 'both wait');101
run(g, 5);102
assert.equal(g.state, 'playing');103
assert.equal(g.pendingGarbage(), 0, 'dropped after the rocket left');104
assert.equal(g.blocksInColumn(2).filter((b) => b.color === GRAY).length, 2);105
assert.ok(cluster);106
});107
108
it('a full column (counting blocks still falling) is skipped for another open one', () =>109
{110
const g = makeGame({ noSpawn: true, seed: 4 });111
lockedExcept(g, [1, 6]);112
for (let r = 0; r < 12; r++) g.place(1, r, r % 5, 'still'); // one cell left in col 1113
const before = g.blocks.length;114
for (let i = 0; i < 4; i++) g.ingestGarbage(1);115
run(g, 10);116
assert.equal(g.blocks.length - before, 4);117
assert.equal(g.blocksInColumn(1).length, 13, 'col 1 filled to the top, not beyond');118
assert.equal(g.blocksInColumn(6).length, 3, 'rest went to col 6');119
assert.equal(g.pendingGarbage(), 0);120
});121
122
it('open wanted column wins; a free field takes all at once in distinct columns', () =>123
{124
const g = makeGame({ noSpawn: true, seed: 5 });125
const a = g.ingestGarbage(4);126
assert.equal(a.col, 4);127
const b = g.ingestGarbage(4);128
assert.ok(b && b.col !== 4, 'second picks another column instead of overlapping');129
assert.equal(g.pendingGarbage(), 0);130
});131
132
it('garbage is not accepted after game over (as before)', () =>133
{134
const g = makeGame({ noSpawn: true });135
g.state = 'gameover';136
assert.equal(g.ingestGarbage(1), null);137
assert.equal(g.pendingGarbage(), 0);138
});139
});140
141
describe('Received garbage queue — offline bots (t1192)', () =>142
{143
it('5 shots at once to a bot with 2 open columns: all 5 land on the bot', () =>144
{145
const { Planet, Rng } = require('./helpers.js');146
const Offline = require('../src/offline.js');147
const battle = Offline.createBattle({ playerPlanet: Planet.defaultPlanet(), rng: Rng.create(7), round: 1 });148
const bot = battle.bots[0];149
const core = bot.core;150
core.spawnInterval = 1e9;151
lockedExcept(core, [2, 8]);152
const before = core.blocks.length;153
for (let i = 0; i < 5; i++)154
{ battle.pending.push({ at: battle.clock, targetId: bot.id, color: 1, fromId: 'me', landCol: 2 }); }155
const player = makeGame({ noSpawn: true });156
for (let i = 0; i < 120 * 8; i++)157
{158
battle.clock += 1 / 120;159
battle._deliver(player);160
core.step(1 / 120, 1 / 120);161
core.consumeOutgoingShots();162
}163
assert.equal(core.pendingGarbage(), 0);164
assert.equal(core.blocks.length - before, 5, 'all 5 on the bot field');165
});166
});