Exemplo n.º 1
0
 public void SetAt(Point p, char c)
 {
     Entries[p] = c;
     if (char.IsLower(c) && char.IsLetter(c))
     {
         AllKeys.Add(c);
     }
     if (c == Start)
     {
         StartingPosition = p;
     }
 }
Exemplo n.º 2
0
        private void Mutation(string key)
        {
            Random rand = new Random(i++);
            int    a    = rand.Next(32);
            int    b    = rand.Next(33);

            StringBuilder newKeyBuilder = new StringBuilder(key);
            char          temp          = newKeyBuilder[a];

            newKeyBuilder[a] = newKeyBuilder[b];
            newKeyBuilder[b] = temp;
            string newKey = newKeyBuilder.ToString();

            if (!AllKeys.ContainsKey(newKey))
            {
                AllKeys.Add(newKey, 0.0);
            }
        }
Exemplo n.º 3
0
 public static void AddToList(KeySetting set)
 {
     if (AllKeys == null)
     {
         if (onAwake == null)
         {
             onAwake = () => { };
         }
         onAwake += () =>
         {
             AllKeys.Add(set);
             OnAdd(); //Was basically Instance.OnAdd();
         };
         return;
     }
     AllKeys.Add(set);
     OnAdd();
 }
Exemplo n.º 4
0
        private void Crossover(string parent1, string parent2)
        {
            Random rand = new Random(i++);

            int a = rand.Next(32);
            int b = rand.Next(a, 34);

            char[] child1 = parent1.ToCharArray();
            char[] child2 = parent2.ToCharArray();

            Dictionary <char, char> accordance1 = new Dictionary <char, char>();
            Dictionary <char, char> accordance2 = new Dictionary <char, char>();

            for (int i = a; i < b; i++)
            {
                child1[i] = parent2[i];
                child2[i] = parent1[i];
                accordance1.Add(parent1[i], parent2[i]);
                accordance2.Add(parent2[i], parent1[i]);
            }

            for (int i = 0; i < a; i++)
            {
                if (accordance1.ContainsKey(child1[i]))
                {
                    child1[i] = accordance1[child1[i]];
                }
                else if (accordance2.ContainsKey(child1[i]))
                {
                    child1[i] = accordance2[child1[i]];
                }

                if (accordance1.ContainsKey(child2[i]))
                {
                    child2[i] = accordance1[child2[i]];
                }
                else if (accordance2.ContainsKey(child2[i]))
                {
                    child2[i] = accordance2[child2[i]];
                }
            }

            for (int i = b; i < 33; i++)
            {
                if (accordance1.ContainsKey(child1[i]))
                {
                    child1[i] = accordance1[child1[i]];
                }
                else if (accordance2.ContainsKey(child1[i]))
                {
                    child1[i] = accordance2[child1[i]];
                }

                if (accordance1.ContainsKey(child2[i]))
                {
                    child2[i] = accordance1[child2[i]];
                }
                else if (accordance2.ContainsKey(child2[i]))
                {
                    child2[i] = accordance2[child2[i]];
                }
            }

            string child1str = new string(child1);
            string child2str = new string(child2);

            if (CheckKey(child1str))
            {
                if (!AllKeys.ContainsKey(child1str))
                {
                    AllKeys.Add(child1str, 0.0);
                }

                if (!AllKeys.ContainsKey(child2str))
                {
                    AllKeys.Add(child2str, 0.0);
                }
            }
        }