Пример #1
0
        public Puzzle GeneratePuzzleKey(Puzzle notYetCompletelyFilledPuzzle)
        {
            int iMax = notYetCompletelyFilledPuzzle.iMax;
            int jMax = notYetCompletelyFilledPuzzle.jMax;

            var wordList = notYetCompletelyFilledPuzzle.WordsInThePuzzleDesired;

            var wordsSuccessfullyFilled = new List <string>();

            int iMaxTrialForSameWord = 10000;

            foreach (var word in wordList)
            {
                int iTrialForSameWord = 0;

                bool wordNotFilled = true;

                while ((iTrialForSameWord < iMaxTrialForSameWord) && wordNotFilled)
                {
                    iTrialForSameWord++;

                    //Pick a random location
                    var location = HelpWithRandomPick.GetRandomLocation(iMax, jMax);

                    //Pick a random direction
                    DirectionInGrid direction  = new DirectionInGrid();
                    var             dirCounter = 0;
                    direction.SetToRandomDirection();

                    while ((dirCounter < 8) && wordNotFilled)
                    {
                        if (IsSpaceEnough(direction, location, word, notYetCompletelyFilledPuzzle))
                        {
                            if (TryFillingWord(direction, location, word, notYetCompletelyFilledPuzzle))
                            {
                                wordNotFilled = false;
                                notYetCompletelyFilledPuzzle.WordsInThePuzzleFilled.Add(word);
                                var puzzleSolutionWord = new PuzzleSolutionWord(word, direction, location);
                                notYetCompletelyFilledPuzzle.PuzzleSolutionSet.Add(word, puzzleSolutionWord);
                                continue; //done with direction switching
                            }
                            else
                            {
                                direction.SetToNextDirection();
                                dirCounter++;
                            }
                        }
                        else
                        {
                            direction.SetToNextDirection();
                            dirCounter++;
                        }
                    } //Keep trying for same word
                }
            }

            return(notYetCompletelyFilledPuzzle);
        }
Пример #2
0
        public Puzzle PadEmptyCells()
        {
            for (int i = 0; i < iMax; i++)
            {
                for (int j = 0; j < jMax; j++)
                {
                    if (PuzzleGrid[i, j] == ' ')
                    {
                        PuzzleGrid[i, j] = HelpWithRandomPick.GetRandomChar();
                    }
                }
            }

            return(this);
        }
Пример #3
0
 public void SetToRandomDirection()
 {
     Direction = HelpWithRandomPick.GetRandomDirection();
 }