Ajouts des algo deterministe - reste a retravailler certain points (regarde ton ardoise matthis)

This commit is contained in:
fauvet 2023-04-28 05:14:35 +02:00
parent 2d1ba67c4c
commit 879a69444c
9 changed files with 242 additions and 51 deletions

View File

@ -1,10 +1,8 @@
import java.util.Random; import java.util.Random;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
public class AlgoAlea { public class AlgoAlea {
private boolean[][] map; private boolean[][] map;
private Cellules[][] grille; private Cellules[][] grille;

41
AlgoDeter.java Normal file
View File

@ -0,0 +1,41 @@
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class AlgoDeter {
public static final int MUR = 1;
public static final int PARCOURU = 0;
private int[][] Parcours;
private boolean[][] map;
private Cellules[][] grille;
private int[] coordGate;
private int cetteTaille;
private int comptErreur=0;
private These notreThese;
private JFrame cetteFrame;
public AlgoDeter(int uneTaille, boolean[][] tableau, Cellules[][] uneGrille, JFrame uneFrame) {
this.cetteTaille = uneTaille;
this.map = tableau;
this.grille = uneGrille;
this.cetteFrame = uneFrame;
}
public void auto() {
int decompte = 0;
this.coordGate = outils.ParcoursCell(this.grille, this.cetteTaille);
//this.notreThese = new These(this.coordGate[0], this.coordGate[1], this.cetteTaille, this.map);
Parcours ceParcours = new Parcours(this.grille, this.coordGate[0], this.coordGate[1], this.cetteTaille);
}
public void manuel(){
this.coordGate = outils.ParcoursCell(this.grille, this.cetteTaille);
ParcoursManuel ceParcour = new ParcoursManuel(this.grille, this.coordGate[0], this.coordGate[1], this.cetteTaille);
}
}

View File

@ -35,6 +35,8 @@ public class GestionChoixAlgo extends JFrame implements ActionListener {
else if(this.ceGroupe0.getSelection().getActionCommand()=="Adeter" && this.ceGroupe1.getSelection().getActionCommand()=="Vauto") else if(this.ceGroupe0.getSelection().getActionCommand()=="Adeter" && this.ceGroupe1.getSelection().getActionCommand()=="Vauto")
{ {
this.frameGrille.dispose(); this.frameGrille.dispose();
AlgoDeter algorithme = new AlgoDeter(this.cetteTaille, this.cetteGrille, this.cetteGrilleCell, null);
algorithme.auto();
} }
else if(this.ceGroupe0.getSelection().getActionCommand()=="Aalea" && this.ceGroupe1.getSelection().getActionCommand()=="Vman") else if(this.ceGroupe0.getSelection().getActionCommand()=="Aalea" && this.ceGroupe1.getSelection().getActionCommand()=="Vman")
{ {
@ -43,7 +45,8 @@ public class GestionChoixAlgo extends JFrame implements ActionListener {
} }
else if(this.ceGroupe0.getSelection().getActionCommand()=="Adeter" && this.ceGroupe1.getSelection().getActionCommand()=="Vman") else if(this.ceGroupe0.getSelection().getActionCommand()=="Adeter" && this.ceGroupe1.getSelection().getActionCommand()=="Vman")
{ {
AlgoDeter algorithme = new AlgoDeter(this.cetteTaille, this.cetteGrille, this.cetteGrilleCell, null);
algorithme.manuel();
} }
} }
} }

View File

@ -85,7 +85,7 @@ Ecriture.class : Ecriture.java
ChoixAlgo.class : ChoixAlgo.java GestionChoixAlgo.class ChoixAlgo.class : ChoixAlgo.java GestionChoixAlgo.class
${JC} ${JCFLAGS} ChoixAlgo.java ${JC} ${JCFLAGS} ChoixAlgo.java
GestionChoixAlgo.class : GestionChoixAlgo.java AlgoAlea.class GestionChoixAlgo.class : GestionChoixAlgo.java AlgoAlea.class AlgoDeter.class
${JC} ${JCFLAGS} GestionChoixAlgo.java ${JC} ${JCFLAGS} GestionChoixAlgo.java
AlgoAlea.class : AlgoAlea.java These.class Attente.class AlgoAlea.class : AlgoAlea.java These.class Attente.class
@ -97,6 +97,15 @@ These.class : These.java
Attente.class : Attente.java Attente.class : Attente.java
${JC} ${JCFLAGS} Attente.java ${JC} ${JCFLAGS} Attente.java
AlgoDeter.class : AlgoDeter.java Parcours.class ParcoursManuel.class
${JC} ${JCFLAGS} AlgoDeter.java
Parcours.class : Parcours.java
${JC} ${JCFLAGS} Parcours.java
ParcoursManuel.class : ParcoursManuel.java
${JC} ${JCFLAGS} ParcoursManuel.java
# ================================ # ================================
### REGLES OPTIONNELLES ### ### REGLES OPTIONNELLES ###

51
Parcours.java Normal file
View File

@ -0,0 +1,51 @@
import javax.swing.JOptionPane;
public class Parcours {
private int taille;
private int ceCompteur = 0;
private Cellules[][] labyrinthe;
public Parcours(Cellules[][] tableau, int X, int Y, int len){
this.taille = len;
this.labyrinthe = tableau;
this.Parcourir(X, Y);
}
public boolean Parcourir(int coordX, int coordY){
boolean done = false;
if(estValide(coordX, coordY)) {
if (this.labyrinthe[coordX][coordY].getType() == Cellules.SORTIE){
JOptionPane.showMessageDialog(null, "Nous avons trouvé un chemin en "+(this.ceCompteur)+" coups pour ce labyrinthe", "Information", JOptionPane.INFORMATION_MESSAGE);
return true;
} else {
this.labyrinthe[coordX][coordY].setType(Cellules.MUR);
//Appels récursifs
if(done != true){
done = Parcourir(coordX + 1, coordY);
done = Parcourir(coordX, coordY + 1);
done = Parcourir(coordX - 1, coordY);
done = Parcourir(coordX, coordY - 1);
}
}
}
return done;
}
private boolean estValide(int pos_x, int pos_y) {
this.ceCompteur++;
boolean result = false;
//Si la case passée en paramètre est dans les dimensions du labyrinthe
if (pos_x >= 0 && pos_x < this.taille && pos_y >= 0 && pos_y < this.taille){
//Et si la case est un espace vide
if (this.labyrinthe[pos_x][pos_y].getType() == Cellules.COULOIR || this.labyrinthe[pos_x][pos_y].getType() == Cellules.ENTREE || this.labyrinthe[pos_x][pos_y].getType() == Cellules.SORTIE){
result = true;
}
}
return result;
} //Fin estValide()
}

58
ParcoursManuel.java Normal file
View File

@ -0,0 +1,58 @@
import javax.swing.JOptionPane;
public class ParcoursManuel {
private int taille;
private int ceCompteur = 0;
private Cellules[][] labyrinthe;
public ParcoursManuel(Cellules[][] tableau, int X, int Y, int len){
this.taille = len;
this.labyrinthe = tableau;
this.Parcourir(X, Y);
}
public boolean Parcourir(int coordX, int coordY){
boolean done = false;
if(estValide(coordX, coordY)) {
if (this.labyrinthe[coordX][coordY].getType() == Cellules.SORTIE){
JOptionPane.showMessageDialog(null, "Nous avons trouvé un chemin en "+this.ceCompteur+" coups pour ce labyrinthe", "Information", JOptionPane.INFORMATION_MESSAGE);
return true;
} else {
this.labyrinthe[coordX][coordY].setType(Cellules.MUR);
//Appels récursifs
if(done != true){
done = Parcourir(coordX + 1, coordY);
done = Parcourir(coordX, coordY + 1);
done = Parcourir(coordX - 1, coordY);
done = Parcourir(coordX, coordY - 1);
}
}
}
return done;
}
private boolean estValide(int pos_x, int pos_y) {
this.ceCompteur++;
boolean result = false;
//Si la case passée en paramètre est dans les dimensions du labyrinthe
if (pos_x >= 0 && pos_x < this.taille && pos_y >= 0 && pos_y < this.taille){
//Et si la case est un espace vide
if (this.labyrinthe[pos_x][pos_y].getType() != Cellules.SORTIE && this.labyrinthe[pos_x][pos_y].getType() != Cellules.MUR && this.labyrinthe[pos_x][pos_y].getType() != Cellules.ENTREE){
this.labyrinthe[pos_x][pos_y].peindre(Cellules.VUE);
}
if (this.labyrinthe[pos_x][pos_y].getType() == Cellules.COULOIR || this.labyrinthe[pos_x][pos_y].getType() == Cellules.ENTREE || this.labyrinthe[pos_x][pos_y].getType() == Cellules.SORTIE){
result = true;
}
if (this.labyrinthe[pos_x][pos_y].getType() != Cellules.SORTIE && this.labyrinthe[pos_x][pos_y].getType() != Cellules.MUR && this.labyrinthe[pos_x][pos_y].getType() != Cellules.ENTREE){
this.labyrinthe[pos_x][pos_y].peindre(Cellules.DESSUS);
}
}
return result;
} //Fin estValide()
}

View File

@ -1,15 +0,0 @@
public class Retournement {
private int[] ceTableau;
public Retournement(int[] unTableau){
this.ceTableau = unTableau;
}
public void setModifyTab(int emplacementTab, int emplacementGrille){
this.ceTableau[emplacementTab] = emplacementGrille;
}
public int[] getValeurPorte(){
return this.ceTableau;
}
}

View File

@ -61,6 +61,43 @@ public class These {
return false; return false;
} }
/* ======================== regarder ======================== */
public boolean debordementVerticaux(){
//renvoie true s'il y a débordement sinon false
if(coordY < 0 && coordY > this.cetteTaille){
return true;
}
return LIBRE;
}
public boolean lookBot(){
if(coordY+1 < this.cetteTaille){
if(this.cetteGrille[coordX+1][coordY] == OCCUPE){
return OCCUPE;
}
}
return LIBRE;
}
public boolean lookLeft(){
if(coordY+1 < this.cetteTaille){
if(this.cetteGrille[coordX][coordY-1] == OCCUPE){
return OCCUPE;
}
}
return LIBRE;
}
public boolean lookTop(){
if(coordY+1 < this.cetteTaille){
if(this.cetteGrille[coordX-1][coordY] == OCCUPE){
return OCCUPE;
}
}
return LIBRE;
}
// Gestion Fin // Gestion Fin
public boolean isArrived(int finalX, int finalY){ public boolean isArrived(int finalX, int finalY){

View File

@ -1,34 +1,43 @@
public void manuel() { import javax.swing.JOptionPane;
Random ran = new Random();
int nxt=0;
int compteur = 0;
Attente attendre = new Attente(); public class Parcours {
this.fenetre.requestFocus();
public boolean resolutionLab(int pos_x, int pos_y) {
boolean done = false;
this.coordGate = outils.ParcoursCell(this.grille, this.cetteTaille); //Si la fonction estValide() renvoie true
this.notreThese = new These(coordGate[0], coordGate[1], this.cetteTaille, this.map); if (estValide(pos_x, pos_y)) {
while(this.notreThese.isArrived(coordGate[2], coordGate[3]) != These.ARRIVE){ grille[pos_x][pos_y] = 3;
//Si la case passée en paramètre est la dernière case du labyrinthe
if (pos_x == grille.length-1 && pos_y == grille[0].length-1)
return true;
else {
//Appels récursifs
done = resolutionLab(pos_x + 1, pos_y);
if (!done)
done = resolutionLab(pos_x, pos_y + 1);
if (!done)
done = resolutionLab(pos_x - 1, pos_y);
if (!done)
done = resolutionLab(pos_x, pos_y - 1);
} if (done)
grille[pos_x][pos_y] = 7;
}
Attente attendre = new Attente(); return done;
this.cetteFrame.addKeyListener(attendre);
/*nxt = ran.nextInt(4); } //Fin resolutionLab()
if(nxt == 0){
this.notreThese.goRight();
} else if(nxt == 1){
this.notreThese.goDown();
} else if(nxt == 2){
this.notreThese.goLeft();
} else {
this.notreThese.goTop();
}
this.grille[notreThese.getCoord()[0]][notreThese.getCoord()[1]].peindre(Cellules.VUE); private boolean estValide(int pos_x, int pos_y) {x
boolean result = false;
//Si la case passée en paramètre est dans les dimensions du labyrinthe
if (pos_x >= 0 && pos_x < grille.length && pos_y >= 0 && pos_y < grille[0].length)
//Et si la case est un espace vide
if (grille[pos_x][pos_y] == 0)
result = true;
return result;
compteur++; } //Fin estValide()
estInfini(compteur);*/
} }
}