-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.js
634 lines (529 loc) · 22.7 KB
/
base.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
/*
* Copyright (c) 2024 bin jin.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @param max {number}
* @returns {number}
*/
function getRandomInt(max) {
return Math.floor(Math.random() * max);
}
/**
* 多个洗牌算法相连,且相邻两个数字不重复
* @param {number} size
* @returns {Generator<number, void, unknown>}
*/
function* Shuffle(size) {
let head;
while (true) {
let poker = Array.from({ length: size }, (v, i) => i * 1);
for (let i = size - 1; i >= 0; i--) {
let ri;
do {
ri = Math.floor(Math.random() * (i + 1));
} while (i == size - 1 && head == poker[ri])
yield poker[ri];
poker[ri] = poker[i];
if (i == 0) { head = poker[0]; }
}
}
}
class Block {
/** @type {number} */ x;
/** @type {number} */ y;
/** @type {number} */ style;
/**
* @param x {number}
* @param y {number}
* @param style {number}
*/
constructor(x, y, style) {
this.init(x, y, style);
}
/**
* @param x {number}
* @param y {number}
* @param style {number}
* @returns {Block}
*/
init(x, y, style) {
this.y = y;
this.x = x;
this.style = style;
}
toString() {
return `{x:${this.x}, y:${this.y}, s:${this.style}}`
}
}
/**
* 每个形状
*/
class Tetromino {
/** @type {Array<Block>} */ blocks;
/** @type {Array<boolean>} [up, right, down, lefft] */ banMoves;
constructor() {
this.blocks = Array.from({ length: 4 }, () => new Block()); // 初始化4个block
}
static #LTZO = [
[0, 0, 1, 0], // L
[0, 0, 2, 0], // T
[1, 0, 2, 0], // L
[0, 0, 0, 1], // O
[0, 0, 2, 1], // Z
[2, 0, 0, 1] // Z
];
/**
* 随机 6 种形状和若干颜色。并指定生成 I 型。
*
* 除了 I 型以外,其他六种形状都会占用三行两列。
*
* 将“用 2 个点将 3x2 矩阵分割成两半”的情况排除掉,剩下的排列就可以组成 L T Z O 四种方块之一。
* 其中 O 概率上会多一倍,强制降低即可。
*
* O O . O . O . O O O . . O . . . . O . . O + + + . X . . X . . X .
* . . . . . . . . . O . . . . O O . . . . O + . + X . . . X . . . X
*
* . . . . . . . . . O . . . . O O . . . . O + . + X . . . X . . . X
* O O . O . O . O O O . . O . . . . O . . O + + + . X . . X . . X .
*
* @param {number} style
* @param {boolean} isLine
*/
init(style, isLine) {
this.banMoves = [false, true, false, true]; // up right down lefft
if (isLine) {
for (let x = 0; x < this.blocks.length; x++) {
this.blocks[x].init(x, 0, style);
}
return;
}
/** @type {Array<number>} [ 0:x1, 1:y1, 2:x2, 3:y2 ] */
let non = Tetromino.#LTZO[getRandomInt(Tetromino.#LTZO.length)];
// let non;
// do {
// non = [getRandomInt(3), getRandomInt(2), getRandomInt(3), getRandomInt(2)];
//
// } while (
// (non[0] == non[2] && non[1] == non[3]) ||
// (non[1] != non[3] && (
// Math.abs(non[0] - non[2]) == 1 ||
// (non[0] == non[2] && non[0] != 2)
// ))
// )
let i = 0;
for (let x = 0; x < 3; x++) {
for (let y = 0; y < 2; y++) {
if (!((x === non[0] && y === non[1]) || (x === non[2] && y === non[3]))) {
this.blocks[i++].init(x, y, style);
}
}
}
// let non_row = 0, non_colume = 0, times = 0;
// let chirality = getRandomInt(2) === 0 ? 0 : 2; // 决定方块朝向
//
// do {
// if (++times > 2) { // 当重复次数超过三次生成 I 型
// for (let colume = 0; colume < this.blocks.length; colume++) {
// this.blocks[colume].init(0, colume, style);
// }
// return;
// }
// non_row = getRandomInt(2), non_colume = getRandomInt(3); // 确定 row = colume = 0 以外的另一个需要排除的点。
//
// } while (
// (non_row === 1 && non_colume === 1) ||
// (non_row === 0 && non_colume === chirality)
// );
//
// let i = 0;
// for (let row = 0; row < 2; row++) { // 刨去排除的点,产生正反 Z L O T 之一
// for (let colume = 0; colume < 3; colume++) {
// if (!(row === non_row && colume === non_colume || row === 0 && colume === chirality)) {
// this.blocks[i++].init(row, colume, style);
// }
// }
// }
//
// return this; // bug: [new Tetromino().init(), new Tetromino().init()]: random undefined
}
/**
* @param x {number}
* @param y {number}
*/
moveBy(x, y) {
this.blocks.forEach(block => {
block.x += x;
block.y += y;
});
}
/**
* 旋转
* 3 x 3 的矩阵
* 顺时针旋转 90 度:交换 y 与 x 的坐标并上下翻转。
* 逆时针旋转 90 度:交换 y 与 x 的坐标并左右翻转。
* 在交换过程中需要减去与 0,0 的间距,
* 在 0,0 点交换 y 与 x 会得到与目标图样颠倒的图样,
* 然后用 2 减去 x 或 y,再将间距加回来。
* 再移动回原来的位置即可实现旋转。
*
* @param counterclockwise {boolean}
*/
rotate(counterclockwise) {
// console.log(`rotate: before ${counterclockwise ? 1 : 0} ${this.blocks}`);
let min_x = this.blocks[0].x, min_y = this.blocks[0].y;
let line_x = true, line_y = true; // 用于判断直线
for (let i = 1; i < this.blocks.length; i++) {
min_x = Math.min(this.blocks[i].x, min_x);
min_y = Math.min(this.blocks[i].y, min_y);
line_x = line_x && this.blocks[0].x == this.blocks[i].x;
line_y = line_y && this.blocks[0].y == this.blocks[i].y;
}
if (line_x || line_y) { counterclockwise = false; }
let empty_line = 0;
this.blocks.forEach(block => {
let old_block_x = block.x;
block.x = (counterclockwise ? block.y - min_y : 2 - (block.y - min_y)) + min_x;
block.y = (!counterclockwise ? old_block_x - min_x : 2 - (old_block_x - min_x)) + min_y;
empty_line += counterclockwise ? (min_y != block.y ? 1 : 0) : (min_x != block.x ? 1 : 0);
});
if (empty_line == this.blocks.length) { this.moveBy(counterclockwise ? 0 : -1, counterclockwise ? -1 : 0); }
// console.log(`rotate: after ${counterclockwise ? 1 : 0} ${this.blocks}`);
}
toString() {
return `{blocks:[${this.blocks}], banMoves:[${this.banMoves}]}`
}
}
/**
* |-- width: 4 --|
* 0,0 5,0 _
* 0,1 5,1 |
* 0,2 O 5,2 |
* 0,3 O O O 5,3 | height: 8
* 0,4 5,4 |
* 0,5 5,5 |
* 0,6 5,6 |
* 0,7 5,7 -
* 0,8 1,8 2,8 3,8 4,8 5,8
*/
export class Background {
static WIDTH = 10; static HEIGHT = 20;
static WALL = -1; static EMPTY = -3;
static #BG_WIDTH_OFFSET = 1;
/** @type {number} */ #bg_auto_drop_cycle;
#autoDropSum = 0;
/**
* [-x+, -y+, exchangeTetromino, pause/game_over] 按键按下状态每步累计的按键累加值。
*/
#key_board_code_holds = Array.from({ length: 5 }, () => 0);
/** 1: pause, 2: gameover */
#gameStatus = 0; #sP = 0; #subLineSum = 0;
#generateTetrisLine = false;
/** @type {Array<number>} */ #TetrisLineListCache = new Array();
/** @type {Generator<number, void, unknown>} 随机不重复数字 */ #loopRan;
/** @type {Array<Tetromino>} */ #dual_tetromino;
/** @type {number} */ #tetIdx = 0;
/** @type {Array<Array<number>>} */ #current_blocksStyle;
/** @type {Snapshot} */ #snapshot;
/**
* @param {number} styleCount
* @param {number} skipCycle
*/
constructor(styleCount, skipCycle) {
this.#loopRan = Shuffle(styleCount);
this.#bg_auto_drop_cycle = skipCycle;
this.#dual_tetromino = [new Tetromino(), new Tetromino()];
this.#dual_tetromino[0].init(this.#loopRan.next().value, false);
this.#dual_tetromino[1].init(this.#loopRan.next().value, false);
const blocksStyle = new Array();
for (let y = 0; y < Background.HEIGHT + Background.#BG_WIDTH_OFFSET; y++) {
blocksStyle[y] = new Array();
if (y == Background.HEIGHT + Background.#BG_WIDTH_OFFSET - 1) {
for (let x = 0; x <= Background.WIDTH + Background.#BG_WIDTH_OFFSET; x++) { blocksStyle[y][x] = Background.WALL; }
} else {
for (const x of [0, Background.WIDTH + Background.#BG_WIDTH_OFFSET]) { blocksStyle[y][x] = Background.WALL; }
for (let x = 1; x <= Background.WIDTH; x++) { blocksStyle[y][x] = Background.EMPTY; }
}
}
this.#current_blocksStyle = blocksStyle;
this.#dual_tetromino[this.#tetIdx].moveBy(5, -2);
this.#snapshot = new Snapshot();
}
init() {
this.#exchangeTetromino();
this.#autoDropSum = 0;
this.#sP = 0;
this.#subLineSum = 0;
this.#gameStatus = 0;
this.#snapshot.init();
for (let y = 0; y < Background.HEIGHT; y++) {
for (let x = 1; x <= Background.WIDTH; x++) {
this.#current_blocksStyle[y][x] = Background.EMPTY;
}
}
}
#exchangeTetromino() {
// console.log(`exchange`);
this.#dual_tetromino[this.#tetIdx].init(this.#loopRan.next().value, this.#generateTetrisLine);
this.#generateTetrisLine = false;
this.#tetIdx = 1 - this.#tetIdx;
this.#dual_tetromino[this.#tetIdx].moveBy(5, -2);
}
#borderAABB() {
const tetris = this.#dual_tetromino[this.#tetIdx], cur_style = this.#current_blocksStyle;
tetris.banMoves.fill(false);
for (const block of tetris.blocks) {
if (block.y < 0) {
tetris.banMoves[1] = true;
tetris.banMoves[3] = true;
}
tetris.banMoves = [
tetris.banMoves[0] /*|| cur_style[block.y - 1] == undefined ||
cur_style[block.y - 1][block.x] > -2 */,
tetris.banMoves[1] || cur_style[block.y] == undefined ||
cur_style[block.y][block.x + 1] > -2,
tetris.banMoves[2] || (cur_style[block.y + 1] != undefined &&
cur_style[block.y + 1][block.x] > -2), // moveBy(5, -2)
tetris.banMoves[3] || cur_style[block.y] == undefined ||
cur_style[block.y][block.x - 1] > -2
]
}
}
/**
* @returns {boolean} hit
*/
#overAABB() {
for (const block of this.#dual_tetromino[this.#tetIdx].blocks) {
if (this.#current_blocksStyle[block.y] == undefined ||
this.#current_blocksStyle[block.y][block.x] > -2) {
return true;
}
}
return false;
}
#subLine() {
let sub_sum = 0;
let y = Background.HEIGHT - Background.#BG_WIDTH_OFFSET;
for (; y >= 0; y--) {
let block_sum = 0;
for (let x = 1; x <= Background.WIDTH; x++) {
if (this.#current_blocksStyle[y][x] >= 0) { block_sum++; }
}
if (block_sum == Background.WIDTH) {
sub_sum++;
let [styleArr] = this.#current_blocksStyle.splice(y++, 1);
styleArr.fill(Background.EMPTY);
styleArr[0] = Background.WALL;
styleArr[styleArr.length - 1] = Background.WALL;
this.#current_blocksStyle.unshift(styleArr);
}
if (block_sum == 0) { break; }
}
/**
* find line space
*/
if (y <= Background.HEIGHT - 5 && !this.#generateTetrisLine) {
const bs = this.#current_blocksStyle;
for (let x = 0; x < Background.WIDTH; x++) {
for (let _y = y + 1; _y < Background.HEIGHT - 2; _y++) {
// TODO if (this.#TetrisLineListCache = new Array()[0] == ) { continue; }
if (bs[_y][x + 1] != Background.EMPTY) { break; }
if (
bs[_y + 0][x] != Background.EMPTY && bs[_y + 0][x + 1] == Background.EMPTY && bs[_y + 0][x + 2] != Background.EMPTY &&
bs[_y + 1][x] != Background.EMPTY && bs[_y + 1][x + 1] == Background.EMPTY && bs[_y + 1][x + 2] != Background.EMPTY &&
bs[_y + 2][x] != Background.EMPTY && bs[_y + 2][x + 1] == Background.EMPTY && bs[_y + 2][x + 2] != Background.EMPTY
) {
// console.log(`find: x,y:${x + 1},${_y}-${_y + 2}`);
this.#generateTetrisLine = getRandomInt(3) == 0;
break;
}
}
if (this.#generateTetrisLine) { break; }
}
}
switch (sub_sum) {
case 1: break;
case 2: this.#sP += 1; break;
case 3: this.#sP += 3; break;
case 4: this.#sP += 6; break;
default: break;
}
this.#sP = Math.min(this.#sP, 30);
this.#subLineSum += sub_sum;
}
#hitBottom() {
const tetris = this.#dual_tetromino[this.#tetIdx];
// console.log(`save to background: ${tetris.blocks}`);
tetris.blocks.forEach(block => {
if (block.y >= 0) {
this.#current_blocksStyle[block.y][block.x] = block.style;
} else { this.#gameStatus = 2; console.log(`game over, ${this.#subLineSum}`); return; }
});
if (this.#gameStatus != 2) {
this.#subLine();
this.#exchangeTetromino();
tetris.banMoves[1] = true;
tetris.banMoves[3] = true;
}
}
/**
* @param {Array<number>} key_board_codes [-x+, -y+, exchangeTetromino, pause/game_over]
* @returns {Array<Array<number>>} [oldBg, newBg, exBg, ready, [gameStatus, sp, subLineSum]]
*/
run1Step(key_board_codes) {
for (const i in key_board_codes) {
key_board_codes[i] == 0 ? this.#key_board_code_holds[i] = 0 : this.#key_board_code_holds[i] += key_board_codes[i];
}
if (this.#key_board_code_holds[3] == 1) {
if (this.#gameStatus == 0) {
this.#gameStatus = 1;
return [[], [], [], [], [1, this.#sP, this.#subLineSum]];
} else if (this.#gameStatus == 1) {
this.#gameStatus = 0;
} else if (this.#gameStatus == 2) {
this.#gameStatus = 0;
this.init();
this.#dual_tetromino[this.#tetIdx].banMoves[2] = false;
return [[], [], [], [], [3, this.#sP, this.#subLineSum]];
}
}
if (this.#gameStatus != 0) {
return [[], [], [], [], [this.#gameStatus == 2 ? 2 : 1, this.#sP, this.#subLineSum]];
}
// console.log(`key_board_codes:${key_board_codes}, key_board_code_holds:${this.#key_board_code_holds}`);
const tetris = this.#dual_tetromino[this.#tetIdx];
if (this.#key_board_code_holds[0] > 0 && this.#key_board_code_holds[0] != 2 && this.#key_board_code_holds[0] != 3) {
this.#borderAABB();
if (!tetris.banMoves[1]) { tetris.moveBy(1, 0); }
} else if (this.#key_board_code_holds[0] < 0 && this.#key_board_code_holds[0] != -2 && this.#key_board_code_holds[0] != -3) {
this.#borderAABB();
if (!tetris.banMoves[3]) { tetris.moveBy(-1, 0); }
}
if (this.#key_board_code_holds[2] == 1) {
if (this.#sP > 0) {
this.#sP --;
this.#exchangeTetromino();
}
}
if (this.#key_board_code_holds[1] > 0) {
if (this.#key_board_code_holds[1] == 1) {
tetris.rotate()
if (this.#overAABB()) {
// tetris.rotate(); tetris.rotate(); tetris.rotate();
tetris.rotate(true);
}
}
} else if (this.#key_board_code_holds[1] < 0) {
for (let y = 0; y < this.#key_board_code_holds[1] * -1 / 2; y++) {
this.#borderAABB();
if (tetris.banMoves[2]) { this.#key_board_code_holds[1] = 2; this.#hitBottom(); } else { tetris.moveBy(0, 1); }
}
}
if (this.#autoDropSum++ >= this.#bg_auto_drop_cycle) {
this.#autoDropSum = 0;
if (this.#key_board_code_holds[1] >= 0) {
this.#borderAABB();
if (tetris.banMoves[2]) { this.#hitBottom(); } else { tetris.moveBy(0, 1); }
}
}
return this.#BgDiff();
}
/**
* @returns {Array<Array<number>>} [oldBg, newBg, exBg, ready, [gameStatus, sp, subLineSum]]
*/
#BgDiff() {
const oldBg = new Array(0), newBg = new Array(0), exBg = new Array(0), oldMap = new Map();
// tetromino diff
const old_tetris = this.#snapshot.log_dual_tetris[0], cur_tetris = this.#dual_tetromino[this.#tetIdx].blocks;
for (let i = 0; i < cur_tetris.length; i++) {
// auto down
if (old_tetris[i].x != cur_tetris[i].x - 1 || old_tetris[i].y != cur_tetris[i].y || old_tetris[i].style != cur_tetris[i].style) {
if (old_tetris[i].x == undefined) {
newBg.push(cur_tetris[i].x - 1, cur_tetris[i].y, cur_tetris[i].style);
} else if (old_tetris[i].x == cur_tetris[i].x - 1 && old_tetris[i].y == cur_tetris[i].y) {
exBg.push(cur_tetris[i].x - 1, cur_tetris[i].y, cur_tetris[i].style);
} else {
oldBg.push(old_tetris[i].x, old_tetris[i].y, old_tetris[i].style);
oldMap.set(`${old_tetris[i].x},${old_tetris[i].y}`, 1);
newBg.push(cur_tetris[i].x - 1, cur_tetris[i].y, cur_tetris[i].style);
}
old_tetris[i].init(cur_tetris[i].x - 1, cur_tetris[i].y, cur_tetris[i].style);
}
}
// background diff
const log_blocksStyle = this.#snapshot.log_blocksStyle, cur_blocksStyle = this.#current_blocksStyle;
for (let y = log_blocksStyle.length - 1; y >= 0; y--) {
let blocksStyleSum = 0;
for (let x = 0; x < log_blocksStyle[y].length; x++) {
if (log_blocksStyle[y][x] >= 0 || cur_blocksStyle[y][x + 1] >= 0) { blocksStyleSum++; }
if (log_blocksStyle[y][x] != cur_blocksStyle[y][x + 1]) {
if (log_blocksStyle[y][x] != Background.EMPTY && cur_blocksStyle[y][x + 1] > 0) {
exBg.push(x, y, cur_blocksStyle[y][x + 1]);
log_blocksStyle[y][x] = cur_blocksStyle[y][x + 1];
} else if (log_blocksStyle[y][x] != Background.EMPTY) {
oldBg.push(x, y, Background.EMPTY);
oldMap.set(`${x},${y}`, 1);
log_blocksStyle[y][x] = Background.EMPTY;
} else {
newBg.push(x, y, cur_blocksStyle[y][x + 1]);
log_blocksStyle[y][x] = cur_blocksStyle[y][x + 1];
}
}
}
if (blocksStyleSum == 0) { break; }
}
// trim block
let ni = 0;
while (newBg[ni] != undefined) {
if (oldMap.has(`${newBg[ni]},${newBg[ni + 1]}`)) {
oldMap.delete(`${newBg[ni]},${newBg[ni + 1]}`);
let oi = 0;
for (; oi < oldBg.length; oi += 3) { if (oldBg[oi] == newBg[ni] && oldBg[oi + 1] == newBg[ni + 1]) { break; } }
if (oldBg[oi + 2] != newBg[ni + 2]) { exBg.push(newBg[ni], newBg[ni + 1], newBg[ni + 2]); }
oldBg.splice(oi, 3);
newBg.splice(ni, 3);
}
ni += 3;
}
// ready tetromino
const ready = new Array(0), old_ready_tetris = this.#snapshot.log_dual_tetris[1], cur_ready_tetris = this.#dual_tetromino[1 - this.#tetIdx].blocks;
for (let i = 0; i < cur_ready_tetris.length; i++) {
if (old_ready_tetris[i].x != cur_ready_tetris[i].x || old_ready_tetris[i].y != cur_ready_tetris[i].y || old_ready_tetris[i].style != cur_ready_tetris[i].style) {
ready.push(cur_ready_tetris[i].x, cur_ready_tetris[i].y, cur_ready_tetris[i].style);
old_ready_tetris[i].init(cur_ready_tetris[i].x, cur_ready_tetris[i].y, cur_ready_tetris[i].style);
}
}
return [oldBg, newBg, exBg, ready, [0, this.#sP, this.#subLineSum]];
}
}
class Snapshot {
/** @type {Array<Array<Block>>} */ log_dual_tetris;
/** @type {Array<Array<number>>} */ log_blocksStyle;
constructor() {
this.log_blocksStyle = Array.from(
{ length: Background.HEIGHT },
() => new Array(Background.WIDTH).fill(Background.EMPTY)
);
// this.log_dual_tetris = Array.from({ length: 2 }, () => new Array(4).fill(new Block())); // bug: Array().fill(): same obj
this.log_dual_tetris = Array.from({ length: 2 }, () => Array.from({ length: 4 }, () => new Block()));
}
init() {
for (const cs of this.log_blocksStyle) { cs.fill(Background.EMPTY); }
for (const tetris of this.log_dual_tetris) {
for (const block of tetris) {
block.init(undefined, undefined, undefined);
}
}
}
}