Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapFitness"/> class.
 /// </summary>
 /// <param name="map"> The map to calculate fitness for. </param>
 /// <param name="mfo"> The map fitness options. </param>
 public MapFitness(
     MapPhenotype map,
     MapFitnessOptions mfo)
 {
     this.ySize          = map.YSize;
     this.xSize          = map.XSize;
     this.map            = map;
     this.mapPathfinding = new JPSMapPathfinding(map.HeightLevels, map.MapItems, map.DestructibleRocks);
     this.mfo            = mfo;
 }
Example #2
0
        /// <summary>
        /// Creates a map where one part has been turned onto the other part of the map.
        /// </summary>
        /// <param name="half"> The half to work on. </param>
        /// <param name="function"> The way to create the complete map. </param>
        /// <returns> The complete map. </returns>
        public MapPhenotype CreateCompleteMap(Half half, Enums.MapFunction function)
        {
            this.mapHalf = half;

            var newHeightLevels = (HeightLevel[, ]) this.HeightLevels.Clone();
            var newMapItems     = (Item[, ]) this.MapItems.Clone();
            var rocks           = (bool[, ]) this.DestructibleRocks.Clone();

            // Figures out which part of the map that should be looked at.
            var xStart = (half == Half.Right) ? this.XSize / 2 : 0;
            var xEnd   = (half == Half.Left) ? this.XSize / 2 : this.XSize;
            var yStart = (half == Half.Top) ? this.YSize / 2 : 0;
            var yEnd   = (half == Half.Bottom) ? this.YSize / 2 : this.YSize;

            for (var y = yStart; y < yEnd; y++)
            {
                var otherY = y;

                // If we mirror top or bottom or turn the map, find the height to copy to.
                if ((function == Enums.MapFunction.Mirror && (half == Half.Top || half == Half.Bottom)) ||
                    function == Enums.MapFunction.Turn)
                {
                    otherY = this.YSize - y - 1;
                }

                for (var x = xStart; x < xEnd; x++)
                {
                    var otherX = x;

                    // If we mirror left or right or turn the map, find the width to copy to.
                    if ((function == Enums.MapFunction.Mirror && (half == Half.Left || half == Half.Right)) ||
                        function == Enums.MapFunction.Turn)
                    {
                        otherX = this.XSize - x - 1;
                    }

                    newHeightLevels[otherX, otherY] = this.HeightLevels[x, y];
                    newMapItems[otherX, otherY]     = this.MapItems[x, y];
                    rocks[otherX, otherY]           = this.DestructibleRocks[x, y];
                }
            }

            var newMap = new MapPhenotype(newHeightLevels, newMapItems, rocks);

            return(newMap);
        }
Example #3
0
        public static MapPhenotype IncreaseSizeOfMap(MapPhenotype mp, int size)
        {
            var newMap = new MapPhenotype(mp.XSize * size, mp.YSize * size);

            for (var x = 0; x < mp.XSize; x++)
            {
                for (var y = 0; y < mp.YSize; y++)
                {
                    var newMapX = x * size;
                    var newMapY = y * size;

                    for (var i = 0; i < size; i++)
                    {
                        for (var j = 0; j < size; j++)
                        {
                            newMap.HeightLevels[newMapX + i, newMapY + j] = mp.HeightLevels[x, y];
                        }
                    }
                }
            }

            return(newMap);
        }