aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/src/util/tetris.ts
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/util/tetris.ts')
-rw-r--r--frontend/src/util/tetris.ts20
1 files changed, 19 insertions, 1 deletions
diff --git a/frontend/src/util/tetris.ts b/frontend/src/util/tetris.ts
index 3547108..6f9d827 100644
--- a/frontend/src/util/tetris.ts
+++ b/frontend/src/util/tetris.ts
@@ -1,5 +1,5 @@
import type { Board } from "@/model/board";
-import type { Tetromino } from "@/model/tetrominoes";
+import { allTetrominoes, type Tetromino } from "@/model/tetrominoes";
export function mergeTetrominoWithBoard(board: Board, tetromino: Tetromino): Board {
return board.map((row, rowIndex) => {
@@ -38,3 +38,21 @@ export function tetrominoCollidesWithBoard(board: Board, tetromino: Tetromino):
});
});
}
+
+export function randomiseNextTetrominoes(): Array<Tetromino> {
+ const tetrominoes = Object.values(allTetrominoes);
+ let currentIndex = tetrominoes.length,
+ randomIndex;
+
+ while (currentIndex > 0) {
+ randomIndex = Math.floor(Math.random() * currentIndex);
+ currentIndex--;
+
+ [tetrominoes[currentIndex], tetrominoes[randomIndex]] = [
+ tetrominoes[randomIndex],
+ tetrominoes[currentIndex],
+ ];
+ }
+
+ return tetrominoes;
+} \ No newline at end of file