/// <summary> /// retourne le nombre de mots possibles à jouer sur une ligne /// </summary> /// <param name="line">ligne concernée</param> /// <param name="letters">lettres du joueurs</param> /// <param name="sizes">tableau des tailles valables pour chaque mot</param> /// <param name="nbSizes">nombre de tailles valables</param> /// <param name="result">tableau de wordScrabble</param> /// <param name="position">position verticale ou horizontale</param> /// <param name="x">absscisse</param> /// <returns>nombre de mots possibles sur la ligne</returns> public static int findWordsWithLine(Structures.box [] line, char [] letters, valableSize [] sizes,int nbSizes, Structures.wordScrabble [] result,bool position, int x) { int nbResult=0; int nbJoker=0; for(int letter=0;letter<7;letter++) { if(letters[letter] == '?') { nbJoker++; } } for(int i = 0;i<nbSizes;i++) { for(int j=0;j<Structures.nbWords;j++) { bool [] tabJok = new bool [15]; int jok=nbJoker; if(sizes[i].max - sizes[i].min >= Structures.sizeWords[j]) { //calcul correspondance des lettres bool matchword=true; bool [] used = new bool [7]; bool [] used2 = new bool [15]; for(int k=0;k<Structures.sizeWords[j];k++) { bool found=false; for(int letter=0;letter<7;letter++) { if(letters[letter] == Structures.dictionary[j,k] && !used[letter] && !found) { used[letter]=true; found=true; } } if(!found) { for(int indice=sizes[i].min; indice < sizes[i].max+1;indice++) { if(line[indice].tok.value != 0 && line[indice].tok.letter == Structures.dictionary[j,k] && !used2[indice]) { found=true; used2[indice]=true; } } } if(!found && jok>0) { found=true; tabJok[k]=true; jok--; } if(!found){ matchword=false; break; } } if(matchword) { int firstIndice=-1; int lastIndice = 0; for(int t=sizes[i].min;t <= sizes[i].max;t++) { if(line[t].tok.value != 0) { if(firstIndice==-1) firstIndice=t; lastIndice = t; } } if(Structures.sizeWords[j] >= lastIndice - firstIndice +1) { bool correspond = true; for(int diff=0;diff <= (sizes[i].max - sizes[i].min ) - Structures.sizeWords[j]+1;diff++) { int everPosed=0; for(int indiceMask=0;indiceMask < Structures.sizeWords[j];indiceMask++) { if(line[sizes[i].min+indiceMask+diff].tok.value != 0) everPosed++; if(line[sizes[i].min+indiceMask+diff].tok.value != 0 && char.ToUpper(line[sizes[i].min+indiceMask+diff].tok.letter) != Structures.dictionary[j,indiceMask]) { correspond =false; } } if(correspond && sizes[i].min + Structures.sizeWords[j] + diff- 1 >= lastIndice && everPosed != Structures.sizeWords[j] && everPosed>0) { Structures.wordScrabble tmp; tmp.letters = new char [15]; for(int t=0;t<Structures.sizeWords[j];t++) { if(tabJok[t]) { tmp.letters[t] = char.ToLower(Structures.dictionary[j,t]); } else tmp.letters[t] = Structures.dictionary[j,t]; } if(position) { tmp.x = x; tmp.y= diff+sizes[i].min; } else { tmp.y = x; tmp.x=diff+sizes[i].min; } tmp.l=Structures.sizeWords[j]; tmp.position = position; result[nbResult]=tmp; nbResult++; } } } } } } } return nbResult; }
/// <summary> /// retourne le nombre de mots possibles à jouer sur une ligne en prenant compte des cases vides et à travers un appel de la fonction findWordsWithLine /// </summary> /// <param name="line">ligne concernée</param> /// <param name="letters">lettres du joueurs</param> /// <param name="nb">postion verticale ou horizontale</param> /// <param name="position">abscisse</param> /// <param name="Words">tableau de wordScrabble</param> /// <returns>appel de la fonction findWordsWithLine</returns> public static int searchWordByLine(Structures.box [] line,char [] letters, bool nb, int position,Structures.wordScrabble [] Words) { int i=0; int newleft=0; int lastleft=0; valableSize [] sizes = new valableSize [100]; int l=0; while(i < 14) { if(line[i].tok.value != 0) { do { i++; } while(line[i].tok.value != 0 && i < 14); valableSize tmp; tmp.min = lastleft; newleft=i+1; int j = i; int nbBlank = 0; while(j < 14 && nbBlank <= 7) { bool letterExist=false; while(line[j].tok.value == 0 && j < 14 && nbBlank <= 7) { nbBlank++; j++; } if(line[j].tok.value !=0) { tmp.max = j-2; } else { tmp.max = j-1; } sizes[l]=tmp; l++; while (line[j].tok.value != 0 && j < 14) { j++; letterExist = true; } } lastleft=newleft; } i++; } return findWordsWithLine(line,letters,sizes,l,Words,nb,position); }