// A coroutine that finds words that can be spelled in this level public IEnumerator FindSubWordsCoroutine(WordLevel level) { level.subWords = new List <string>(); string str; List <string> words = WordList.S.GetWords(); // ^ This is very fast because List<string> is passed by reference // Iterate through all the words in the WordList for (int i = 0; i < WordList.S.wordCount; i++) { str = words[i]; // Check whether each one can be spelled using level.charDict if (WordLevel.CheckWordInLevel(str, level)) { level.subWords.Add(str); } // Yield if we've parsed a lot of words this frame if (i % WordList.S.numToParseBeforeYield == 0) { // yield until the next frame yield return(null); } } // List<string>.Sort() sorts alphabetically by default level.subWords.Sort(); // Now sort by length to have words grouped by number of letters level.subWords = SortWordsByLength(level.subWords).ToList(); // The coroutine is complete, so call SubWordSearchComplete() SubWordSearchComplete(); }
public IEnumerator FindSubWordsCoroutine(WordLevel level) { level.subWords = new List <string>(); string str; List <string> words = WordList.GET_WORDS(); for (int i = 0; i < WordList.WORD_COUNT; i++) { str = words[i]; if (WordLevel.CheckWordInLevel(str, level)) { level.subWords.Add(str); } if (i % WordList.NUM_TO_PARSE_BEFORE_YIELD == 0) { yield return(null); } } level.subWords.Sort(); level.subWords = SortWordsByLength(level.subWords).ToList(); SubWordSearchComplete(); }
public IEnumerator FindSubWordsCoroutine(WordLevel level) { level.subWords = new List <string> (); string str; List <string> words = WordList.S.GetWords(); for (int i = 0; i < WordList.S.wordCount; i++) { str = words [i]; if (WordLevel.CheckWordInLevel(str, level)) { level.subWords.Add(str); } if (i % WordList.S.numToParseBeforeYield == 0) { yield return(null); } } level.subWords.Sort(); level.subWords = SortWordsByLength(level.subWords).ToList(); SubWordSearchComplete(); }
// A coroutine that finds words that can be spelled in this level public IEnumerator FindSubWordsCoroutine(WordLevel level) { level.subWords = new List <string>(); string str; List <string> words = WordList.GET_WORDS(); // Iterate through all of the words in the wordList for (int i = 0; i < WordList.WORD_COUNT; i++) { str = words[i]; // Check whether each one can be spelled using level.charDict if (WordLevel.CheckWordInLevel(str, level)) { level.subWords.Add(str); } // Yield if we have parsed a lot of words this frame if (i % WordList.NUM_TO_PARSE_BEFORE_YIELD == 0) { // yield until the next frame yield return(null); } } level.subWords.Sort(); level.subWords = SortWordsByLength(level.subWords).ToList(); // The coroutine is complete, so call SubWordSearchComplete() SubWordSearchComplete(); }
public IEnumerator FindSubWordsCoroutine(WordLevel level) { level.subWords = new List <string>(); string str; List <string> words = WordList.S.GetWords(); // ^ работает быстро т.к. возвращает ссылку // Повторяем среди всех слов в списке for (int i = 0; i < WordList.S.wordCount; i++) { str = words[i]; // Проверяем может ли слово сделанно из букв if (WordLevel.CheckWordInLevel(str, level)) { level.subWords.Add(str); } // Уступаем если мы передали много слов в этот кадр if (i % WordList.S.numToParseBeforeYield == 0) { // Уступаем до следующего кадра yield return(null); } } // List<string>.Sort() сортирует по алфавиту level.subWords.Sort(); // Теперь сортируем по длинне level.subWords = SortWordsByLength(level.subWords).ToList(); // Сопроцесс окончен, вызываем SubWordSearchComplete() SubWordSearchComplete(); }
}//end of MakeWordLevel(int levelNum = -1) //a coroutine to find words that can be spelled in this level public IEnumerator FindSubWordsCoroutine(WordLevel level){ level.subWords = new List<string> (); string str; List<string> words = WordList.S.GetWords (); for (int i = 0; i < WordList.S.wordCount; i++) { str = words [i]; //can the word be spelled? if(WordLevel.CheckWordInLevel(str,level)) level.subWords.Add(str); if (i % WordList.S.numToParseBeforeYield == 0) yield return null; }//end of for loop //sort the list of words alphabetically level.subWords.Sort(); //now sort by length of word level.subWords = SortWordsByLength(level.subWords).ToList(); //now the coroutine is complete so call the function to let the system know SubWordSearchComplete(); }//end of FindSubWordsCoroutine(WordLevel level)