コード例 #1
0
ファイル: Chromosome.cs プロジェクト: OmarShehata/ETPKLDiv
        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
ファイル: Chromosome.cs プロジェクト: OmarShehata/ETPKLDiv
 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);
             }
         }
     }
 }
コード例 #3
0
 public void AddRange(PatternList list)
 {
     this._patterns.AddRange(list._patterns);
 }
コード例 #4
0
        public static Tuple <Dictionary <int, PatternCounts>, Dictionary <int, PatternList>, Dictionary <int, BorderPatternList> > CalculateTilePatternProbabilities(List <int[, ]> maps, List <int> tp_sizes, WarpOptions warp = null, BorderOptions borders = null)
        {
            Dictionary <int, PatternCounts>     p               = new Dictionary <int, PatternCounts>();
            Dictionary <int, PatternList>       patterns        = new Dictionary <int, PatternList>();
            Dictionary <int, BorderPatternList> border_patterns = new Dictionary <int, BorderPatternList>();

            foreach (int size in tp_sizes)
            {
                p[size]               = new PatternCounts();
                patterns[size]        = new PatternList();
                border_patterns[size] = new BorderPatternList();
                for (int i = 0; i < maps.Count; i++)
                {
                    int[,] map = maps[i];
                    int ySize = size;
                    if (warp != null && warp["y"])
                    {
                        ySize = 1;
                    }
                    for (int y = 0; y < map.GetLength(0) - ySize + 1; y++)
                    {
                        int xSize = size;
                        if (warp != null && warp["x"])
                        {
                            xSize = 1;
                        }
                        for (int x = 0; x < map.GetLength(1) - xSize + 1; x++)
                        {
                            Pattern pattern = CalculateTilePattern(map, x, y, size);

                            p[size].Add(pattern);

                            if (borders != null)
                            {
                                bool temp_border = false;
                                if (borders["top"] && y == 0)
                                {
                                    temp_border = true;
                                    border_patterns[size].Add("top", pattern);
                                }
                                if (borders["bot"] && y == map.GetLength(0) - size)
                                {
                                    temp_border = true;
                                    border_patterns[size].Add("bot", pattern);
                                }
                                if (borders["left"] && x == 0)
                                {
                                    temp_border = true;
                                    border_patterns[size].Add("left", pattern);
                                }
                                if (borders["right"] && x == map.GetLength(1) - size)
                                {
                                    temp_border = true;
                                    border_patterns[size].Add("right", pattern);
                                }
                                if (!temp_border)
                                {
                                    patterns[size].Add(pattern);
                                }
                            }
                            else
                            {
                                patterns[size].Add(pattern);
                            }
                        }
                    }
                }
            }
            return(Tuple.Create(p, patterns, border_patterns));
        }