Bonsoir à tous, je vous écris cette fois car ça fait des heures que je me casse la tête sans trouver la cause de mon problème.
Enfin la cause est identifié; mais je ne comprends pas pourquoi j'ai un tel comportement...peut être pourrez vous m’éclaircir.
Voici le main de test en question
Code:
1
2
3
4
5
6
7
8
9
10
11 Goban g=new Goban(9); String etatGoban=g.afficheGoban(); System.out.println(etatGoban); Intersection[] i= g.getPlateau(); System.out.println(i[1].getNbLiberteIntersection(g)); Rock r=new Rock("BLANC",0,0,g); i=g.setRockGoban(r,i); etatGoban=g.afficheGoban(); System.out.println(etatGoban); System.out.println(i[1].getNbLiberteIntersection(g));
Ce main va provoquer l'affichage suivant
L'intersection numéro 1 est donc celle correspondant à (1,2) à l'affichage.Citation:
1 2 3 4 5 6 7 8 9
1 . . . . . . . . .
2 . . . . . . . . .
3 . . . . . . . . .
4 . . . . . . . . .
5 . . . . . . . . .
6 . . . . . . . . .
7 . . . . . . . . .
8 . . . . . . . . .
9 . . . . . . . . .
0 Contient:.
2 Contient:.
10 Contient:.
3
1 2 3 4 5 6 7 8 9
1 O . . . . . . . .
2 . . . . . . . . .
3 . . . . . . . . .
4 . . . . . . . . .
5 . . . . . . . . .
6 . . . . . . . . .
7 . . . . . . . . .
8 . . . . . . . . .
9 . . . . . . . . .
0 Contient:.
2 Contient:.
10 Contient:.
3
Comme vous pouvez le voir au niveau de mon String d'état goban l'affichage est bien mis à jour; je met là l'intersection 0 (1,1) un "O".
A la suite du plateau; j'affiche le numéro des intersections à coté de l'intersection 1.
Soit l'intersection 0 à gauche et 3 à droite ainsi que 10 en bas.
Et ces intersection étant toutes libres j'affiche leur nombre soit 3.
Mais voilà...lorsque je remplace le . par le 0 dans l'intersection 0.
Je m'attendrais à ce que le second affichage me dise
Citation:
0 Contient:O
2 Contient:.
10 Contient:.
2
J'espère que vous serez en mesure de m'aider.
Voici un résumé des fonctions qui sont appelé.
Constructeur de Goban
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 public Goban(int taille){ int cpt=0; int currentRow; int currentColumn; this.size=taille; this.nbIntersection=taille*taille; this.plateau =new Intersection[taille*taille]; for(currentRow=0;currentRow<taille;currentRow++) { for(currentColumn=0;currentColumn<taille;currentColumn++) { this.plateau[cpt]=new Intersection(currentRow,currentColumn); cpt++; } } }
Constructeur de Rock
Constructeur d'intersectionCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 public Rock(String c,int r,int col,Goban g){ if(c=="BLANC") { this.couleur=c; this.symbole="O"; this.row=r; this.column=col; this.setNbliberteMax(g); this.numIntersection=getNumIntersection(g); } else { if(c=="NOIR") { this.couleur=c; this.symbole="X"; this.row=r; this.column=col; this.setNbliberteMax(g); this.numIntersection=getNumIntersection(g); } else { System.out.println("Attention instenciation d'une pierre invalide\n"); this.couleur="INVALIDE"; this.symbole="."; } } }
Maintenant les fonctions d'ajout en elle même dans GobanCode:
1
2
3
4
5
6
7 public Intersection(int l,int c){ this.row=l; this.column=c; this.empty=true; this.contenu="."; }
Code:
1
2
3 public Intersection[] getPlateau(){ return this.plateau; }
Et la fonction setRock d'intersectionCode:
1
2
3
4 public Intersection[] setRockGoban(Rock r,Intersection[] i){ i[r.getNumIntersection(this)].setRock(r,this); return i; }
Code:
1
2
3
4
5
6
7 public void setRock(Rock r,Goban g){ this.pierre=r; this.contenu=r.getSymbole(); this.empty=false; }
Le problème je l'ai identifié mais je ne vois pas sa source et je suis certain que j'ai un problème d'assignation avec mes tableau, je ne vois que ça....
Je rajoute également la fonction qui produit l'affichage du contenu des intersections même si je ne pense pas que le problème vienne de là.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14 public int getNbLiberteIntersection(Goban g){ int nbLib=0; int liberteMax=this.getNbIntersectionClose(g); Intersection tab[]=new Intersection[liberteMax]; tab=this.getIntersectionClose(g); for(int k=0;k<tab.length;k++){ System.out.println(tab[k].getNumIntersection(g)+" Contient:"+tab[k].getContenu()); if(tab[k].isEmpty()){ nbLib++; } } return nbLib; }
Merci pour votre aide, un désespéré :aie:
EDIT:
Problème résolu il m'aura fallu toute l'après midi pour le déboguer mais j'ai fini par trouver è_é
En réalité dans ma fonction qui retournait les intersection proches, je créais de nouvelles intersections au lieu de récupérer celles existantes...Bref comment perdre une journée pour une ligne de code x)