|
|
@ -136,276 +136,6 @@ void findPlayerPieces(const SGameState* state, const EPlayer color, int pieces[1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void voisins(int idCase, int * voisinsCase) |
|
|
|
{ |
|
|
|
idCase ++; |
|
|
|
|
|
|
|
int const nbCasesParLignes[17] = {1,2,3,4,13,12,11,10,9,10,11,12,13,4,3,2,1}; //Optimisable car symetrique |
|
|
|
int const Maxlignes[17] = {1,3,6,10,23,35,46,56,65,75,86,98,111,115,118,120,121}; //stockage des max de chaque ligne |
|
|
|
int const Minlignes[17] = {1,2,4,7,11,24,36,47,57,66,76,87,99,112,116,119,121}; //stockage des max de chaque ligne |
|
|
|
|
|
|
|
int ligne = 0,i=0; |
|
|
|
int somme = 0; |
|
|
|
|
|
|
|
do |
|
|
|
{ |
|
|
|
somme += nbCasesParLignes[ligne++]; |
|
|
|
} |
|
|
|
while( somme < idCase ); |
|
|
|
|
|
|
|
ligne=ligne-1; |
|
|
|
|
|
|
|
double rat=0; |
|
|
|
int ecart; |
|
|
|
|
|
|
|
voisinsCase[0]=idCase+1; |
|
|
|
voisinsCase[3]=idCase-1; |
|
|
|
|
|
|
|
rat=(((double)idCase-(double)Minlignes[ligne])/((double)Maxlignes[ligne]-(double)Minlignes[ligne]))*(double)nbCasesParLignes[ligne+1]; |
|
|
|
voisinsCase[1]=Minlignes[ligne+1]+rat; |
|
|
|
voisinsCase[2]=voisinsCase[1]-1; |
|
|
|
|
|
|
|
/***************gauche haut*************/ |
|
|
|
if((24<= idCase && idCase <30 ) ||(36<= idCase && idCase <41 ) ||(47<= idCase && idCase <52 ) ) |
|
|
|
{ |
|
|
|
rat=(((double)idCase-(double)Minlignes[ligne])/((double)Maxlignes[ligne]-(double)Minlignes[ligne]))*(double)nbCasesParLignes[ligne-1]; |
|
|
|
if((rat-(int)rat<0.5)) |
|
|
|
{ |
|
|
|
ecart=(int)rat; |
|
|
|
voisinsCase[4]=Minlignes[ligne-1]+ecart; |
|
|
|
voisinsCase[5]=voisinsCase[4]+1; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ecart=(int)rat+1; |
|
|
|
voisinsCase[5]=Minlignes[ligne-1]+ecart; |
|
|
|
voisinsCase[4]=voisinsCase[5]-1; |
|
|
|
} |
|
|
|
} |
|
|
|
if(idCase ==41 ) |
|
|
|
{ |
|
|
|
rat=(((double)idCase-(double)Minlignes[ligne])/((double)Maxlignes[ligne]-(double)Minlignes[ligne]))*(double)nbCasesParLignes[ligne-1]; |
|
|
|
ecart=(int)rat; |
|
|
|
voisinsCase[4]=Minlignes[ligne-1]+ecart-1; |
|
|
|
voisinsCase[5]=voisinsCase[4]+1; |
|
|
|
} |
|
|
|
|
|
|
|
if(15 <= idCase && idCase <=17) |
|
|
|
{ |
|
|
|
rat=(idCase-Minlignes[ligne])-4; |
|
|
|
voisinsCase[5]=Minlignes[ligne-1]+rat; |
|
|
|
voisinsCase[4]=voisinsCase[5]-1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(57<= idCase && idCase <=60)//ligne au milieu de letoile horizontallememnt |
|
|
|
{ |
|
|
|
rat=(((double)idCase-(double)Minlignes[ligne])/((double)Maxlignes[ligne]-(double)Minlignes[ligne]))*(double)nbCasesParLignes[ligne-1]; |
|
|
|
if((rat-(int)rat<0.5)) |
|
|
|
{ |
|
|
|
ecart=(int)rat; |
|
|
|
voisinsCase[4]=Minlignes[ligne-1]+ecart; |
|
|
|
voisinsCase[5]=voisinsCase[4]+1; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ecart=(int)rat+1; |
|
|
|
voisinsCase[5]=Minlignes[ligne-1]+ecart; |
|
|
|
voisinsCase[4]=voisinsCase[5]-1; |
|
|
|
} |
|
|
|
|
|
|
|
rat=(((double)idCase-(double)Minlignes[ligne])/((double)Maxlignes[ligne]-(double)Minlignes[ligne]))*(double)nbCasesParLignes[ligne+1]; |
|
|
|
if((rat-(int)rat<0.5)) |
|
|
|
{ |
|
|
|
ecart=(int)rat; |
|
|
|
voisinsCase[2]=Minlignes[ligne+1]+ecart; |
|
|
|
voisinsCase[1]=voisinsCase[2]+1; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ecart=(int)rat+1; |
|
|
|
voisinsCase[1]=Minlignes[ligne+1]+ecart; |
|
|
|
voisinsCase[2]=voisinsCase[1]-1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(idCase ==61 )//noyeau de letoile |
|
|
|
{ |
|
|
|
rat=(((double)idCase-(double)Minlignes[ligne])/((double)Maxlignes[ligne]-(double)Minlignes[ligne]))*(double)nbCasesParLignes[ligne-1]; |
|
|
|
ecart=(int)rat; |
|
|
|
voisinsCase[4]=Minlignes[ligne-1]+ecart-1; |
|
|
|
voisinsCase[5]=voisinsCase[4]+1; |
|
|
|
} |
|
|
|
|
|
|
|
/***************droite haut**************/ |
|
|
|
if((30<= idCase && idCase <36 ) ||(41< idCase && idCase <47 ) ||(52<= idCase && idCase <57 ) ||(62<= idCase && idCase <=65)) |
|
|
|
{ |
|
|
|
rat=(((double)idCase-(double)Minlignes[ligne])/((double)Maxlignes[ligne]-(double)Minlignes[ligne]))*(double)nbCasesParLignes[ligne-1]; |
|
|
|
if( rat-(int)rat==0.0) |
|
|
|
{ |
|
|
|
ecart=(int)rat-1; |
|
|
|
voisinsCase[5]=Minlignes[ligne-1]+ecart; |
|
|
|
voisinsCase[4]=voisinsCase[5]-1; |
|
|
|
} |
|
|
|
|
|
|
|
else if(rat-(int)rat>0.5) |
|
|
|
{ |
|
|
|
ecart=(int)rat; |
|
|
|
voisinsCase[5]=Minlignes[ligne-1]+ecart; |
|
|
|
voisinsCase[4]=voisinsCase[5]-1; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ecart=(int)rat-1; |
|
|
|
voisinsCase[4]=Minlignes[ligne-1]+ecart; |
|
|
|
voisinsCase[5]=voisinsCase[4]+1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(18<= idCase && idCase <20) |
|
|
|
{ |
|
|
|
ecart=((idCase-Minlignes[ligne])-4); |
|
|
|
voisinsCase[5]=Minlignes[ligne-1]+ecart; |
|
|
|
voisinsCase[4]=voisinsCase[5]-1; |
|
|
|
} |
|
|
|
|
|
|
|
/************droite bas*******************/ |
|
|
|
if((71 <= idCase && idCase <76) ||(82<= idCase && idCase <87) ||(93<= idCase && idCase <99 ) ||(106<= idCase && idCase <112 )) |
|
|
|
{ |
|
|
|
rat=(((double)idCase-(double)Minlignes[ligne])/((double)Maxlignes[ligne]-(double)Minlignes[ligne]))*(double)nbCasesParLignes[ligne-1]; |
|
|
|
voisinsCase[5]=Minlignes[ligne-1]+rat; |
|
|
|
voisinsCase[4]=voisinsCase[5]-1; |
|
|
|
|
|
|
|
ecart=(int)rat; |
|
|
|
voisinsCase[2]=Minlignes[ligne+1]+rat; |
|
|
|
voisinsCase[1]=voisinsCase[2]+1; |
|
|
|
} |
|
|
|
|
|
|
|
if(105< idCase && idCase <=107) |
|
|
|
{ |
|
|
|
rat=(Maxlignes[ligne]-idCase)-4; |
|
|
|
voisinsCase[1]=Maxlignes[ligne+1]-rat+1; |
|
|
|
voisinsCase[2]=voisinsCase[1]-1; |
|
|
|
} |
|
|
|
|
|
|
|
//*****************gauche bas ******************// |
|
|
|
if((66<= idCase && idCase <70) ||(76<= idCase && idCase <81) ||(87<= idCase && idCase <92) ||(99<= idCase && idCase <103 ) ||(103<= idCase && idCase <=105)) |
|
|
|
{ |
|
|
|
rat=(((double)idCase-(double)Minlignes[ligne])/((double)Maxlignes[ligne]-(double)Minlignes[ligne]))*(double)nbCasesParLignes[ligne+1]; |
|
|
|
if((rat-(int)rat<0.5)) |
|
|
|
{ |
|
|
|
ecart=(int)rat; |
|
|
|
voisinsCase[2]=Minlignes[ligne+1]+ecart; |
|
|
|
voisinsCase[1]=voisinsCase[2]+1; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ecart=(int)rat+1; |
|
|
|
voisinsCase[1]=Minlignes[ligne+1]+ecart; |
|
|
|
voisinsCase[2]=voisinsCase[1]-1; |
|
|
|
} |
|
|
|
|
|
|
|
rat=(((double)idCase-(double)Minlignes[ligne])/((double)Maxlignes[ligne]-(double)Minlignes[ligne]))*(double)nbCasesParLignes[ligne-1]; |
|
|
|
voisinsCase[5]=Minlignes[ligne-1]+rat; |
|
|
|
voisinsCase[4]=voisinsCase[5]-1; |
|
|
|
} |
|
|
|
|
|
|
|
if(idCase ==81) |
|
|
|
{ |
|
|
|
rat=(((double)idCase-(double)Minlignes[ligne])/((double)Maxlignes[ligne]-(double)Minlignes[ligne]))*(double)nbCasesParLignes[ligne+1]; |
|
|
|
ecart=(int)rat; |
|
|
|
voisinsCase[5]=Minlignes[ligne-1]+rat-1; |
|
|
|
voisinsCase[4]=voisinsCase[5]-1; |
|
|
|
} |
|
|
|
|
|
|
|
if(103<= idCase && idCase <=105) |
|
|
|
{ |
|
|
|
rat=(idCase-Minlignes[ligne])-4; |
|
|
|
voisinsCase[1]=Minlignes[ligne+1]+rat; |
|
|
|
voisinsCase[2]=voisinsCase[1]-1; |
|
|
|
} |
|
|
|
//************ailes droite-gauche bas***************************/ |
|
|
|
|
|
|
|
if((99<= idCase && idCase <103) || (108<= idCase && idCase <=111) )//cas special |
|
|
|
{ |
|
|
|
voisinsCase[2]=-1; |
|
|
|
voisinsCase[1]=-1; |
|
|
|
} |
|
|
|
/******************aile droite-gauche haut***********************/ |
|
|
|
|
|
|
|
if((11<= idCase && idCase <=14) || (20<= idCase && idCase <=23) )//cas special |
|
|
|
{ |
|
|
|
voisinsCase[4]=-1; |
|
|
|
voisinsCase[5]=-1; |
|
|
|
} |
|
|
|
/*****************aile plus-bas*******************************/ |
|
|
|
|
|
|
|
if(116<= idCase && idCase <=121) |
|
|
|
{ |
|
|
|
rat=idCase-Minlignes[ligne]; |
|
|
|
// printf ("rat %d\n", idCase-Minlignes[ligne]); |
|
|
|
voisinsCase[4]=Minlignes[ligne-1]+rat; |
|
|
|
voisinsCase[5]=voisinsCase[4]+1; |
|
|
|
} |
|
|
|
if(112<= idCase && idCase <=115) |
|
|
|
{ |
|
|
|
ecart=idCase-Minlignes[ligne]; |
|
|
|
rat=ecart+4; |
|
|
|
// printf ("rat %d\n", idCase-Minlignes[ligne]); |
|
|
|
voisinsCase[4]=Minlignes[ligne-1]+rat; |
|
|
|
voisinsCase[5]=voisinsCase[4]+1; |
|
|
|
} |
|
|
|
|
|
|
|
/*****************aile plus-haut*******************************/ |
|
|
|
|
|
|
|
if(1<= idCase && idCase <=10) |
|
|
|
{ |
|
|
|
rat=idCase-Minlignes[ligne]-1; |
|
|
|
// printf ("rat %d\n", idCase-Minlignes[ligne]); |
|
|
|
voisinsCase[4]=Minlignes[ligne-1]+rat; |
|
|
|
voisinsCase[5]=voisinsCase[4]+1; |
|
|
|
|
|
|
|
voisinsCase[2]=Minlignes[ligne+1]+rat+1; |
|
|
|
voisinsCase[1]=voisinsCase[2]+1; |
|
|
|
} |
|
|
|
|
|
|
|
if(7<= idCase && idCase <=10) |
|
|
|
{ |
|
|
|
ecart=idCase-Minlignes[ligne]; |
|
|
|
rat=ecart+4; |
|
|
|
// printf ("rat %d\n", idCase-Minlignes[ligne]); |
|
|
|
voisinsCase[2]=Minlignes[ligne+1]+rat; |
|
|
|
voisinsCase[1]=voisinsCase[2]+1; |
|
|
|
} |
|
|
|
|
|
|
|
/**********************/ |
|
|
|
for(i = 0; i<6; i++) |
|
|
|
{ |
|
|
|
// printf ("v%d: %d\n", i, voisinsCase[i]); |
|
|
|
} |
|
|
|
|
|
|
|
if(!(voisinsCase[0] <=Maxlignes[ligne] && voisinsCase[0]>Maxlignes[ligne-1] )) |
|
|
|
voisinsCase[0]=-1; |
|
|
|
if(!(voisinsCase[3] <=Maxlignes[ligne] && voisinsCase[3]>Maxlignes[ligne-1] )) |
|
|
|
voisinsCase[3]=-1; |
|
|
|
|
|
|
|
if(!(voisinsCase[1] <= Maxlignes[ligne+1] && voisinsCase[1] > Maxlignes[ligne] )) |
|
|
|
voisinsCase[1]=-1; |
|
|
|
if(!(voisinsCase[2] <= Maxlignes[ligne+1] && voisinsCase[2]>Maxlignes[ligne] )) |
|
|
|
voisinsCase[2]=-1; |
|
|
|
|
|
|
|
if(!(voisinsCase[4] <= Maxlignes[ligne-1] && voisinsCase[4]>Maxlignes[ligne-2] )) |
|
|
|
voisinsCase[4]=-1; |
|
|
|
if(!(voisinsCase[5] <= Maxlignes[ligne-1] && voisinsCase[5]>Maxlignes[ligne-2] )) |
|
|
|
voisinsCase[5]=-1; |
|
|
|
|
|
|
|
for (i=0; i<6; i++) |
|
|
|
{ |
|
|
|
if (voisinsCase[i] != -1) |
|
|
|
voisinsCase[i] --; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int getNeighbour(const int hole, Direction dir) |
|
|
|
{ |
|
|
|
int x,y; |
|
|
|