Created
September 15, 2019 21:52
-
-
Save Jorger/7c6a5d431984b1c85ab89e08fbf835ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Crea un nuevo board, estableciendo la posición de las figuras en la misma | |
* @param {*} showFigure | |
*/ | |
const createBoard = (showFigure = 1) => { | |
const board = [...new Array(DIMENSION_BOARD)].map(() => | |
new Array(DIMENSION_BOARD).fill(0) | |
); | |
const figures = []; | |
// // Empezar a ubicar los elementos en el escenario... | |
for (let c = 1, initial = MAX_FIGURES; c <= MAX_FIGURES; c++, initial--) { | |
for (let d = 1; d <= c; d++) { | |
const figure = locateFigure(initial, board); | |
for (let r = figure[1]; r <= figure[3]; r++) { | |
for (let l = figure[2]; l <= figure[4]; l++) { | |
board[r][l] = 1; | |
} | |
} | |
/* | |
0 : Muestra figura | |
1 : Tamaño de la figura | |
2 : Giro | |
3 : Fila | |
4 : Columba | |
5 : Fila final | |
6 : Columna final | |
*/ | |
figures.push([showFigure, initial, ...figure]); | |
} | |
} | |
return { board, figures }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment