Пример #1
0
        public void GraphDetour(object a_charCoOrd)
        {
            _pathOfword = new WordPath();
            var charCoOrd        = (CoOrd)a_charCoOrd;
            var allNeighborgoods = GetCellNeighborhoods((CoOrd)charCoOrd);

            _pathOfword.PushLetter(new LetterInWord(0, charCoOrd, _field[charCoOrd.x][charCoOrd.y], allNeighborgoods));
            Thread.Sleep(0);

            var status = _wordCheck.ContainsWordOrPart(_pathOfword.GetWord());

            if (status == WordCheck.SearchStatus.NotFound)
            {
                return;
            }

            var flag  = true;
            int level = 0;

            while (flag)
            {
                if (_pathOfword.HaveNeighborhood())
                {
                    _index++;
                    var nextStep = _pathOfword.GetAndPopNeighborhood();

                    allNeighborgoods = GetCellNeighborhoods(nextStep);

                    level++;
                    _pathOfword.PushLetter(new LetterInWord(level, nextStep, _field[nextStep.x][nextStep.y], allNeighborgoods));

                    //Console.WriteLine("Step > " + nextStep + " and word > " + _wordPath.GetWord());
                    var checkStatus = _wordCheck.ContainsWordOrPart(_pathOfword.GetWord());
                    if (checkStatus == WordCheck.SearchStatus.NotFound)  // нужна ограничение, если слово уже найдено. Данная проверка работает плохо...
                    {
                        while (_pathOfword.HaveNeighborhood())
                        {
                            nextStep = _pathOfword.GetAndPopNeighborhood();
                        }
                    }
                    else if (checkStatus == WordCheck.SearchStatus.FoundAWordAndParts ||
                             (checkStatus == WordCheck.SearchStatus.FoundAWord))
                    {
                        var tempWord = _pathOfword.GetWord();
                        if (!_allWords.Contains(tempWord))
                        {
                            _allWords.Add(tempWord);
                            Console.WriteLine(">>> Have a word: " + _allWords.Last());
                        }
                    }
                }
                else
                {
                    _pathOfword.PopLetter();
                    level--;
                    if (level == -1)
                    {
                        flag = false;
                    }
                }
            }

            Console.WriteLine(">>> Count of iterations: " + _index);

            return;
        }
Пример #2
0
        public void GraphDetour(object a_charCoOrd)
        {
            _pathOfword = new WordPath();
            var charCoOrd = (CoOrd)a_charCoOrd;
            var allNeighborgoods = GetCellNeighborhoods((CoOrd)charCoOrd);

            _pathOfword.PushLetter(new LetterInWord(0, charCoOrd, _field[charCoOrd.x][charCoOrd.y], allNeighborgoods));
            Thread.Sleep(0);

            var status = _wordCheck.ContainsWordOrPart(_pathOfword.GetWord());
            if (status == WordCheck.SearchStatus.NotFound)
            {
                return;
            }

            var flag = true;
            int level = 0;
            while (flag)
            {
                if (_pathOfword.HaveNeighborhood())
                {
                    _index++;
                    var nextStep = _pathOfword.GetAndPopNeighborhood();

                    allNeighborgoods = GetCellNeighborhoods(nextStep);

                    level++;
                    _pathOfword.PushLetter(new LetterInWord(level, nextStep, _field[nextStep.x][nextStep.y], allNeighborgoods));

                    //Console.WriteLine("Step > " + nextStep + " and word > " + _wordPath.GetWord());
                    var checkStatus = _wordCheck.ContainsWordOrPart(_pathOfword.GetWord());
                    if (checkStatus == WordCheck.SearchStatus.NotFound)  // нужна ограничение, если слово уже найдено. Данная проверка работает плохо...
                    {
                        while (_pathOfword.HaveNeighborhood())
                        {
                            nextStep = _pathOfword.GetAndPopNeighborhood();
                        }
                    }else if (checkStatus == WordCheck.SearchStatus.FoundAWordAndParts
                        || (checkStatus == WordCheck.SearchStatus.FoundAWord))
                    {
                        var tempWord = _pathOfword.GetWord();
                        if (!_allWords.Contains(tempWord))
                        {
                            _allWords.Add(tempWord);
                            Console.WriteLine(">>> Have a word: " + _allWords.Last());
                        }
                    }

                } else
                {
                    _pathOfword.PopLetter();
                    level--;
                    if (level == -1)
                    {
                        flag = false;
                    }
                }
            }

            Console.WriteLine(">>> Count of iterations: " + _index);

            return;
        }