Example #1
0
        internal void LookDiagonally(Word word, int charIndex)
        {
            //ColumnCount 20, RowCount 10, charIndex 15, rowIndex 0, charactersAbove 0, charactersBelow 9
            int
                rowIndex = charIndex / ColumnCount,
                charactersAbove = rowIndex,
                charactersBelow = RowCount - rowIndex - 1,
                charactersToLeft = charIndex % ColumnCount,
                charactersToRight = ColumnCount - charactersToLeft - 1;

            if (charactersAbove >= word.LengthMinusOne)
            {
                if (charactersToRight >= word.LengthMinusOne && LookUpAndRight(word, charIndex))
                    if(FoundWords.Add(new BTLRFoundWord(word.Text, charIndex, this)))
                        return;
                if (charactersToLeft >= word.LengthMinusOne && LookUpAndLeft(word, charIndex))
                    if(FoundWords.Add(new BTRLFoundWord(word.Text, charIndex, this)))
                        return;
            }

            if (charactersBelow >= word.LengthMinusOne)
            {
                if (charactersToRight >= word.LengthMinusOne && LookDownAndRight(word, charIndex))
                    if(FoundWords.Add(new TBLRFoundWord(word.Text, charIndex, this)))
                        return;
                if (charactersToLeft >= word.LengthMinusOne && LookDownAndLeft(word, charIndex))
                    if(FoundWords.Add(new TBRLFoundWord(word.Text, charIndex, this)))
                        return;
            }
        }
Example #2
0
        internal bool LookDown(Word word, int charIndex)
        {
            char[] possibleWord = new char[word.Length];
            int startingRowIndex = charIndex / ColumnCount;

            for (int i = 0; i < word.Length; i++)
                possibleWord[i] = Characters[charIndex + ColumnCount * i];

            return ArrayEquals(possibleWord, word.Text.ToCharArray());
        }
Example #3
0
 internal void FindWord(Word word, int currentIndex)
 {
     LookHorizontally(word, currentIndex);
     LookVertically(word, currentIndex);
     LookDiagonally(word, currentIndex);
 }
Example #4
0
        internal void LookVertically(Word word, int charIndex)
        {
            //ColumnCount 20, RowCount 10, charIndex 15, rowIndex 0, charactersAbove 0, charactersBelow 9
            int
                rowIndex = charIndex / ColumnCount,
                charactersAbove = rowIndex,
                charactersBelow = RowCount - rowIndex - 1;

            if (charactersAbove >= word.LengthMinusOne && LookUp(word, charIndex))
                if (FoundWords.Add(new BTFoundWord(word.Text, charIndex, this)))
                    return;

            if (charactersBelow >= word.LengthMinusOne && LookDown(word, charIndex))
                if(FoundWords.Add(new TBFoundWord(word.Text, charIndex, this)))
                    return;
        }
Example #5
0
        internal bool LookToRight(Word word, int charIndex)
        {
            char[] possibleWord = new char[word.Length];

            for (int i = 0; i < possibleWord.Length; i++)
                possibleWord[i] = Characters[charIndex + i];

            return ArrayEquals(possibleWord, word.Text.ToCharArray());
        }
Example #6
0
        internal void LookHorizontally(Word word, int charIndex)
        {
            // ColumnCount 10, charIndex 5, char to left 5, char to right 4
            int
                charactersToLeft = charIndex % ColumnCount,
                charactersToRight = ColumnCount - charactersToLeft - 1;

            if (charactersToRight >= word.LengthMinusOne && LookToRight(word, charIndex))
                if(FoundWords.Add(new LRFoundWord(word.Text, charIndex, this)))
                    return;

            if (charactersToLeft >= word.LengthMinusOne && LookToLeft(word, charIndex))
                if(FoundWords.Add(new RLFoundWord(word.Text, charIndex, this)))
                    return;
        }