예제 #1
0
 public HorizontalWord(int l, PosMatrix p)
 {
     wordList        = new List <string>();
     numBackTracking = 0;
     lunParola       = l;
     pos             = p;
 }
예제 #2
0
        public bool CheckVerticalMatches(PosMatrix p, int lun, List <string> wordsUsed, List <string> wordsTried) // si controlla che da una parola si generino delle combinazioni accettabili
        {
            string startCaracters = "";
            int    row, r;

            for (int c = p.GetColumn(); c < p.GetColumn() + lun; c++) // per ogni colonna, calcolare i caratteri iniziali
            {
                r = p.GetRow();
                if (matrix[r, c].GetLunParola() > 1)
                {
                    startCaracters = "";
                    row            = matrix[r, c].GetPosMatrix().GetRow();
                    while (r >= 0 && r >= row)
                    {
                        startCaracters += matrix[r, c].GetLetter().ToString();
                        r--;
                    }

                    startCaracters = Reverse(startCaracters);                        // inverso della stringa dei caratteri iniziali

                    if (!w.ExistWord(matrix[row, c].GetLunParola(), startCaracters)) // se non esiste una parola che inizia con determinati caratteri speciali
                    {
                        wordsTried.Add(wordsUsed[wordsUsed.Count - 1]);              // parola aggiunta a quelle provate
                        wordsUsed.RemoveAt(wordsUsed.Count - 1);                     // parola rimossa da quelle usate
                        return(false);
                    }
                }
            }
            return(true);
        }
예제 #3
0
 public void RemoveWord(PosMatrix p, int lun) // rimozione della parola dalla matrice
 {
     for (int c = p.GetColumn(); c < p.GetColumn() + lun; c++)
     {
         matrix[p.GetRow(), c].Azzera();
     }
 }
예제 #4
0
        public bool LoadWord(PosMatrix p, int lunParolaBef, int lunParoleAft, List <string> wordsUsed, List <string> wordsTried)
        {
            string newWord  = w.GetWord(lunParolaBef, lunParoleAft, wordsTried, wordsUsed); // nuova parola da inserire
            int    startCol = p.GetColumn();

            if (newWord != "")              // se la parola non è nulla
            {
                wordsUsed.Add(newWord);     // si aggiunge la parola a quelle usate
                foreach (char c in newWord) // si aggiunge la parola alla matrice
                {
                    matrix[p.GetRow(), startCol].SetLetter(c);
                    startCol++;
                }
                // StampaMatrice();
                return(false); // backtracking risulta false
            }
            return(true);
        }