Example #1
0
        public void AppendSearch(cWord WordTried, int GoodChars)
        {
            if (m_collection.Contains(WordTried))
            {
                m_collection.Remove(WordTried);
            }

            //get char list from word to check to and copy word list to append in

            //List<char> abc = textBox2.Text.Select(c => c).ToList();
            List<char> InputWord = WordTried.GetChars();

            List<cWord> cleanedWordList = new List<cWord>(m_collection.ToList());
            //cleanedWordList = m_collection.ToList();

            //check every word in m_collection

            foreach (cWord collWord in m_collection)
            {
                //get char list from word to check and create bool list to find the good charsin good places
                List<char> CheckWord = collWord.GetChars();
                List<bool> bMatchList = new List<bool>();
                int index = 0;

                //check which chars are on the same place. bool list will state true on index of match and false on index of non-match

                // compare InputWord with collWord
                foreach (char t in InputWord)
                {
                    //correction.Add(ab.Contains(t));
                    bMatchList.Add(CheckWord.ElementAt<char>(index) == t);
                    index++;
                }

                //if the amount of matched chars is the same as the correct value than word still qualifies.

                if (bMatchList.FindAll(v => v == true).Count != GoodChars)
                {
                    // if word does not qualify than word is removed from m_collection
                    cleanedWordList.Remove(collWord);
                }
            }

            // cleaned list is moved to the original list.
            m_collection.Clear();
            m_collection = cleanedWordList.ToList<cWord>();
        }