Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Viet281101 committed Jun 16, 2024
1 parent 4201a9c commit beff091
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
22 changes: 19 additions & 3 deletions 2D/js/ai.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Polyomino } from "./polyomino";

/**
* Performs backtracking auto tiling on a grid board using the given polyominoes.
*
* @param {Array} polyominoes - The array of polyominoes to be placed on the grid board.
* @param {Array<Polyomino>} polyominoes - The list of polyominoes to be placed on the grid board.
* @param {GridBoard} gridBoard - The grid board object representing the grid on which the polyominoes will be placed.
* @param {Function} placePolyomino - The function to place a polyomino on the grid board.
* @param {Function} removePolyomino - The function to remove a polyomino from the grid board.
Expand Down Expand Up @@ -56,7 +58,7 @@ export function backtrackingAutoTiling(polyominoes, gridBoard, placePolyomino, r
* Random tiling of polyominoes blocks to the grid board.
*
* @param {Object} gridBoard - The grid board object.
* @param {Array} polyominoes - The array of polyominoes.
* @param {Array<Polyomino>} polyominoes - The list of polyominoes.
* @param {Function} placePolyomino - The function to place a polyomino on the grid board.
* @param {Function} redraw - The function to redraw the grid board.
* @param {Function} [message] - An optional function to display a message.
Expand Down Expand Up @@ -171,7 +173,7 @@ export function bruteForceTiling(gridBoard, polyominoes, placePolyomino, redraw,
/**
* Random backtracking tiling for a given set of polyominoes on a grid board.
*
* @param {Array} polyominoes - The array of polyominoes to be placed on the grid board.
* @param {Array} polyominoes - The list of polyominoes to be placed on the grid board.
* @param {GridBoard} gridBoard - The grid board object representing the grid on which the polyominoes will be placed.
* @param {Function} placePolyomino - The function to place a polyomino on the grid board.
* @param {Function} removePolyomino - The function to remove a polyomino from the grid board.
Expand Down Expand Up @@ -253,6 +255,14 @@ export function randomBacktrackingTiling(polyominoes, gridBoard, placePolyomino,
* @return {void} This function does not return anything.
*/
export function fullAutoTiling(gridBoard, polyominoes, placePolyomino, removePolyomino, redraw, duplicatePolyomino, message) {
/**
* Determines if a polyomino can be placed at the specified coordinates on the grid board.
*
* @param {Polyomino} polyomino - The polyomino to be placed.
* @param {number} x - The x-coordinate to place the polyomino.
* @param {number} y - The y-coordinate to place the polyomino.
* @return {boolean} True if the polyomino can be placed, false otherwise.
*/
function canPlace(polyomino, x, y) {
const originalX = polyomino.x;
const originalY = polyomino.y;
Expand All @@ -268,6 +278,12 @@ export function fullAutoTiling(gridBoard, polyominoes, placePolyomino, removePol
return false;
};

/**
* Recursively places all polyominoes on the gridBoard starting from the given index.
*
* @param {number} index - The index of the polyomino to start placing.
* @return {boolean} Returns true if all polyominoes are placed successfully, false otherwise.
*/
function placeAllPolyominoes(index) {
if (index >= polyominoes.length) { return true; }
const polyomino = polyominoes[index];
Expand Down
3 changes: 2 additions & 1 deletion 2D/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ class MainApp {
case 2: messageBox.textContent = 'BRUTE FORCE TILING FINISHED'; break;
case 3: messageBox.textContent = 'RANDOM TILING FINISHED'; break;
case 4: messageBox.textContent = 'RANDOM BACKTRACKING TILING FINISHED'; break;
case 5: messageBox.textContent = 'FULL AUTOMATIC TILING FINISHED'; break;
default: messageBox.textContent = 'TILING FINISHED';
}
Object.assign(messageBox.style, { position: 'absolute', top: '20%', left: '50%', transform: 'translate(-50%, -50%)',
Expand Down Expand Up @@ -368,7 +369,7 @@ class MainApp {

fullAutoTiling() {
this.resetBoard();
const messageBox = this.createMessageBox(2);
const messageBox = this.createMessageBox(5);
setTimeout(() => { fullAutoTiling( this.gridBoard, this.polyominoes, this.placePolyomino.bind(this), this.gridBoard.removePolyomino.bind(this.gridBoard), this.redraw.bind(this), this.duplicatePolyomino.bind(this), () => { this.showMessageBox(messageBox); } ); }, 1000);
};
};
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Polyominoes Tiling in JS (Pavages de Polyominos en JavaScript)

In pure html, css and javascript with ES6 modules.
In pure html, css and javascript with ES6 modules, 2 libraries: [three.js](https://threejs.org/) and [dat.gui](https://github.com/dataarts/dat.gui).

## Description

Expand Down Expand Up @@ -30,9 +30,15 @@ Learn about the Polyominoes and give the solutions of tiling with one or several
- [Tiling with Pentominos](https://demonstrations.wolfram.com/TilingWithPentominos/)


## Authors (Auteurs):
## Authors (Auteurs)

| Name (Nom) | N° student | GitHub |
| -------- | ------- | ---------------------------------------- |
| Viet Nguyen | 20006303 | [Viet281101](https://github.com/Viet281101) |
| GEOFFROY Damien | 21007431 | [D-TheProgrammer](https://github.com/D-TheProgrammer) |


## Contribution

This is a study project, but if you want to contribute, please don't hesitate.
Be free to add the Issues, Pull Requests or new features in this repository.

0 comments on commit beff091

Please sign in to comment.