HashMap reverseHex = new HashMap(2 * mapSettings.getBoardWidth() * mapSettings.getBoardHeight());
HashMap<IHex,Point> reverseHex = new HashMap<IHex,Point>(2 * mapSettings.getBoardWidth() * mapSettings.getBoardHeight());
    public static IBoard generateRandom(MapSettings mapSettings) {        int elevationMap[][] = new int[mapSettings.getBoardWidth()][mapSettings.getBoardHeight()];        double sizeScale = (double)(mapSettings.getBoardWidth() * mapSettings.getBoardHeight()) / ((double)(16 * 17));                generateElevation(mapSettings.getHilliness(),                mapSettings.getBoardWidth(),                 mapSettings.getBoardHeight(),                mapSettings.getRange() + 1,                 mapSettings.getProbInvert(),                mapSettings.getInvertNegativeTerrain(),                elevationMap,                mapSettings.getAlgorithmToUse());                IHex[] nb = new IHex[mapSettings.getBoardWidth() * mapSettings.getBoardHeight()];        int index = 0;        for (int h = 0; h < mapSettings.getBoardHeight(); h++) {            for (int w = 0; w < mapSettings.getBoardWidth(); w++) {                nb[index++] = new Hex(elevationMap[w][h],"",mapSettings.getTheme());            }        }                IBoard result = new Board(mapSettings.getBoardWidth(),mapSettings.getBoardHeight(), nb);        /* initalize reverseHex */        HashMap reverseHex = new HashMap(2 * mapSettings.getBoardWidth() * mapSettings.getBoardHeight());        for (int y = 0; y < mapSettings.getBoardHeight(); y++) {            for (int x = 0; x < mapSettings.getBoardWidth(); x++) {                reverseHex.put(result.getHex(x, y),new Point(x, y));            }        }                int peaks = mapSettings.getMountainPeaks();        while(peaks > 0) {            peaks--;            int mountainHeight = mapSettings.getMountainHeightMin() +             Compute.randomInt(1 + mapSettings.getMountainHeightMax() -                     mapSettings.getMountainHeightMin());            int mountainWidth = mapSettings.getMountainWidthMin() +             Compute.randomInt(1 + mapSettings.getMountainWidthMax() -                     mapSettings.getMountainWidthMin());            int mapWidth = result.getWidth();            int mapHeight = result.getHeight();                        //put the peak somewhere in the middle of the map...            Coords peak = new Coords(mapWidth/4 + Compute.randomInt((mapWidth+1)/2),                    mapHeight/4 + Compute.randomInt((mapHeight+1)/2));                        generateMountain(result, mountainWidth, peak, mountainHeight, mapSettings.getMountainStyle());                    }                if(mapSettings.getCliffs() > 0) {            addCliffs(result, mapSettings.getCliffs());        }                /* Add the woods */        int count = mapSettings.getMinForestSpots();        if (mapSettings.getMaxForestSpots() > 0) {            count += Compute.randomInt(mapSettings.getMaxForestSpots());        }        count *= sizeScale;        for (int i = 0; i < count; i++) {            placeSomeTerrain(result, Terrains.WOODS, mapSettings.getProbHeavy() ,                    mapSettings.getMinForestSize(),                     mapSettings.getMaxForestSize(),                    reverseHex,                    true);        }        /* Add the rough */        count = mapSettings.getMinRoughSpots();        if (mapSettings.getMaxRoughSpots() > 0) {            count += Compute.randomInt(mapSettings.getMaxRoughSpots());        }        count *= sizeScale;        for (int i = 0; i < count; i++) {            placeSomeTerrain(result, Terrains.ROUGH, 0,                    mapSettings.getMinRoughSize(),                     mapSettings.getMaxRoughSize(),                    reverseHex,                    true);        }        /* Add the swamp */        count = mapSettings.getMinSwampSpots();        if (mapSettings.getMaxSwampSpots() > 0) {            count += Compute.randomInt(mapSettings.getMaxSwampSpots());        }        count *= sizeScale;        for (int i = 0; i < count; i++) {            placeSomeTerrain(result, Terrains.SWAMP, 0,                    mapSettings.getMinSwampSize(),                     mapSettings.getMaxSwampSize(),                    reverseHex,                    false); // can stack with woods or roughs        }        // Add the Fortified hexes        count = mapSettings.getMinFortifiedSpots();        if (mapSettings.getMaxFortifiedSpots() > 0) {            count += Compute.randomInt(mapSettings.getMaxFortifiedSpots());        }        count *= sizeScale;        for (int i = 0; i < count; i++) {            placeSomeTerrain(result, Terrains.FORTIFIED, 0,                    mapSettings.getMinFortifiedSize(),                     mapSettings.getMaxFortifiedSize(),                    reverseHex,                    false);         }        // Add the rubble        count = mapSettings.getMinRubbleSpots();        if (mapSettings.getMaxRubbleSpots() > 0) {            count += Compute.randomInt(mapSettings.getMaxRubbleSpots());        }        count *= sizeScale;        for (int i = 0; i < count; i++) {            placeSomeTerrain(result, Terrains.RUBBLE, 0,                    mapSettings.getMinRubbleSize(),                     mapSettings.getMaxRubbleSize(),                    reverseHex,                    true);        }        /* Add the water */        count = mapSettings.getMinWaterSpots();        if (mapSettings.getMaxWaterSpots() > 0) {             count += Compute.randomInt(mapSettings.getMaxWaterSpots());        }        count *= sizeScale;        for (int i = 0; i < count; i++) {            placeSomeTerrain(result, Terrains.WATER, mapSettings.getProbDeep() ,                    mapSettings.getMinWaterSize(),                     mapSettings.getMaxWaterSize(),                    reverseHex,                    true);        }        /* Add the pavements */        count = mapSettings.getMinPavementSpots();        if (mapSettings.getMaxPavementSpots() > 0) {            count += Compute.randomInt(mapSettings.getMaxPavementSpots());        }        count *= sizeScale;        for (int i = 0; i < count; i++) {            placeSomeTerrain(result, Terrains.PAVEMENT, 0,                    mapSettings.getMinPavementSize(),                     mapSettings.getMaxPavementSize(),                    reverseHex,                    true);         }                /* Add the ice */        count = mapSettings.getMinIceSpots();        if (mapSettings.getMaxIceSpots() > 0) {            count += Compute.randomInt(mapSettings.getMaxIceSpots());        }        count *= sizeScale;        for (int i = 0; i < count; i++) {            placeSomeTerrain(result, Terrains.ICE, 0,                    mapSettings.getMinIceSize(),                     mapSettings.getMaxIceSize(),                    reverseHex,                    true);         }                /* Add the craters */        if (Compute.randomInt(100) < mapSettings.getProbCrater()) {            addCraters(result, mapSettings.getMinRadius(), mapSettings.getMaxRadius(),                    (int)(mapSettings.getMinCraters()*sizeScale),                    (int)(mapSettings.getMaxCraters()*sizeScale));        }                /* Add the river */        if (Compute.randomInt(100)<mapSettings.getProbRiver()) {            addRiver(result, reverseHex);        }                /* Add special effects */        if(Compute.randomInt(100)<mapSettings.getProbFlood()) {            PostProcessFlood(nb, mapSettings.getFxMod());        }        if(Compute.randomInt(100)<mapSettings.getProbDrought()) {            PostProcessDrought(nb, mapSettings.getFxMod());        }        if(Compute.randomInt(100)<mapSettings.getProbFreeze()) {            PostProcessDeepFreeze(nb, mapSettings.getFxMod());        }        if(Compute.randomInt(100)<mapSettings.getProbForestFire()) {            PostProcessForestFire(nb, mapSettings.getFxMod());        }                /* Add the road */        boolean roadNeeded = false;        if (Compute.randomInt(100)<mapSettings.getProbRoad()) {            roadNeeded = true;        }        // add buildings         Vector buildings = mapSettings.getBoardBuildings();        CityBuilder cityBuilder = new CityBuilder(mapSettings, result);        if(buildings.size() == 0) {            buildings = cityBuilder.generateCity(roadNeeded);        }        for(int i=0; i<buildings.size();i++) {            placeBuilding(result, (BuildingTemplate)(buildings.elementAt(i)));        }        return result;    }