I'm representing tetris pieces as:
var jPiece = [
[ true, false, false ],
[ true, true, true]
];
This is the L shaped piece, where false represents emptiness. Once it's rotated, it should look like
var jPiece = [
[false, true],
[false, true],
[true, true],
]
I have a rotate function written like this:
function rotate1(L) {
var result = [];
var a;
for (var col = 1; col < (L[0].length) +1; col++) {
//print("yeet");
var result1 = [];
for (var row = 0; row < L.length; row++) {
a = L[row][L.length - col];
result1.push(a);
print(a);
}
result.push(result1);
}
return result;
}
function rotateFallingPiece() {
fallingPiece = rotate1(fallingPiece);
fallingPieceCols = fallingPiece[0].length;
if (fallingPieceIsLegal == false) {
for (var i = 0; i < 3; i ++) {
fallingPiece = rotate1(fallingPiece);
fallingPieceCols = fallingPiece[0].length;
}
}
print(fallingPiece);
}
however, when I run the rotate1(L) on a tetris piece, it doesn't rotate the entire piece, i.e, some of it is lost. please help!