public override Dictionary <IPos, ILand> MakeLands(int _N) { Dictionary <string, IPos> pm = GenerateBasicMap(_N); Dictionary <IPos, ILand> landsDict = new Dictionary <IPos, ILand>(); float[,] elevation = NoiseGrid(_N); float[,] temperature = NoiseGrid(_N); MapUtil.TransformMapMinMax(ref elevation, MapUtil.dNormalize); MapUtil.TransformMapMinMax(ref temperature, MapUtil.dNormalize); foreach (IPos p in pm.Values) { float elev = elevation[(int)p.gridLoc.x(), (int)p.gridLoc.y()]; float temp = temperature[(int)p.gridLoc.x(), (int)p.gridLoc.y()]; Dictionary <string, float> _val = new Dictionary <string, float>() { { "elevation", elev }, { "temperature", temp } }; ILand newLand = LandFactory.CreateLand(p, _val, game.landType); landsDict[p] = newLand; } return(landsDict); }
/// <summary> /// Gets the fertile plots of land in ascending order as a single string /// </summary> /// <param name="plotsToSaltAsStrings">The plots to salt as a collection of strings, with each string representing an plot to salt</param> /// <returns>A single string containing the fertile plots, separated by a space, in ascending order</returns> public static string GetFertileLandsAsOrderedString(string[] plotsToSaltAsStrings) { _logger.Debug($"Entering {nameof(GetFertileLandsAsOrderedString)}"); var pointFactory = new PointFactory(); var rectangleFactory = new RectangleFactory(); var landFactory = new LandFactory(); var landDefinition = rectangleFactory.CreateRectangle(pointFactory, COLUMNS_OF_LAND, ROWS_OF_LAND); var land = landFactory.CreateLand(landDefinition); // Salt the land var plotsToSalt = plotsToSaltAsStrings.Select(plotToSaltAsString => rectangleFactory.CreateRectangle(pointFactory, plotToSaltAsString)); foreach (var plotToSalt in plotsToSalt) { land.AddSalt(plotToSalt); } // This line satisfies the output requirements string fertileLandAsOrderedString = string.Join(" ", land.FertilePlotsInSquareMeters.OrderBy(plot => plot)); _logger.Debug($"Exiting {nameof(GetFertileLandsAsOrderedString)} with a return value of \"{fertileLandAsOrderedString}\""); return(fertileLandAsOrderedString); }
public Dictionary <IPos, ILand> InitializeLandsFromMidpointDisplacement(int _N, Dictionary <string, IPos> pm) { Dictionary <IPos, ILand> landsDict = new Dictionary <IPos, ILand>(); float[,] elevation = NoiseGrid(_N); MapUtil.TransformMapMinMax(ref elevation, MapUtil.dNormalize); foreach (IPos p in pm.Values) { Dictionary <string, float> _val = new Dictionary <string, float>() { { "elevation", elevation[(int)p.gridLoc.x(), (int)p.gridLoc.y()] } }; ILand newLand = LandFactory.CreateLand(p, _val, game.landType); landsDict[p] = newLand; } return(landsDict); }