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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| import java.util.ArrayList;
public class Noeud {
int []tabia;
int []tabhm;
int scoreia,scorehm,profendeur;
String tour;
Noeud(){
}
Noeud(int []tabia,int []tabhm,int scoreia,int scorehm,int profendeur,String tour){
super();
this.tabhm=tabhm;
this.tabia=tabia;
this.scorehm=scorehm;
this.scoreia=scoreia;
this.profendeur=profendeur;
this.tour=tour;
ArrayList <Integer>parcour = new ArrayList<Integer>();
/**********************************************
******* Construction Liste de parcour *******
*********************************************/
if (this.tour.equals("hm")){
for (int hm : this.tabhm){
int i = new Integer(hm);
parcour.add(i);
}
int i = new Integer(this.scorehm);
parcour.add(i);
for (int ia : this.tabia){
int j = new Integer(ia);
parcour.add(j);
}
}
else {
for (int ia : this.tabia){
int i = new Integer(ia);
parcour.add(i);
}
int i = new Integer(this.scoreia);
parcour.add(i);
for (int hm : this.tabhm){
int j = new Integer(hm);
parcour.add(j);
}
}
/******************** Fin List ************************/
for (int it : parcour)System.out.print(" "+it);
System.out.println(" ");
/*****************************************************/
/****************** Génération des fils *************/
/***************************************************/
for(int it=0;it<6;it++){
/********** verifie Fin ********/
int sommeFin=0;
for(int tmp=0;tmp<6;tmp++)sommeFin=sommeFin+parcour.get(tmp);
/*******************************/
/*****Verifie Case n'est pas vide && Fin profendeur && Fin du jeu .Sinon Noeud Vide*******/
if(parcour.get(it)==0 || sommeFin==0 || this.profendeur==-1){
Noeud noeudFils=new Noeud();
}
else {
/************************************************************************************/
/**************Copie de la liste pour ne pas modifier les valeurs des fils*********/
ArrayList <Integer> parcourCopie= new ArrayList<Integer>();
for(int i=0;i<parcour.size();i++){
int loc=new Integer(parcour.get(i));
parcourCopie.add(loc);}
/***************************************************************************/
/***********************************************************************
*****************Distribution des grains ******************************/
int graineTmp=new Integer(parcourCopie.get(it));
parcourCopie.set(it,0);
int caseDepart=new Integer(it+1);
while(graineTmp>0){
for(int itLoc=caseDepart;itLoc<parcourCopie.size();itLoc++){
if(graineTmp>0){
int newValeur=new Integer((parcourCopie.get(itLoc)+1));
parcourCopie.set(itLoc,newValeur);
graineTmp--;
}
}
caseDepart=0;
}
/**************************************************************************/
/***********Récursiviter ***************************************/
for(int locP=0;locP<parcourCopie.size();locP++)System.out.print(" "+parcourCopie.get(locP));
System.out.println("");
/************************************************************/
/**************Reconstrution des plateaux *****************/
if (this.tour.equals("hm")){
int newTabhm[]=new int [6];
int newTabia[]=new int [6];
for(int locIn=0;locIn<6;locIn++)newTabhm[locIn]=parcourCopie.get(locIn);
int scoreHM=parcourCopie.get(6);
for(int locIn=7;locIn<parcourCopie.size()-1;locIn++)newTabia[locIn]=parcourCopie.get(locIn);
int scoreIA=parcourCopie.get((parcourCopie.size()-1));
new Noeud(newTabia,newTabhm,scoreIA,scoreHM,this.profendeur--,tour);
}
else{
int newTabhm[]=new int [6];
int newTabia[]=new int [6];
for(int locIn=0;locIn<6;locIn++)newTabia[locIn]=parcourCopie.get(locIn);
int scoreIA=parcourCopie.get(6);
for(int locIn=7;locIn<parcourCopie.size()-1;locIn++)newTabhm[locIn]=parcourCopie.get(locIn);
int scoreHM=parcourCopie.get((parcourCopie.size()-1));
new Noeud(newTabia,newTabhm,scoreIA,scoreHM,this.profendeur--,tour);
}
}
}
/**********profendeur doit reduire*********************/
// this.profendeur--;
}
}
// for (int itCopie : parcourCopie)System.out.print(" "+itCopie);
// System.out.println(" ");
/**************************************************************************
*
* System.out.println("Les Graines a distribuer (graineTmp): "+graineTmp);
*
* System.out.println("Case départ : "+caseDepart);
*
for (int itCopie : parcourCopie)System.out.print(" "+itCopie);
System.out.println(" ");*/ |
Partager