Exemplo n.º 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (words.m_collection.Count == 0) { words.CharCount = TrBgoodChar.Maximum = textBox1.Text.Count(); }
     if (textBox1.Text != "" && words.CharCount == textBox1.Text.Count())
     {
         richTextBox1.Text += textBox1.Text + '\n';
         cWord a = new cWord(textBox1.Text);
         words.m_collection.Add(a);
         refreshList(words.ConvertToString());
         textBox1.Text = "";
     }
     else if (words.CharCount != textBox1.Text.Count())
     {
         MessageBox.Show("invalid number of char in your word!\nA word must have " 
             + words.CharCount.ToString() 
             + " char.\nFor example: " 
             + words.m_collection.ElementAt(0).GetWord()
             + "."
             , "invalid input"
             , MessageBoxButtons.OK);
     }
     if (words.m_collection.Count != 0)
     {
         //GetWordsValue();
         comboBox1.SelectedItem = words.GetBestGuess().GetWord();
         TrBgoodChar.Enabled = true;
     }
     else
     {
         richTextBox1.Text = "";
     }
 }
Exemplo n.º 2
0
        public bool ChangeWordTo(cWord WordToChange, cWord ChangeToWord)
        {
            bool result = false;

            if (m_collection.Contains(WordToChange))
            {
                m_collection.Remove(WordToChange);
                m_collection.Add(ChangeToWord);
                result = true;
            }

            return result;
        }
Exemplo n.º 3
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>();
        }
Exemplo n.º 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (button2.Text == "test solution")
            {
                //get needed info from form controlls

                int value = TrBgoodChar.Value;
                richTextBox2.Text += '\n' + value.ToString();
                //words.Remove(textBox2.Text);
                cWord word = new cWord();
                if ((string)comboBox1.SelectedItem == null)
                {
                    word.SetWord(comboBox1.Text);
                }
                else
                {
                    word.SetWord( (string)comboBox1.SelectedItem);
                }

                words.AppendSearch(word, value);

                /*
                if (words.Contains(word))
                {
                    words.Remove(word);
                }

                //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 = word.Select(c => c).ToList();
                List<string> corr = new List<string>();
                corr = words.ToList<string>();

                //check every word in m_collection

                foreach (string i in words)
                {
                    //get char list from word to check and create bool list to find the good charsin good places
                    List<char> CheckWord = i.Select(c => c).ToList();
                    List<bool> correction = 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

                    foreach (char t in InputWord)
                    {
                        //correction.Add(ab.Contains(t));
                        correction.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 (correction.FindAll(v => v == true).Count == value)
                    {

                    }

                    // if not word does not qualify than word is removes from m_collection

                    else
                    {
                        corr.Remove(i);
                    }
                }

                //appended list is merged with original list.

                words.Clear();
                words = corr.ToList<string>();

                //char values are redetermined

                letters2.Clear();
                foreach (string i in words)
                {
                    foreach (char t in i)
                    {
                        letters2.Add(t);
                    }
                }

                //word values are redetermined

                GetWordsValue();

                */

                //combobox is updated

                refreshList(words.ConvertToString());
            }

            //only used to change a word
            else if (button2.Text == "append word")
            {
                //word is removed and the mew one is added at the end of the list(arengment is of no concern.
                cWord WordToChange = new cWord((string)comboBox1.SelectedItem);
                cWord ChangeToWord = new cWord(textBox2.Text);

                words.ChangeWordTo(WordToChange, ChangeToWord);

                /*
                words.Remove(word);
                textBox1.Text = textBox2.Text;
                button1.PerformClick();
                letters2.Clear();
                foreach (string i in words)
                {
                    foreach (char t in i)
                    {
                        letters2.Add(t);
                    }
                }
                */
                
                refreshList(words.ConvertToString());
            }
        }
Exemplo n.º 5
0
        public cWord GetBestGuess()
        {
            cWord result = new cWord();

            List<int> wordValues = GetWordValues();
            result = m_collection.ElementAt(wordValues.FindIndex(c => c == wordValues.Max()));

            return result;
        }