예제 #1
0
 public static void ResetDisplayBoard()
 {
     CrosswordBoardMain.Instance().ResetBoard();
     CrosswordBoardPlacedWord.Instance().ResetBoard();
     CrosswordViewModel.Instance().AssignCrosswordDisplayBoard(CrosswordBoardMain.Instance().Board, CrosswordBoardPlacedWord.Instance().Board);
     CrosswordViewModel.Instance().Definitions.Clear();
 }
예제 #2
0
        // Itterates through board looking for potential letters where words can intersect
        private WordAndStartPositions FindWordAndPositions(int wordLength, WordDirection direction)
        {
            var startPosAttempts = 0;
            var word             = String.Empty;
            var usedWords        = new List <string>(_usedWords);
            var starPosList      = new List <Tuple <int, int> > {
            };
            var maxCounts        = 25;

            // Attempt to find start positions
            while (startPosAttempts < maxCounts)
            {
                word = RetrieveWord(usedWords, wordLength);

                var wordCharCount = 0;

                // Attemps cycling through letters
                while (wordCharCount < word.Length)
                {
                    var posList = CrosswordBoardMain.Instance().GetWordStartPositions(word, wordCharCount, direction);
                    starPosList.AddRange(posList);

                    wordCharCount++;
                }

                if (starPosList.Count > 0)
                {
                    break;
                }

                usedWords.Add(word);

                startPosAttempts++;
            }

            // Return null of no position found
            if (starPosList.Count == 0)
            {
                Debug.WriteLine("____________failed to find startPos");
                return(null);
            }

            var wordAndPosList = new WordAndStartPositions
            {
                StartPosList = new List <Tuple <int, int> >(starPosList),
                Word         = word
            };

            return(wordAndPosList);
        }
예제 #3
0
        public MainController()
        {
            // Grid size 10, MinWordsPlaced = 12
            // Grid size 12, MinWordsPlaced = 15
            // Grid size 14, MinWordsPlaced = 21
            // Grid size 16, MinWordsPlaced = 24

            GridSize       = 12;
            MinWordsPlaced = 15;


            CrosswordBoardMain.Instance().InitializeBoard(GridSize, GridSize, Char.MinValue);
            CrosswordBoardPlacedWord.Instance().InitializeBoard(GridSize, GridSize);
            CrosswordViewModel.Instance().InitializeDisplayBoard(GridSize, GridSize);
        }
예제 #4
0
        // Keeps trying to solve board until the _minWordsPlaced count is reached
        public void PlaceAllWords()
        {
            PlacedWords.Clear();
            _usedWords.Clear();
            _wordsPlaced = 0;
            _count       = 0;

            var solved = false;

            while (solved == false)
            {
                PlaceWords();

                if (_wordsPlaced >= MainController.MinWordsPlaced)
                {
                    solved = true;
                    break;
                }

                // Reset the board and start again if min word count in not met
                if (!solved)
                {
                    CrosswordBoardMain.Instance().ResetBoard();

                    _wordsPlaced = 0;
                    _usedWords   = new List <string>();
                    solved       = false;
                }
            }

            // Assign placed words location to each cell with a character (used for highlighting words)
            CrosswordBoardPlacedWord.Instance().AssignPlacedWords(PlacedWords);

            // Sort and find definition of placed words then apply formatting
            var SortedPlacedWords = _definitionSortingTools.SortPlacedWordsByPosition(PlacedWords);

            GroupedWords = _definitionSortingTools.GroupPlacedWords(SortedPlacedWords);

            var definitions = _definitionSortingTools.ReturnDefinitionArray(GroupedWords);

            Definitions = _definitionSortingTools.ApplyDefinitionHeadingFormatting(definitions);
        }
예제 #5
0
        // Place first word on board
        private void PlaceFirstWord()
        {
            var word = RetrieveWord(new List <string> {
            }, _wordSizes[0]);

            var random         = new Random();
            var horizontalPos  = random.Next(0, 1);
            var vertiacalPos   = random.Next(4, 6);
            var randomStartPos = new Tuple <int, int>(horizontalPos, vertiacalPos);

            // Place first word
            var placedWord = CrosswordBoardMain.Instance().PlaceWord(word, randomStartPos, WordDirection.Horizontal);

            if (placedWord != null)
            {
                PlacedWords.Add(placedWord);
            }
            else
            {
                Debug.WriteLine("IsNull");
            }
            _usedWords.Add(word);
        }
예제 #6
0
        // Try placing all words on board itterating through _wordSizes array for word sizes
        private void PlaceWords()
        {
            _count++;
            PlacedWords.Clear();

            // First Word
            PlaceFirstWord();

            // Rest of board
            var direction = WordDirection.Vertical;

            // Sequence through word size array
            for (var i = 1; i < _wordSizes.Length; i++)
            {
                var wordAndPosList = FindWordAndPositions(_wordSizes[i], direction);

                if (wordAndPosList != null)
                {
                    var startPositions = new List <Tuple <int, int> >(wordAndPosList.StartPosList);

                    var word = wordAndPosList.Word;

                    var usedCharsIndex = new List <int> {
                    };

                    if (startPositions.Count > 0)
                    {
                        var whileCount = 0;

                        // Try start positions until word placement is found
                        while (whileCount < startPositions.Count)
                        {
                            // Randomly itterate through start positions
                            var listIndex = ReturnRandomNumberExcludingArrayInts(startPositions.Count, usedCharsIndex);
                            usedCharsIndex.Add(listIndex);

                            var startPos = startPositions[listIndex];

                            var placedWord = CrosswordBoardMain.Instance().PlaceWord(word, startPos, direction);

                            if (placedWord != null)
                            {
                                _usedWords.Add(word);

                                if (direction == WordDirection.Horizontal)
                                {
                                    direction = WordDirection.Vertical;
                                }
                                else
                                {
                                    direction = WordDirection.Horizontal;
                                }

                                PlacedWords.Add(placedWord);

                                _wordsPlaced++;

                                // Break from while if wordcount reached
                                if (_wordsPlaced >= MainController.MinWordsPlaced)
                                {
                                    break;
                                }

                                break;
                            }

                            whileCount++;
                        }
                    }
                }
            }
        }