Merge branch 'main' of https://git.serveurtom.fr/Tom/24hducode
This commit is contained in:
@@ -24,6 +24,15 @@ class Noeud {
|
||||
getCheminsPossibles(){
|
||||
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;
|
||||
|
||||
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
|
||||
while(isObjectifTrouve()){
|
||||
currentNode = getCaseAnalysee();
|
||||
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
|
||||
|
||||
analyseEnvironnement(){
|
||||
currentNode = getCaseAnalysee();
|
||||
analyseEnvironnement(currentNode){
|
||||
currentNode.toString();
|
||||
|
||||
// SI case déjà visitée, alors on connait ses obstacles
|
||||
if (currentNode == null) {
|
||||
@@ -99,15 +114,17 @@ class ModeAutomatique {
|
||||
|
||||
//////////////////////////////////////// MOVE
|
||||
|
||||
move(){
|
||||
deplacer(currentNode){
|
||||
// on choisi le prochain noeud
|
||||
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
|
||||
updatePaths(nextNode);
|
||||
// on met à jour les coordonnées
|
||||
this.updateCoordonnees(nextNode);
|
||||
this.updateCoordonnees(currentNode, nextNode);
|
||||
// move
|
||||
this.move(nextNode);
|
||||
this.move();
|
||||
}
|
||||
|
||||
// parcours en profondeur : il s'agit de LIFOs
|
||||
@@ -117,6 +134,8 @@ class ModeAutomatique {
|
||||
cheminChoisi = this.cheminsPossibles[this.cheminsPossibles.length - 1];
|
||||
// on récupère le dernier élément de cette liste
|
||||
nodeChoisi = cheminChoisi[cheminChoisi.length - 1];
|
||||
log.console("noeud choisi :");
|
||||
nodeChoisi.toString();
|
||||
// on créé un nouveau noeud
|
||||
return new Noeud(nodeChoisi.posX, nodeChoisi.posY);
|
||||
}
|
||||
@@ -141,18 +160,30 @@ class ModeAutomatique {
|
||||
cheminsPossibles = cheminsPossibles.filter(function (el) {
|
||||
return el.length > 0;
|
||||
});
|
||||
log.console("nombre de chemins restants : " + this.cheminsPossibles.length)
|
||||
log.console("chemins possibles : " + this.cheminsPossibles)
|
||||
}
|
||||
|
||||
updateCoordonnees() {
|
||||
if(this.rotation = Orientation.HAUT){
|
||||
this.posX++;
|
||||
} else if(this.rotation = Orientation.BAS){
|
||||
this.posX--;
|
||||
}else if(this.rotation = Orientation.GAUCHE){
|
||||
updateCoordonnees(currentNode, nextNode) {
|
||||
log.console("coordonnees : (" + this.posX + "; " + this.posY + ")");
|
||||
if (currentNode.getX > nextNode.getX){
|
||||
this.rotation = Orientation.GAUCHE
|
||||
this.posY--;
|
||||
}else if(this.rotation = Orientation.DROITE){
|
||||
} else if (currentNode.getX < nextNode.getX){
|
||||
this.rotation = Orientation.DROITE
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user