Algo Aléatoire terminé - début algo intéligent

This commit is contained in:
fauvet 2023-04-27 21:19:45 +02:00
parent 47f29fcb63
commit f7c5974019
17 changed files with 538 additions and 42 deletions

View File

@ -1,5 +1,3 @@
import javax.swing.CellEditor;
public class Affichage {
private Cellules cetteCellules;
private PanneauModification cePanel;
@ -32,16 +30,17 @@ public class Affichage {
//System.out.println("Etat des deux valeur : " + this.caseEntrortie[0] + " "+ this.caseEntrortie[1]);
if(radio2Selected==true && this.caseEntrortie[0]==0){
this.cetEtat=ModificationsTab.LIBRE;
this.cetEtat=Cellules.LIBRE;
this.cetteCellules.setType(Cellules.ENTREE);
this.cetteCellules.peindre(Cellules.ENTREE);
this.caseEntrortie[0]=1;
} else if(radio3Selected==true && this.caseEntrortie[1]==0){
this.cetEtat=ModificationsTab.LIBRE;
this.cetEtat=Cellules.LIBRE;
this.cetteCellules.setType(Cellules.SORTIE);
this.cetteCellules.peindre(Cellules.SORTIE);
this.caseEntrortie[1]=1;
} else if(this.cetEtat == ModificationsTab.LIBRE && radio1Selected==true){
} else if(this.cetEtat == Cellules.LIBRE && radio1Selected==true){
//System.out.println("cellules peinte en couloir");
if(this.cetteCellules.getType()==Cellules.ENTREE){
this.caseEntrortie[0]=0;
} else if(this.cetteCellules.getType()==Cellules.SORTIE){
@ -49,7 +48,8 @@ public class Affichage {
}
this.cetteCellules.setType(Cellules.COULOIR);
this.cetteCellules.peindre(Cellules.COULOIR);
} else if(this.cetEtat == ModificationsTab.OCCUPE && radio1Selected==true){
} else if(this.cetEtat == Cellules.OCCUPE && radio1Selected==true){
//System.out.println("cellules peinte en mur");
this.cetteCellules.setType(Cellules.MUR);
this.cetteCellules.peindre(Cellules.MUR);
}

93
AlgoAlea.java Normal file
View File

@ -0,0 +1,93 @@
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class AlgoAlea {
private boolean[][] map;
private Cellules[][] grille;
private int cetteTaille;
private int comptErreur=0;
private int[] coordGate;
private These notreThese;
private JFrame cetteFrame;
public AlgoAlea(int uneTaille, boolean[][] tableau, Cellules[][] uneGrille, int visuel, JFrame uneFrame) {
this.map = tableau;
this.grille = uneGrille;
this.cetteFrame = uneFrame;
this.cetteTaille = uneTaille;
if(visuel==0){
this.auto();
} else if(visuel==1){
this.manuel();
}
}
/* ==================================== AUtomatique ==================================== */
public void auto() {
//outils.PrintGrilleBool(this.map,this.cetteTaille);
//outils.PrintGrilleCell(this.grille, this.cetteTaille);
int decompte = 0;
int[] tabRes = new int[1000];
Random ran = new Random();
int nxt=0;
while(decompte < 1000){
int compteur = 0;
this.coordGate = outils.ParcoursCell(this.grille, this.cetteTaille);
this.notreThese = new These(coordGate[0], coordGate[1], this.cetteTaille, this.map);
while(this.notreThese.isArrived(coordGate[2], coordGate[3]) != These.ARRIVE){
nxt = ran.nextInt(4);
if(nxt == 0){
this.notreThese.goRight();
} else if(nxt == 1){
this.notreThese.goDown();
} else if(nxt == 2){
this.notreThese.goLeft();
} else {
this.notreThese.goTop();
}
compteur+=1;
estInfini(compteur);
}
tabRes[decompte] = compteur;
decompte++;
}
JOptionPane.showMessageDialog(null, "Nous avons une moyenne de : "+outils.moyenneTabint(tabRes)+" pour ce labyrinthe", "Information", JOptionPane.INFORMATION_MESSAGE);
}
/* ==================================== Manuelle ==================================== */
public void manuel() {
this.coordGate = outils.ParcoursCell(this.grille, this.cetteTaille);
this.notreThese = new These(coordGate[0], coordGate[1], this.cetteTaille, this.map);
Attente attendre = new Attente(this.notreThese, this.grille, this.coordGate);
this.cetteFrame.addKeyListener(attendre);
}
/* ==================================== INFINI ==================================== */
public void estInfini(int unCompteur){
if(unCompteur > 10000){
this.comptErreur++;
}
if(this.comptErreur > 3){
JOptionPane.showMessageDialog(null, "Le labyrinthe est trop probablement non-finissable", "Erreur", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}
}

67
Attente.java Normal file
View File

@ -0,0 +1,67 @@
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;
import javax.swing.*;
import java.awt.*;
public class Attente implements KeyListener {
public static final boolean FINI = true;
public static final boolean ENCOURS = false;
private Random rand;
private int number;
private int compteur;
private These notreThese;
private Cellules[][] grilleCellules;
private int[] coordGate;
public Attente(These unPerso, Cellules[][] grille, int[] coord){
this.notreThese = unPerso;
this.grilleCellules = grille;
this.compteur=0;
this.rand = new Random();
this.coordGate = coord;
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
this.grilleCellules[notreThese.getCoord()[0]][notreThese.getCoord()[1]].peindre(Cellules.VUE);
this.number = this.rand.nextInt(4);
if(this.number == 0){
this.notreThese.goRight();
} else if(this.number == 1){
this.notreThese.goDown();
} else if(this.number == 2){
this.notreThese.goLeft();
} else {
this.notreThese.goTop();
}
this.grilleCellules[notreThese.getCoord()[0]][notreThese.getCoord()[1]].peindre(Cellules.DESSUS);
this.compteur++;
if(this.notreThese.isArrived(this.coordGate[2], this.coordGate[3]) == These.ARRIVE){
JOptionPane.showMessageDialog(null, "Labyrinthe treminé en "+this.compteur+" coups !", "Information", JOptionPane.INFORMATION_MESSAGE);
System.exit(1);
}
}
}
@Override
public void keyReleased(KeyEvent e) {
// Ne rien faire ici
}
@Override
public void keyTyped(KeyEvent e) {
// Ne rien faire ici
}
public void checked(){
System.out.println("true");
}
}

View File

@ -9,6 +9,12 @@ public class Cellules extends JComponent{
public static final int ENTREE=2;
public static final int SORTIE=3;
public static final int DESSUS=10;
public static final int VUE=11;
public static final boolean LIBRE = false;
public static final boolean OCCUPE = true;
private Color backgroundColor;
private int cetteLigne;
@ -58,6 +64,10 @@ public class Cellules extends JComponent{
backgroundColor = Color.BLUE;
} else if(peinture==SORTIE){
backgroundColor = Color.RED;
} else if(peinture==VUE){
backgroundColor = Color.YELLOW;
} else if(peinture==DESSUS){
backgroundColor = Color.ORANGE;
}
repaint();

View File

@ -1,7 +1,146 @@
import javax.swing.*;
import java.awt.*;
public class ChoixAlgo extends Fenetre {
public ChoixAlgo(boolean[][] uneGrille){
private JFrame frameGrille;
private boolean[][] ceTableau;
private Cellules[][] cetteGrille;
private int cetteTaille;
public ChoixAlgo(int uneTaille, JFrame fenGrille, boolean[][] uneGrille, Cellules[][] uneGrilleCell){
super();
outils.PrintGrilleBool(uneGrille, uneGrille.length);
this.fenetre.setVisible(true);
this.fenetre.setTitle("Algorithmes et visualisation");
this.ceTableau = uneGrille;
this.cetteGrille = uneGrilleCell;
this.frameGrille = fenGrille;
this.cetteTaille = uneTaille;
GridLayout gestionnaire = new GridLayout(6, 1);
this.fenetre.setLayout(gestionnaire);
}
public void setUp(){
/* ============================= TEXT PRESENTATION =========================*/
JLabel unText = new JLabel(" Etape 2 : Choix de l'Algorithme et de la Visualisation");
JPanel unPanel = new JPanel();
unPanel.setBackground(Color.CYAN);
unPanel.add(unText, BorderLayout.CENTER);
JPanel unPanel2 = new JPanel();
unPanel2.setBackground(Color.CYAN);
unPanel2.setLayout(new BoxLayout(unPanel2, BoxLayout.Y_AXIS));
unPanel2.add(Box.createVerticalGlue());
unPanel2.add(unPanel);
unPanel2.add(Box.createVerticalGlue());
this.fenetre.add(unPanel2, BorderLayout.CENTER);
/*============================ Choix de l'algo ============================*/
JLabel text0 = new JLabel("Choix de l'Algorithme");
JPanel cePanel0 = new JPanel();
cePanel0.setBackground(Color.CYAN);
cePanel0.add(text0, BorderLayout.CENTER);
JPanel cePanel1 = new JPanel();
cePanel1.setBackground(Color.CYAN);
cePanel1.setLayout(new BoxLayout(cePanel1, BoxLayout.Y_AXIS));
cePanel1.add(Box.createVerticalGlue());
cePanel1.add(cePanel0);
cePanel1.add(Box.createVerticalGlue());
this.fenetre.add(cePanel1, BorderLayout.CENTER);
/* ===== -_- ===== */
JPanel unPanel3 = new JPanel();
JPanel unPanel4 = new JPanel();
JRadioButton radioAA = new JRadioButton("Algorithme Aléatoire");
JRadioButton radioAD = new JRadioButton("Algorithme Déterminatif");
radioAA.setActionCommand("Aalea");
radioAD.setActionCommand("Adeter");
radioAA.setBackground(Color.CYAN);
radioAA.setSelected(true);
radioAD.setBackground(Color.CYAN);
ButtonGroup group = new ButtonGroup();
group.add(radioAA);group.add(radioAD);
unPanel4.add(radioAA);
unPanel4.add(radioAD);
unPanel3.setBackground(Color.CYAN);
unPanel3.setLayout(new BoxLayout(unPanel3, BoxLayout.Y_AXIS));
unPanel3.add(Box.createVerticalGlue());
unPanel3.add(unPanel4);
unPanel3.add(Box.createVerticalGlue());
unPanel3.setBackground(Color.CYAN);
unPanel4.setBackground(Color.CYAN);
this.fenetre.add(unPanel3, BorderLayout.CENTER);
/* ===== */
JLabel text1 = new JLabel(" Choix de la visualisation");
JPanel cePanel2 = new JPanel();
cePanel2.setBackground(Color.CYAN);
cePanel2.add(text1, BorderLayout.CENTER);
JPanel cePanel3 = new JPanel();
cePanel3.setBackground(Color.CYAN);
cePanel3.setLayout(new BoxLayout(cePanel3, BoxLayout.Y_AXIS));
cePanel3.add(Box.createVerticalGlue());
cePanel3.add(cePanel2);
cePanel3.add(Box.createVerticalGlue());
this.fenetre.add(cePanel3, BorderLayout.CENTER);
/*============================ Choix de la vue ============================*/
JPanel unPanel5 = new JPanel();
JPanel unPanel6 = new JPanel();
JRadioButton radioVA = new JRadioButton("Visualisation Automatique");
JRadioButton radioVD = new JRadioButton("Visualisation Manuelle");
radioVA.setActionCommand("Vauto");
radioVD.setActionCommand("Vman");
radioVA.setBackground(Color.CYAN);
radioVA.setSelected(true);
radioVD.setBackground(Color.CYAN);
ButtonGroup groupe = new ButtonGroup();
groupe.add(radioVA);groupe.add(radioVD);
unPanel6.add(radioVA);
unPanel6.add(radioVD);
unPanel5.setBackground(Color.CYAN);
unPanel5.setLayout(new BoxLayout(unPanel5, BoxLayout.Y_AXIS));
unPanel5.add(Box.createVerticalGlue());
unPanel5.add(unPanel6);
unPanel5.add(Box.createVerticalGlue());
unPanel5.setBackground(Color.CYAN);
unPanel6.setBackground(Color.CYAN);
this.fenetre.add(unPanel5, BorderLayout.CENTER);
/*Création du dernier panneau */
JPanel unPanel10 = new JPanel();
JButton unButton0 = new JButton("Suivant");
JPanel unPanel11 = new JPanel();
unPanel11.add(unButton0, BorderLayout.CENTER);
unPanel10.setBackground(Color.CYAN);
unPanel11.setBackground(Color.CYAN);
unPanel10.setBackground(Color.CYAN);
unPanel10.setLayout(new BoxLayout(unPanel10, BoxLayout.Y_AXIS));
unPanel10.add(Box.createVerticalGlue());
unPanel10.add(unPanel11);
unPanel10.add(Box.createVerticalGlue());
this.fenetre.add(unPanel10, BorderLayout.CENTER);
/* Evenement */
this.fenetre.setVisible(true);
GestionChoixAlgo gestion = new GestionChoixAlgo(this.cetteTaille, this.fenetre, group, groupe, this.ceTableau, this.cetteGrille ,this.frameGrille);
unButton0.addActionListener(gestion);
}
}

View File

@ -2,6 +2,7 @@ import java.awt.*;
public class FenetreImpGrille extends Fenetre {
private boolean[][] grille;
private Cellules[][] grilleCell;
public FenetreImpGrille(){
super();
@ -11,6 +12,7 @@ public class FenetreImpGrille extends Fenetre {
/* ================================================================ Déclaration des variables ============================================================================= */
int[][] ce_double_tab = new int[taille][taille];
this.grille = new boolean[taille][taille];
this.grilleCell = new Cellules[taille][taille];
//System.out.println("LA TAILLE DE LA GRRILLE VAUT : "+tabGrille.length);
/* =============================================================== Gestion des paramètres de la fenètre ========================================================================== */
@ -42,20 +44,25 @@ public class FenetreImpGrille extends Fenetre {
if((i*taille+j)==(Lentre*taille+Centre)){
Cellules cellules = new Cellules(i, j, Cellules.ENTREE);
this.grilleCell[i][j] = cellules;
this.fenetre.add(cellules);
} else if((i*taille+j)==(Lortie*taille+Cortie)){
Cellules cellules = new Cellules(i, j, Cellules.SORTIE);
this.grilleCell[i][j] = cellules;
this.fenetre.add(cellules);
} else if(ce_double_tab[i][j] == 1){
Cellules cellules = new Cellules(i, j, Cellules.MUR);
this.grilleCell[i][j] = cellules;
this.fenetre.add(cellules);
} else{
Cellules cellules = new Cellules(i, j, Cellules.COULOIR);
this.grilleCell[i][j] = cellules;
this.fenetre.add(cellules);
}
}
}
this.fenetre.setVisible(true);
outils.PrintGrilleBool(this.grille, taille);
ChoixAlgo Suite = new ChoixAlgo(taille, this.fenetre, this.grille, this.grilleCell);
Suite.setUp();
}
}

View File

@ -52,9 +52,9 @@ public class FenetreRndmGrille extends Fenetre{
int nombreAleatoire = rand.nextInt(2); // génère un nombre entre 0 et 2
if(nombreAleatoire == 0){
grille[i][j] = true;
grille[i][j] = Cellules.LIBRE; //true
} else {
grille[i][j] = false;
grille[i][j] = Cellules.OCCUPE; //false
}
this.modif = new Modifications(interfacePanel, grille,this.tabCouleur);
@ -65,7 +65,7 @@ public class FenetreRndmGrille extends Fenetre{
this.fenetre.add(cellules);
cellules.addMouseListener(modif);
grilleCellules[i][j] = cellules;
grille[i][j] = ModificationsTab.LIBRE;
grille[i][j] = Cellules.LIBRE;
}
else if(compteur == ValeurSortie)
{
@ -73,9 +73,9 @@ public class FenetreRndmGrille extends Fenetre{
this.fenetre.add(cellules);
cellules.addMouseListener(modif);
grilleCellules[i][j] = cellules;
grille[i][j] = ModificationsTab.LIBRE;
grille[i][j] = Cellules.LIBRE;
}
else if(grille[i][j] == true)
else if(grille[i][j] == Cellules.LIBRE)
{
Cellules cellules = new Cellules(i, j, Cellules.COULOIR);
this.fenetre.add(cellules);
@ -94,8 +94,6 @@ public class FenetreRndmGrille extends Fenetre{
compteur++;
}
}
outils.PrintGrilleBool(grille, taille);
this.fenetre.setVisible(true);
}
}

47
GestionChoixAlgo.java Normal file
View File

@ -0,0 +1,47 @@
import javax.swing.*;
import java.awt.event.*;
public class GestionChoixAlgo extends JFrame implements ActionListener {
private JFrame cetteFrame;
private ButtonGroup ceGroupe0;
private ButtonGroup ceGroupe1;
private int cetteTaille;
private JFrame frameGrille;
private boolean[][] cetteGrille;
private Cellules[][] cetteGrilleCell;
public GestionChoixAlgo(int uneTaille, JFrame uneFrame, ButtonGroup group0, ButtonGroup group1, boolean[][] uneGrille, Cellules[][] grilleCell,JFrame uneFenetre){
this.cetteFrame = uneFrame;
this.ceGroupe0 = group0;
this.ceGroupe1 = group1;
this.cetteTaille = uneTaille;
this.frameGrille=uneFenetre;
this.cetteGrille = uneGrille;
this.cetteGrilleCell=grilleCell;
}
public void actionPerformed(ActionEvent e){
this.cetteFrame.dispose();
if(this.ceGroupe0.getSelection().getActionCommand()=="Aalea" && this.ceGroupe1.getSelection().getActionCommand()=="Vauto")
{
this.frameGrille.dispose();
AlgoAlea algorithme = new AlgoAlea(this.cetteTaille, this.cetteGrille, this.cetteGrilleCell, 0, null);
}
else if(this.ceGroupe0.getSelection().getActionCommand()=="Adeter" && this.ceGroupe1.getSelection().getActionCommand()=="Vauto")
{
this.frameGrille.dispose();
}
else if(this.ceGroupe0.getSelection().getActionCommand()=="Aalea" && this.ceGroupe1.getSelection().getActionCommand()=="Vman")
{
AlgoAlea algorithme = new AlgoAlea(this.cetteTaille, this.cetteGrille, this.cetteGrilleCell, 1, this.frameGrille);
}
else if(this.ceGroupe0.getSelection().getActionCommand()=="Adeter" && this.ceGroupe1.getSelection().getActionCommand()=="Vman")
{
}
}
}

View File

@ -26,18 +26,20 @@ public class GestionExporter implements ActionListener{
public void actionPerformed(ActionEvent e){
this.cet_event=e.getActionCommand();
if (cet_event.equals(this.Reponses1)){
this.frameGrille.dispose();
this.frameModif.dispose();
this.framePopup.dispose();
//outils.PrintGrilleBool(this.cetteGrille, this.cetteTaille);
PreEcriture precriture = new PreEcriture(this.cetteGrille, this.grilleCellules, this.cetteTaille);
ChoixAlgo suite = new ChoixAlgo(this.cetteGrille);
ChoixAlgo suite = new ChoixAlgo(this.cetteTaille, this.frameGrille ,this.cetteGrille, this.grilleCellules);
suite.setUp();
}
else if (cet_event.equals(this.Reponses2)){
this.frameGrille.dispose();
this.frameModif.dispose();
this.framePopup.dispose();
ChoixAlgo suite = new ChoixAlgo(this.cetteGrille);
ChoixAlgo suite = new ChoixAlgo(this.cetteTaille, this.frameGrille, this.cetteGrille, this.grilleCellules);
suite.setUp();
}
}
}

View File

@ -27,6 +27,7 @@ public class GestionModif implements ActionListener{
}
else if (cet_event.equals(this.Reponses2)){
Exporter newExport = new Exporter(this.cetteGrille, this.grilleCellules, this.cetteTaille, this.cetteFrameGrille, this.cetteFrameModif);
//outils.PrintGrilleBool(this.cetteGrille, this.cetteTaille);
}
}
}

View File

@ -105,9 +105,9 @@ public class Lecture {
ceResultat = outils.concatenate(ceResultat, outils.reverse(ceTableauTemp));
}
for(int i=0; i<ceResultat.length; i++){
/*for(int i=0; i<ceResultat.length; i++){
System.out.print("le resultats vaut : "+ceResultat[i] +"\n");
}
}*/
/* =================================== Fermeture fichier ==================================== */

View File

@ -31,7 +31,7 @@ Lecture.class : Lecture.java outils.class
outils.class : outils.java
${JC} ${JCFLAGS} outils.java
FenetreImpGrille.class : FenetreImpGrille.java Cellules.class
FenetreImpGrille.class : FenetreImpGrille.java Cellules.class ChoixAlgo.class
${JC} ${JCFLAGS} FenetreImpGrille.java
### ========================================================================
@ -82,8 +82,21 @@ PreEcriture.class : PreEcriture.java Ecriture.class
Ecriture.class : Ecriture.java
${JC} ${JCFLAGS} Ecriture.java
ChoixAlgo.class : ChoixAlgo.java
ChoixAlgo.class : ChoixAlgo.java GestionChoixAlgo.class
${JC} ${JCFLAGS} ChoixAlgo.java
GestionChoixAlgo.class : GestionChoixAlgo.java AlgoAlea.class
${JC} ${JCFLAGS} GestionChoixAlgo.java
AlgoAlea.class : AlgoAlea.java These.class Attente.class
${JC} ${JCFLAGS} AlgoAlea.java
These.class : These.java
${JC} ${JCFLAGS} These.java
Attente.class : Attente.java
${JC} ${JCFLAGS} Attente.java
# ================================
### REGLES OPTIONNELLES ###

View File

@ -1,12 +1,6 @@
import java.awt.event.MouseEvent;
public class ModificationsTab {
// --------------------------------------------
public static final boolean LIBRE = true;
public static final boolean OCCUPE = false;
// --------------------------------------------
private boolean[][] cetteGrille;
private MouseEvent cetEvent;
@ -40,13 +34,13 @@ public class ModificationsTab {
/* ========================================= */
//System.out.println("Etat de la case avant cliqué : "+this.cetteGrille[this.cetteLigne][this.cetteColone]);
if(this.cetteGrille[this.cetteLigne][this.cetteColone] == OCCUPE){
this.cetteGrille[this.cetteLigne][this.cetteColone] = LIBRE;
if(this.cetteGrille[this.cetteLigne][this.cetteColone] == Cellules.OCCUPE){
this.cetteGrille[this.cetteLigne][this.cetteColone] = Cellules.LIBRE;
} else {
if(notreCellule.getType()==Cellules.ENTREE || notreCellule.getType()==Cellules.SORTIE){
this.cetteGrille[this.cetteLigne][this.cetteColone] = LIBRE;
this.cetteGrille[this.cetteLigne][this.cetteColone] = Cellules.LIBRE;
} else if (radio1Selected==true) {
this.cetteGrille[this.cetteLigne][this.cetteColone] = OCCUPE;
this.cetteGrille[this.cetteLigne][this.cetteColone] = Cellules.OCCUPE;
}
}

View File

@ -57,9 +57,9 @@ public class PreEcriture {
if(this.octetRemaining<8){
break;
}
if(cetteIteration==true){
if(cetteIteration==Cellules.LIBRE){
tempString = tempString + "0";
} else if(cetteIteration==false){
} else if(cetteIteration==Cellules.OCCUPE){
tempString = tempString + "1";
}
if(tempString.length()==8){
@ -73,9 +73,9 @@ public class PreEcriture {
if(decompte != tabHorizontal.length){
while(decompte != tabHorizontal.length){
if(tabHorizontal[decompte]==true){
if(tabHorizontal[decompte]==Cellules.LIBRE){
tempString=tempString+"0";
}else if(tabHorizontal[decompte]==false){
}else if(tabHorizontal[decompte]==Cellules.OCCUPE){
tempString=tempString+"1";
}
decompte++;
@ -85,9 +85,6 @@ public class PreEcriture {
this.tabTemp[compteur1] = tempString;
}
for(int i=0; i<tabTemp.length; i++){
System.out.println(tabTemp[i]+" ");
}

86
These.java Normal file
View File

@ -0,0 +1,86 @@
public class These {
public static final boolean LIBRE = false;
public static final boolean OCCUPE = true;
public static final boolean ARRIVE = true;
public static final boolean CHEMIN = false;
private int coordX;
private int coordY;
private int cetteTaille;
private boolean[][] cetteGrille;
public These(int x, int y, int taille, boolean[][] grille){
this.coordX = x;
this.coordY = y;
this.cetteGrille = grille;
this.cetteTaille = taille;
}
public boolean goRight(){
if(coordY+1 < this.cetteTaille){
//System.out.println("etat case droite :"+this.cetteGrille[coordX][coordY+1]+" pose :"+(coordX+1)+" "+coordY);
if(this.cetteGrille[coordX][coordY+1] == LIBRE){
this.coordY = this.coordY+1;
return true;
}
}
return false;
}
public boolean goDown(){
if(coordX+1 < this.cetteTaille){
if(this.cetteGrille[coordX+1][coordY] == LIBRE){
this.coordX = this.coordX+1;
return true;
}
}
return false;
}
public boolean goLeft(){
if(coordY-1 >= 0){
//System.out.println("etat case gauche :"+this.cetteGrille[coordX-1][coordY]+" pose :"+(coordX-1)+" "+coordY);
if(this.cetteGrille[coordX][coordY-1] == LIBRE){
this.coordY = this.coordY-1;
return true;
}
}
return false;
}
public boolean goTop(){
if(coordX-1 >= 0){
//System.out.println("etat case top : "+this.cetteGrille[coordX][coordY-1] +" pose : "+coordX+" "+(coordY-1));
if(this.cetteGrille[coordX-1][coordY] == LIBRE){
this.coordX = this.coordX-1;
return true;
}
}
return false;
}
// Gestion Fin
public boolean isArrived(int finalX, int finalY){
// renvoie un boolean
if(this.coordX == finalX && this.coordY == finalY){
return ARRIVE;
} else {
return CHEMIN;
}
}
// Miscelaneous
public void printPlacement(){
System.out.println("La position en X vaut : "+coordX+" et en y : "+coordY);
}
public int[] getCoord(){
int[] coordonnes = new int[2];
coordonnes[0] = coordX; coordonnes[1]=coordY;
return coordonnes;
}
}

View File

@ -107,4 +107,12 @@ public class outils {
}
return resultat;
}
public static int moyenneTabint(int[] leTableau){
int somme = 0;
for(int valeur : leTableau){
somme = somme + valeur;
}
return somme/leTableau.length;
}
}

34
save.txt Normal file
View File

@ -0,0 +1,34 @@
public void manuel() {
Random ran = new Random();
int nxt=0;
int compteur = 0;
Attente attendre = new Attente();
this.fenetre.requestFocus();
this.coordGate = outils.ParcoursCell(this.grille, this.cetteTaille);
this.notreThese = new These(coordGate[0], coordGate[1], this.cetteTaille, this.map);
while(this.notreThese.isArrived(coordGate[2], coordGate[3]) != These.ARRIVE){
Attente attendre = new Attente();
this.cetteFrame.addKeyListener(attendre);
/*nxt = ran.nextInt(4);
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);
compteur++;
estInfini(compteur);*/
}
}