From 981f50ffc30804d462ce23b1560af35eb9a38367 Mon Sep 17 00:00:00 2001 From: maudulo Date: Sat, 22 Mar 2025 16:58:58 +0100 Subject: [PATCH 1/3] add algo --- algo.js | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 algo.js diff --git a/algo.js b/algo.js new file mode 100644 index 0000000..4a23bec --- /dev/null +++ b/algo.js @@ -0,0 +1,92 @@ +const Orientation = Object.freeze({ + HAUT: Symbol("haut"), + BAS: Symbol("bas"), + GAUCHE: Symbol("gauche"), + DROITE: Symbol("droite") +}); + + +class ModeAutomatique { + + casesParcourues = new Array(); + cheminsParcours = new Array(); + cheminsConnus = new Array(); + + + constructor(){ + // valeurs pour la première position + posX=0; + posY=0; + rotation=HAUT; + } + + run(){ + this.analyseEnvironnement(); // met à jour les obstacles + this.move(); // en fonction des chemins connus non encore parcourus + + //obstacle + if (!this.aBouge){ + // recule + // teste de 30 degrés + // tente d'avancer + // teste de 30 degrés + // tente d'avancer + // + } + } + + analyseEnvironnement(){ + if (isCaseAnalysee()) { + isObstacleDevant(); + tourne(); // + isObstacleDevant(); + tourne(); + isObstacleDevant(); + tourne(); + isObstacleDevant(); + tourne(); + } + + // SI case déjà visitée, alors on connait ses obstacles + } + + isCaseAnalysee(){ + // TODO + } + + updateCoordonnees() { + switch (this.rotation) { + case Orientation.HAUT: + + break; + case Orientation.BAS: + case Orientation.GAUCHE: + console.log("Mangoes and papayas are $2.79 a pound."); + // Expected output: "Mangoes and papayas are $2.79 a pound." + break; + case Orientation.DROITE: + console.log(`Sorry, we are out of ${expr}.`); + } + } + +} + +class Case { + coordX; + coordY; + chemins; + + constructor(coordX, coordY){ + this.coordX = coordX; + this.coordY = coordY; + chemins = new Array(); + } + + addCheminPossible(chemin){ + this.chemins.push(chemin) + } + + getCheminsPossibles(){ + return this.chemins + } +} \ No newline at end of file From 104e93936bb9b5be1ce36d759bc8d10837375e70 Mon Sep 17 00:00:00 2001 From: Jack Parrot Date: Sat, 22 Mar 2025 17:10:53 +0100 Subject: [PATCH 2/3] =?UTF-8?q?Cr=C3=A9ation=20bouton=20mode=20auto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/bootstrap-5.3.3-dist/css/bootstrap.css | 68 ++++++++++++++++++++++- ui/index.html | 6 +- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/ui/bootstrap-5.3.3-dist/css/bootstrap.css b/ui/bootstrap-5.3.3-dist/css/bootstrap.css index b7ab57f..0cc4521 100644 --- a/ui/bootstrap-5.3.3-dist/css/bootstrap.css +++ b/ui/bootstrap-5.3.3-dist/css/bootstrap.css @@ -2454,7 +2454,8 @@ textarea.form-control-lg { } .form-switch .form-check-input { --bs-form-switch-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='rgba%280, 0, 0, 0.25%29'/%3e%3c/svg%3e"); - width: 2em; + width: 4em; + height: 2em; margin-left: -2.5em; background-image: var(--bs-form-switch-bg); background-position: left center; @@ -12054,4 +12055,67 @@ textarea.form-control-lg { } } -/*# sourceMappingURL=bootstrap.css.map */ \ No newline at end of file +/*# sourceMappingURL=bootstrap.css.map */ + + /* The switch - the box around the slider */ + .switch { + position: relative; + display: inline-block; + width: 60px; + height: 34px; +} + +/* Hide default HTML checkbox */ +.switch input { + opacity: 0; + width: 0; + height: 0; +} + +/* The slider */ +.slider { + position: absolute; + cursor: pointer; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: #ccc; + -webkit-transition: .4s; + transition: .4s; +} + +.slider:before { + position: absolute; + content: ""; + height: 26px; + width: 26px; + left: 4px; + bottom: 4px; + background-color: white; + -webkit-transition: .4s; + transition: .4s; +} + +input:checked + .slider { + background-color: #2196F3; +} + +input:focus + .slider { + box-shadow: 0 0 1px #2196F3; +} + +input:checked + .slider:before { + -webkit-transform: translateX(26px); + -ms-transform: translateX(26px); + transform: translateX(26px); +} + +/* Rounded sliders */ +.slider.round { + border-radius: 34px; +} + +.slider.round:before { + border-radius: 50%; +} \ No newline at end of file diff --git a/ui/index.html b/ui/index.html index e9abe6f..039418b 100644 --- a/ui/index.html +++ b/ui/index.html @@ -27,7 +27,11 @@

Automatique

- +
+ + +
+ \ No newline at end of file From 8b7413b89b1c2f5608a7ac9dec8079ec22407c60 Mon Sep 17 00:00:00 2001 From: maudulo Date: Sat, 22 Mar 2025 19:04:02 +0100 Subject: [PATCH 3/3] update algo --- algo.js | 211 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 144 insertions(+), 67 deletions(-) diff --git a/algo.js b/algo.js index 4a23bec..8216873 100644 --- a/algo.js +++ b/algo.js @@ -6,72 +6,7 @@ const Orientation = Object.freeze({ }); -class ModeAutomatique { - - casesParcourues = new Array(); - cheminsParcours = new Array(); - cheminsConnus = new Array(); - - - constructor(){ - // valeurs pour la première position - posX=0; - posY=0; - rotation=HAUT; - } - - run(){ - this.analyseEnvironnement(); // met à jour les obstacles - this.move(); // en fonction des chemins connus non encore parcourus - - //obstacle - if (!this.aBouge){ - // recule - // teste de 30 degrés - // tente d'avancer - // teste de 30 degrés - // tente d'avancer - // - } - } - - analyseEnvironnement(){ - if (isCaseAnalysee()) { - isObstacleDevant(); - tourne(); // - isObstacleDevant(); - tourne(); - isObstacleDevant(); - tourne(); - isObstacleDevant(); - tourne(); - } - - // SI case déjà visitée, alors on connait ses obstacles - } - - isCaseAnalysee(){ - // TODO - } - - updateCoordonnees() { - switch (this.rotation) { - case Orientation.HAUT: - - break; - case Orientation.BAS: - case Orientation.GAUCHE: - console.log("Mangoes and papayas are $2.79 a pound."); - // Expected output: "Mangoes and papayas are $2.79 a pound." - break; - case Orientation.DROITE: - console.log(`Sorry, we are out of ${expr}.`); - } - } - -} - -class Case { +class Noeud { coordX; coordY; chemins; @@ -89,4 +24,146 @@ class Case { getCheminsPossibles(){ return this.chemins } -} \ No newline at end of file +} + + +class ModeAutomatique { + + cheminsPossibles = new Array(); // liste des listes de noeuds + noeudsVisites = new Array(); + + // valeurs pour la première position + posX=0; + posY=0; + rotation=HAUT; + + run(){ + // TODO while find + this.analyseEnvironnement(); // met à jour ses connaissances (à dessiner au fur et à mesure ?) + this.move(); // récupère un chemin non encore parcourus en fonction de ses connaissances + } + + //////////////////////////////////////// ANALYSE ENVIRONNEMENT + + analyseEnvironnement(){ + currentNode = getCaseAnalysee(); + + // SI case déjà visitée, alors on connait ses obstacles + if (currentNode == null) { + + // pour les 4 directions possibles + for (let i = 0; i < 4; i++) { + if (!isObstacleDevant(currentNode, rotation)){ + addCheminPossible(currentNode); + } + tourne(); // changement de l'angle de 90 degrés + } + this.noeudsVisites.push(currentNode); + } + } + + isObstacleDevant(){ + // TODO + return true; + } + + tourne(){ + if(this.rotation = Orientation.HAUT){ + // TODO tourne + this.rotation = Orientation.GAUCHE; + } else if(this.rotation = Orientation.BAS){ + // TODO tourne + this.rotation = Orientation.GAUCHE; + }else if(this.rotation = Orientation.BAS){ + // TODO tourne + this.rotation = Orientation.DROITE; + }else if(this.rotation = Orientation.DROITE){ + // TODO tourne + this.rotation = Orientation.HAUT; + } + } + + addCheminPossible(){ + chemin = new Array(); + if(this.rotation = Orientation.HAUT){ + chemin.push(new Noeud(posX+1, posY)); + } else if(this.rotation = Orientation.BAS){ + chemin.push(new Noeud(posX-1, posY)); + }else if(this.rotation = Orientation.GAUCHE){ + chemin.push(new Noeud(posX, posY-1)); + }else if(this.rotation = Orientation.DROITE){ + chemin.push(new Noeud(posX, posY+1)); + } + this.cheminsPossibles.push(chemin); + } + + //////////////////////////////////////// MOVE + + move(){ + // on choisi le prochain noeud + nextNode = getNextNode(); + // on met à jour la liste des chemins en ajoutant le noeud courant dans les chemins non choisis + updatePaths(nextNode); + // on met à jour les coordonnées + this.updateCoordonnees(nextNode); + // move + this.move(nextNode); + } + + // parcours en profondeur : il s'agit de LIFOs + getNextNode(){ + if (this.cheminsPossibles[this.cheminsPossibles.length - 1] > 0) { + // on récupère la dernière liste + cheminChoisi = this.cheminsPossibles[this.cheminsPossibles.length - 1]; + // on récupère le dernier élément de cette liste + nodeChoisi = cheminChoisi[cheminChoisi.length - 1]; + // on créé un nouveau noeud + return new Noeud(nodeChoisi.posX, nodeChoisi.posY); + } + return null; + } + + updatePaths(nextNode){ + nextNode = this.getCaseAnalysee(); + // on ajoute le noeud visité à toutes les listes sauf la dernière + for (let i=0; i < this.cheminsPossibles -1; i++){ + cheminPossible = this.cheminsPossibles[i]; + if (nextNode == null){ + // on ajoute le noeud en cours à la liste des noeuds visités + cheminPossible.push(nextNode); + } else { + // on vire le noeud visité de toutes les listes s'il a déjà été visité avant (on fait demi tour) + cheminPossible.pop(); + } + } + + // on supprime les listes vides + cheminsPossibles = cheminsPossibles.filter(function (el) { + return el.length > 0; + }); + } + + updateCoordonnees() { + if(this.rotation = Orientation.HAUT){ + this.posX++; + } else if(this.rotation = Orientation.BAS){ + this.posX--; + }else if(this.rotation = Orientation.GAUCHE){ + this.posY--; + }else if(this.rotation = Orientation.DROITE){ + this.pos++; + } + } + + /////////////////////////////////////// GETTERS + + getCaseAnalysee(){ + noeudsVisites.forEach((noeud) => { + if (noeud.posX == this.posX && noeud.posY == this.posY){ + return noeud; + } + }); + return null; + } +} +