-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f713f06
commit 3d2061d
Showing
4 changed files
with
81 additions
and
87 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
export function backtrackingAutoTiling(polyominoes, gridBoard, placePolyomino, removePolyomino, redraw) { | ||
const polyominoesCopy = [...polyominoes]; // Clone des polyominos pour ne pas les modifier | ||
polyominoesCopy.sort((a, b) => b.shape.flat().reduce((acc, val) => acc + val) - a.shape.flat().reduce((acc, val) => acc + val)); // trie par taille | ||
let index = 0; | ||
|
||
function placeNextPolyomino() { | ||
if (index >= polyominoesCopy.length) { | ||
console.log("Pavage Réussi!"); | ||
return; | ||
} | ||
|
||
const polyomino = polyominoesCopy[index]; | ||
const originalColor = polyomino.color; // Sauvegarde de la couleur d'origine | ||
polyomino.color = '#FFFF99'; // Couleur jaune fade pour montrer la selection | ||
redraw(); | ||
|
||
setTimeout(() => { | ||
let placed = false; | ||
|
||
for (let row = 0; row < gridBoard.rows && !placed; row++) { | ||
for (let col = 0; col < gridBoard.cols && !placed; col++) { | ||
const originalX = polyomino.x; | ||
const originalY = polyomino.y; | ||
polyomino.x = col * gridBoard.gridSize + gridBoard.gridOffsetX; | ||
polyomino.y = row * gridBoard.gridSize + gridBoard.gridOffsetY; | ||
|
||
if (gridBoard.isInBounds(polyomino) && !gridBoard.isOverlapping(polyomino)) { | ||
placePolyomino(polyomino); | ||
placed = true; | ||
} else { | ||
polyomino.x = originalX; | ||
polyomino.y = originalY; | ||
} | ||
} | ||
} | ||
|
||
// On remet la couleur d'origine | ||
polyomino.color = originalColor; | ||
redraw(); | ||
|
||
if (placed) { | ||
index++; | ||
setTimeout(placeNextPolyomino, 1000); //Appel rzcursif avec un delai d'une seconde | ||
} else { | ||
console.log("Pavage Échoué!"); | ||
} | ||
}, 1000); // Delai une seconde pour montrer la selection avant le placement | ||
} | ||
|
||
placeNextPolyomino(); | ||
} | ||
const polyominoesCopy = [...polyominoes]; // Clone des polyominos pour ne pas les modifier | ||
polyominoesCopy.sort((a, b) => b.shape.flat().reduce((acc, val) => acc + val) - a.shape.flat().reduce((acc, val) => acc + val)); // trie par taille | ||
let index = 0; | ||
|
||
function placeNextPolyomino() { | ||
if (index >= polyominoesCopy.length) { | ||
console.log("Pavage Réussi!"); | ||
return; | ||
} | ||
|
||
const polyomino = polyominoesCopy[index]; | ||
const originalColor = polyomino.color; // Sauvegarde de la couleur d'origine | ||
polyomino.color = '#FFFF99'; // Couleur jaune fade pour montrer la selection | ||
redraw(); | ||
|
||
setTimeout(() => { | ||
let placed = false; | ||
|
||
for (let row = 0; row < gridBoard.rows && !placed; row++) { | ||
for (let col = 0; col < gridBoard.cols && !placed; col++) { | ||
const originalX = polyomino.x; | ||
const originalY = polyomino.y; | ||
polyomino.x = col * gridBoard.gridSize + gridBoard.gridOffsetX; | ||
polyomino.y = row * gridBoard.gridSize + gridBoard.gridOffsetY; | ||
|
||
if (gridBoard.isInBounds(polyomino) && !gridBoard.isOverlapping(polyomino)) { | ||
placePolyomino(polyomino); | ||
placed = true; | ||
} else { | ||
polyomino.x = originalX; | ||
polyomino.y = originalY; | ||
} | ||
} | ||
} | ||
|
||
// On remet la couleur d'origine | ||
polyomino.color = originalColor; | ||
redraw(); | ||
|
||
if (placed) { | ||
index++; | ||
setTimeout(placeNextPolyomino, 1000); //Appel rzcursif avec un delai d'une seconde | ||
} else { | ||
console.log("Pavage Échoué!"); | ||
} | ||
}, 1000); // Delai une seconde pour montrer la selection avant le placement | ||
}; | ||
|
||
placeNextPolyomino(); | ||
}; |
This file contains 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
This file contains 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
This file contains 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