let data = [];
function startGame() { // 4 × 4 표 그리기
const $fragment = document.createDocumentFragment();
[1, 2, 3, 4].forEach(function () {
const rowData = [];
data.push(rowData);
const $tr = document.createElement('tr');
[1, 2, 3, 4].forEach(() => {
rowData.push(0);
const $td = document.createElement('td');
$tr.appendChild($td);
});
$fragment.appendChild($tr);
});
$table.appendChild($fragment);
put2ToRandomCell();
draw();
}
function put2ToRandomCell() { // 빈칸을 찾아 무작위로 숫자 2 넣기
const emptyCells = [];
data.forEach(function (rowData, i) {
rowData.forEach(function (cellData, j) {
if (!cellData) {
emptyCells.push([i, j]);