예제 #1
0
        private WordSet GetWordList()
        {
            //determine orientation of played tiles
            WordOrientation orientation;
            int lastWordIdx = mCurrentWord.Count - 1;
            int startX = mCurrentWord[0].X;
            int startY = mCurrentWord[0].Y;
            int endX = mCurrentWord[lastWordIdx].X;
            int endY = mCurrentWord[lastWordIdx].Y;

            if (mCurrentWord.Count == 1)
                orientation = WordOrientation.SINGLE_TILE;
            else if (startX != endX)
                orientation = WordOrientation.VERTICAL;
            else
                orientation = WordOrientation.HORIZONTAL;

            //Initialize word set
            WordSet wordSet = new WordSet(orientation);

            //for each letter in the proposed word, add the score of any new words generated by that letter
            foreach (LetterLoc letter in mCurrentWord)
            {
                //evaluate in X direction
                int initX = letter.X;
                int minX = initX;
                for (int i = initX; i >= 0; i--)
                {
                    if (mBoardLetters[i, letter.Y].IsEmptySpace())
                    {
                        break;
                    }
                    else
                    {
                        minX = i;
                    }
                }

                int maxX = initX;
                for (int i = initX; i < GameVals.BOARD_SIZE; i++)
                {
                    if (mBoardLetters[i, letter.Y].IsEmptySpace())
                    {
                        break;
                    }
                    else
                    {
                        maxX = i;
                    }
                }

                int wordLenX = maxX - minX + 1;
                if (wordLenX > 1)
                {
                    //get word
                    string word = "";
                    for (int i = minX; i <= maxX; i++)
                    {
                        word += mBoardLetters[i, letter.Y];
                    }

                    List<LetterLoc> letters = new List<LetterLoc>();
                    for (int i = minX; i <= maxX; i++)
                    {
                        letters.Add(mBoardLetters[i, letter.Y].GenLetterLoc(i, letter.Y));
                    }

                    if (orientation == WordOrientation.VERTICAL)
                        wordSet.PrimaryWord = new WordLocation(letters);
                    else
                        wordSet.AddIncidentalWord(new WordLocation(letters));
                }

                //evaluate in Y direction
                int initY = letter.Y;
                int minY = initY;
                for (int j = initY; j >= 0; j--)
                {
                    if (mBoardLetters[letter.X, j].IsEmptySpace())
                    {
                        break;
                    }
                    else
                    {
                        minY = j;
                    }
                }

                int maxY = initY;
                for (int j = initY; j < GameVals.BOARD_SIZE; j++)
                {
                    if (mBoardLetters[letter.X, j].IsEmptySpace())
                    {
                        break;
                    }
                    else
                    {
                        maxY = j;
                    }
                }

                int wordLenY = maxY - minY + 1;
                if (wordLenY > 1)
                {
                    //get word
                    List<LetterLoc> letters = new List<LetterLoc>();
                    for (int j = minY; j <= maxY; j++)
                    {
                        letters.Add(mBoardLetters[letter.X, j].GenLetterLoc(letter.X, j));
                    }

                    if (orientation == WordOrientation.HORIZONTAL)
                        wordSet.PrimaryWord = new WordLocation(letters);
                    else
                        wordSet.AddIncidentalWord(new WordLocation(letters));
                }
            }

            return wordSet;
        }
예제 #2
0
        private bool AreIncidentalWordsIllegal(HashSet<WordLocation> illegalWords, WordSet wordSet)
        {
            foreach(WordLocation illegalWord in illegalWords)
            {
                if (wordSet.IncidentalWords.Contains(illegalWord))
                {
                    return true;
                }
            }

            return false;
        }