Ejemplo n.º 1
0
        public void SetWordSolution(WordSolution solution)
        {
            if (this.InvokeRequired)
            {
                MethodInvoker del = delegate
                {
                    SetWordSolution(solution);
                };
                Invoke(del);
            }
            else
            {
                foreach (LetterLoc letter in solution.Letters)
                {
                    TextBox txtBox = mGameTextBoxes[letter.X, letter.Y];

                    txtBox.Text = letter.Letter.ToString() + (letter.IsBlankLetter ? "*" : "");
                    (txtBox.Tag as SpaceInfo).IsSolutionTile = true;

                    SetLocationColor(letter.X, letter.Y, Color.LightCoral);
                }
            }
        }
Ejemplo n.º 2
0
        private void _evaluateLetter(char letter, bool isBlankLetter, int letterIdx, int x, int y, List<WordSolution> solutions, int depth)
        {
            mBoardLetters[x, y] = new CharInfo(letter, isBlankLetter);

            LetterLoc curLetterLoc = new LetterLoc(letter, x, y, isBlankLetter);
            mCurrentWord.Add(curLetterLoc);
            mUsedLetterIdxs.Add(letterIdx);

            //get score of current turn
            WordSet wordSet = GetWordList();
            List<WordLocation> wordList = wordSet.GetFullList();
            HashSet<WordLocation> illegalWords;
            int score = GetWordScore(wordList, mCurrentWord, out illegalWords);
            if (score > 0)
            {
                //store this move as one that has scores
                LetterLoc[] letterArr = new LetterLoc[mCurrentWord.Count];
                mCurrentWord.CopyTo(letterArr);
                WordSolution solution = new WordSolution(letterArr, wordList, score);
                solutions.Add(solution);
            }

            //see if we should continue down this path
            if (score < 0
                && AreIncidentalWordsIllegal(illegalWords, wordSet))
            {
                //an incidental word is illegal.  Adding new tiles won't help with this so we are done
                clearCandidateLetterFromBoard(x, y, letterIdx, curLetterLoc);
                return;
            }
            else if (wordSet.PrimaryWord != null
                && mWordDict.IsDeadWord(wordSet.PrimaryWord.WordText))
            {
                //there are no words that contain our primary word, so stop
                clearCandidateLetterFromBoard(x, y, letterIdx, curLetterLoc);
                return;
            }

            //Look for next word
            if (wordSet.Orientation == WordOrientation.SINGLE_TILE)
            {
                //go in all 4 directions

                int y_next = NextTileUp(x, y);
                if (y_next >= 0)
                {
                    List<WordSolution> words = SolutionSearch(x, y_next, depth + 1);
                    solutions.AddRange(words);
                }

                y_next = NextTileDown(x, y);
                if (y_next >= 0)
                {
                    List<WordSolution> words = SolutionSearch(x, y_next, depth + 1);
                    solutions.AddRange(words);
                }

                int x_next = NextTileLeft(x, y);
                if (x_next >= 0)
                {
                    List<WordSolution> words = SolutionSearch(x_next, y, depth + 1);
                    solutions.AddRange(words);
                }

                x_next = NextTileRight(x, y);
                if (x_next >= 0)
                {
                    List<WordSolution> words = SolutionSearch(x_next, y, depth + 1);
                    solutions.AddRange(words);
                }
            }
            else if (wordSet.Orientation == WordOrientation.HORIZONTAL)
            {
                //go top and bottom
                int y_next = NextTileUp(x, y);
                if (y_next >= 0)
                {
                    List<WordSolution> words = SolutionSearch(x, y_next, depth + 1);
                    solutions.AddRange(words);
                }

                y_next = NextTileDown(x, y);
                if (y_next >= 0)
                {
                    List<WordSolution> words = SolutionSearch(x, y_next, depth + 1);
                    solutions.AddRange(words);
                }
            }
            else
            {
                //go left and right
                int x_next = NextTileLeft(x, y);
                if (x_next >= 0)
                {
                    List<WordSolution> words = SolutionSearch(x_next, y, depth + 1);
                    solutions.AddRange(words);
                }

                x_next = NextTileRight(x, y);
                if (x_next >= 0)
                {
                    List<WordSolution> words = SolutionSearch(x_next, y, depth + 1);
                    solutions.AddRange(words);
                }
            }

            //clear the location we are looking at
            clearCandidateLetterFromBoard(x, y, letterIdx, curLetterLoc);
        }