package me.lucaspickering.groundwar.world.generate;

import java.util.HashSet;
import java.util.Map;
import java.util.Random;
import java.util.Set;

import me.lucaspickering.groundwar.util.Funcs;
import me.lucaspickering.groundwar.util.InclusiveRange;
import me.lucaspickering.groundwar.util.TilePoint;
import me.lucaspickering.groundwar.world.WorldHelper;
import me.lucaspickering.groundwar.world.tile.Tile;

public class PeakGenerator implements Generator {

    // Generation parameters
    private static final InclusiveRange PEAKS_RANGE = new InclusiveRange(3, 5);
    private static final int MIN_PEAK_SEPARATION = 2; // Min distance between two peak

    @Override
    public void generate(Map<TilePoint, Tile.Builder> world, Random random) {
        // Generate peaks
        // Copy the key set because we're going to be modifying it
        final Set<TilePoint> potentialPeaks = new HashSet<>(world.keySet());
        final Set<TilePoint> peaks = new HashSet<>();
        final int peaksToGen = PEAKS_RANGE.randomIn(random);

        while (peaks.size() < peaksToGen && !potentialPeaks.isEmpty()) {
            // Pick a random peak from the set of potential peaks
            final TilePoint peak = Funcs.randomFromCollection(random, potentialPeaks);
            peaks.add(peak); // Add it to the set

            // Get all the tiles that are too close to this one to be peaks themselves,
            // and remove them from the set of potential peaks
            final Set<TilePoint> tooClose = WorldHelper.getTilesInRange(world.keySet(), peak,
                                                                        MIN_PEAK_SEPARATION);
            potentialPeaks.removeAll(tooClose);
        }

        for (TilePoint peak : peaks) {
            world.get(peak).setElevation(5); // Modify the peak tile
        }
    }
}

@@ -523,25 +523,30 @@
 veRange PEAK
-S
+_COUNT
 _RANGE = new
@@ -565,12 +565,103 @@
 nge(
-3, 5
+4, 7);%0A    private static final InclusiveRange PEAK_ELEVATION_RANGE = new InclusiveRange(45, 60
 );%0A 
@@ -1098,17 +1098,22 @@
 n = PEAK
-S
+_COUNT
 _RANGE.r
@@ -1840,24 +1840,158 @@
  : peaks) %7B%0A
+            // Pick a random elevation for the peak and assign it%0A            final int elev = PEAK_ELEVATION_RANGE.randomIn(random);%0A
             
@@ -2023,35 +2023,14 @@
 ion(
-5); // Modify the peak tile
+elev);
 %0A   
@@ -2036,16 +2036,18 @@
       %7D%0A
+%0A%0A
     %7D%0A%7D%0A

Change peak elev