Пример #1
0
        public Chromosome Mutate(List <int> tp_sizes, int mut_times, BorderOptions borders)
        {
            Chromosome clone = this.Clone();
            int        times = Math.Max(0, this._random.Next(mut_times)) + 1;

            for (int i = 0; i < times; i++)
            {
                int         size            = tp_sizes[this._random.Next(tp_sizes.Count)];
                int         x               = clone._random.Next(clone._width - size + 1);
                int         y               = clone._random.Next(clone._height - size + 1);
                PatternList patterns        = clone._tpdict.GetTPArray(size);
                PatternList border_patterns = new PatternList();
                if (borders != null)
                {
                    if (borders["top"] && y == 0)
                    {
                        border_patterns.AddRange(clone._tpdict.GetTPBorderArray(size, "top"));
                    }
                    if (borders["bot"] && y == clone._height - size)
                    {
                        border_patterns.AddRange(clone._tpdict.GetTPBorderArray(size, "bot"));
                    }
                    if (borders["left"] && x == 0)
                    {
                        border_patterns.AddRange(clone._tpdict.GetTPBorderArray(size, "left"));
                    }
                    if (borders["right"] && x == clone._width - size)
                    {
                        border_patterns.AddRange(clone._tpdict.GetTPBorderArray(size, "right"));
                    }
                }
                if (border_patterns.Length > 0)
                {
                    patterns = border_patterns;
                }
                if (patterns.Length > 0)
                {
                    clone.ApplyTP(patterns.Sample(clone._random), x, y);
                    clone._calculated = false;
                }
            }
            return(clone);
        }
Пример #2
0
 public void RandomInitialize(List <int> tp_sizes, BorderOptions borders)
 {
     for (int y = 0; y < this._height; y++)
     {
         for (int x = 0; x < this._width; x++)
         {
             int size = tp_sizes[this._random.Next(tp_sizes.Count)];
             size = Math.Min(size, this._height - y);
             size = Math.Min(size, this._width - x);
             PatternList patterns        = this._tpdict.GetTPArray(size);
             PatternList border_patterns = new PatternList();
             if (borders != null)
             {
                 if (borders["top"] && y == 0)
                 {
                     border_patterns.AddRange(this._tpdict.GetTPBorderArray(size, "top"));
                 }
                 if (borders["bot"] && y == this._height - size)
                 {
                     border_patterns.AddRange(this._tpdict.GetTPBorderArray(size, "bot"));
                 }
                 if (borders["left"] && x == 0)
                 {
                     border_patterns.AddRange(this._tpdict.GetTPBorderArray(size, "left"));
                 }
                 if (borders["right"] && x == this._width - size)
                 {
                     border_patterns.AddRange(this._tpdict.GetTPBorderArray(size, "rigth"));
                 }
             }
             if (border_patterns.Length > 0)
             {
                 patterns = border_patterns;
             }
             if (patterns.Length > 0)
             {
                 this.ApplyTP(patterns.Sample(this._random), x, y);
             }
         }
     }
 }