Merge branch 'main' of https://git.serveurtom.fr/Tom/24hducode
This commit is contained in:
@@ -24,6 +24,15 @@ class Noeud {
|
|||||||
getCheminsPossibles(){
|
getCheminsPossibles(){
|
||||||
return this.chemins;
|
return this.chemins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toString(){
|
||||||
|
log.console("node : (" + currentNode.getX + "; " + currentNode.getY + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
toStringWithVoisins(){
|
||||||
|
log.console("node : (" + currentNode.getX + "; " + currentNode.getY + ")");
|
||||||
|
log.console("voisins connus : " + this.chemins.forEach((chemin) => chemin.toString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -38,15 +47,21 @@ class ModeAutomatique {
|
|||||||
rotation=HAUT;
|
rotation=HAUT;
|
||||||
|
|
||||||
run(){
|
run(){
|
||||||
// TODO while find
|
while(isObjectifTrouve()){
|
||||||
this.analyseEnvironnement(); // met à jour ses connaissances (à dessiner au fur et à mesure ?)
|
currentNode = getCaseAnalysee();
|
||||||
this.move(); // récupère un chemin non encore parcourus en fonction de ses connaissances
|
this.analyseEnvironnement(currentNode); // met à jour ses connaissances (à dessiner au fur et à mesure ?)
|
||||||
|
this.deplacer(currentNode); // récupère un chemin non encore parcourus en fonction de ses connaissances
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isObjectifTrouve(){
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////// ANALYSE ENVIRONNEMENT
|
//////////////////////////////////////// ANALYSE ENVIRONNEMENT
|
||||||
|
|
||||||
analyseEnvironnement(){
|
analyseEnvironnement(currentNode){
|
||||||
currentNode = getCaseAnalysee();
|
currentNode.toString();
|
||||||
|
|
||||||
// SI case déjà visitée, alors on connait ses obstacles
|
// SI case déjà visitée, alors on connait ses obstacles
|
||||||
if (currentNode == null) {
|
if (currentNode == null) {
|
||||||
@@ -99,15 +114,17 @@ class ModeAutomatique {
|
|||||||
|
|
||||||
//////////////////////////////////////// MOVE
|
//////////////////////////////////////// MOVE
|
||||||
|
|
||||||
move(){
|
deplacer(currentNode){
|
||||||
// on choisi le prochain noeud
|
// on choisi le prochain noeud
|
||||||
nextNode = getNextNode();
|
nextNode = getNextNode();
|
||||||
|
log.console("next node : ");
|
||||||
|
nextNode.toString();
|
||||||
// on met à jour la liste des chemins en ajoutant le noeud courant dans les chemins non choisis
|
// on met à jour la liste des chemins en ajoutant le noeud courant dans les chemins non choisis
|
||||||
updatePaths(nextNode);
|
updatePaths(nextNode);
|
||||||
// on met à jour les coordonnées
|
// on met à jour les coordonnées
|
||||||
this.updateCoordonnees(nextNode);
|
this.updateCoordonnees(currentNode, nextNode);
|
||||||
// move
|
// move
|
||||||
this.move(nextNode);
|
this.move();
|
||||||
}
|
}
|
||||||
|
|
||||||
// parcours en profondeur : il s'agit de LIFOs
|
// parcours en profondeur : il s'agit de LIFOs
|
||||||
@@ -117,6 +134,8 @@ class ModeAutomatique {
|
|||||||
cheminChoisi = this.cheminsPossibles[this.cheminsPossibles.length - 1];
|
cheminChoisi = this.cheminsPossibles[this.cheminsPossibles.length - 1];
|
||||||
// on récupère le dernier élément de cette liste
|
// on récupère le dernier élément de cette liste
|
||||||
nodeChoisi = cheminChoisi[cheminChoisi.length - 1];
|
nodeChoisi = cheminChoisi[cheminChoisi.length - 1];
|
||||||
|
log.console("noeud choisi :");
|
||||||
|
nodeChoisi.toString();
|
||||||
// on créé un nouveau noeud
|
// on créé un nouveau noeud
|
||||||
return new Noeud(nodeChoisi.posX, nodeChoisi.posY);
|
return new Noeud(nodeChoisi.posX, nodeChoisi.posY);
|
||||||
}
|
}
|
||||||
@@ -141,18 +160,30 @@ class ModeAutomatique {
|
|||||||
cheminsPossibles = cheminsPossibles.filter(function (el) {
|
cheminsPossibles = cheminsPossibles.filter(function (el) {
|
||||||
return el.length > 0;
|
return el.length > 0;
|
||||||
});
|
});
|
||||||
|
log.console("nombre de chemins restants : " + this.cheminsPossibles.length)
|
||||||
|
log.console("chemins possibles : " + this.cheminsPossibles)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCoordonnees() {
|
updateCoordonnees(currentNode, nextNode) {
|
||||||
if(this.rotation = Orientation.HAUT){
|
log.console("coordonnees : (" + this.posX + "; " + this.posY + ")");
|
||||||
this.posX++;
|
if (currentNode.getX > nextNode.getX){
|
||||||
} else if(this.rotation = Orientation.BAS){
|
this.rotation = Orientation.GAUCHE
|
||||||
this.posX--;
|
|
||||||
}else if(this.rotation = Orientation.GAUCHE){
|
|
||||||
this.posY--;
|
this.posY--;
|
||||||
}else if(this.rotation = Orientation.DROITE){
|
} else if (currentNode.getX < nextNode.getX){
|
||||||
|
this.rotation = Orientation.DROITE
|
||||||
this.pos++;
|
this.pos++;
|
||||||
|
} else if (currentNode.getY > nextNode.getY){
|
||||||
|
this.rotation = Orientation.BAS
|
||||||
|
this.posX--;
|
||||||
|
} else {
|
||||||
|
this.rotation = Orientation.HAUT
|
||||||
|
this.posX++;
|
||||||
}
|
}
|
||||||
|
log.console("new coordonnees : (" + this.posX + "; " + this.posY + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
move(currentNode, nextNode){
|
||||||
|
// déplacer robot (les coordonnées sont déjà à jour)
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////// GETTERS
|
/////////////////////////////////////// GETTERS
|
||||||
|
|||||||
Reference in New Issue
Block a user