public static Array2D <GridSpace> Convert(Container2D <GenSpace> container) { Array2D <GridSpace> arrOut = new Array2D <GridSpace>(container.Bounding); foreach (Value2D <GenSpace> val in container) { if (val == null) { continue; } switch (val.val.Type) { case GridType.Path_Horiz: case GridType.Path_Vert: case GridType.Path_RT: case GridType.Path_LT: case GridType.Path_LB: case GridType.Path_RB: val.val.Type = GridType.Floor; break; } arrOut[val.x, val.y] = new GridSpace(val.val.Type, val.x, val.y); } return(arrOut); }
public static void DrawPotentialInternalDoors(this Container2D <GenSpace> arr, DrawAction <GenSpace> action) { DrawPotentialDoors(arr, new StrokedAction <GenSpace>() { UnitAction = action }); }
protected override bool ModifyInternal(RoomSpec spec) { IPillarTheme pillarTheme = spec.Theme as IPillarTheme; if (pillarTheme == null) { throw new ArgumentException("Theme must be IPillarTheme"); } Bounding bounds = spec.Grids.Bounding; int spacingX = spacingOptions.Get(spec.Random); int spacingY = spec.Random.Percent(differingSpacingChance) ? spacingOptions.Get(spec.Random) : spacingX; Container2D <GenSpace> arr = spec.Grids; var pillarSet = pillarTheme.GetPillars().SmartElement; var call = Draw.IsType <GenSpace>(GridType.Floor).And(Draw.Not(Draw.Blocking(Draw.Walkable()))) .IfThen(Draw.MergeIn(pillarSet, spec.Random, spec.Theme)); for (int x = bounds.XMin; x < bounds.XMax; x = x + spacingX) { for (int y = bounds.YMin; y < bounds.YMax; y = y + spacingY) { call(arr, x, y); } } return(true); }
public JumpTowardsSearcher(Container2D <T> cont, int x, int y, int minJump, int maxJump, DrawAction <T> allowedSpace, DrawAction <T> target, System.Random rand, Point gravityPt, bool hugCorners = true, bool edgeSafe = false) { jumps = Container2D <JumpSetup> .CreateArrayFromBounds <T>(cont); this.container = cont; curPoint = new Point(x, y); this.allowedSpace = allowedSpace; this.rand = rand; this.gravityPt = gravityPt; this.foundTarget = target; this.edgeSafe = edgeSafe; this.minJump = minJump; this.maxJump = maxJump; this.hugCorners = hugCorners; jumpAmountOptionPrototype = new List <int>(maxJump - minJump); for (int i = minJump; i <= maxJump; i++) { jumpAmountOptionPrototype.Add(i); } jumpSmallerOptionPrototype = new List <int>(minJump); for (int i = 1; i < minJump; i++) { jumpSmallerOptionPrototype.Add(i); } }
public static DrawAction <GenSpace> CopyTo(Container2D <GenSpace> cont, Point shift = null) { if (shift == null) { return((arr, x, y) => { GenSpace space; if (arr.TryGetValue(x, y, out space)) { cont.SetTo(x, y, space.Type, space.Theme); } return true; }); } else { return((arr, x, y) => { GenSpace space; if (arr.TryGetValue(x, y, out space)) { cont.SetTo(x + shift.x, y + shift.y, space.Type, space.Theme); } return true; }); } }
public static void DrawPotentialDoors(this Container2D <GenSpace> arr, StrokedAction <GenSpace> action) { DrawAction <GenSpace> check = Draw.CanDrawDoor(); StrokedAction <GenSpace> findDoors = new StrokedAction <GenSpace>(); if (action.StrokeAction != null) { findDoors.StrokeAction = (arr2, x, y) => { if (check(arr2, x, y)) { action.StrokeAction(arr2, x, y); } return(true); }; } if (action.UnitAction != null) { findDoors.UnitAction = (arr2, x, y) => { if (check(arr2, x, y)) { action.UnitAction(arr2, x, y); } return(true); }; } arr.DrawPerimeter(Draw.Not(Draw.IsType <GenSpace>(GridType.NULL)), findDoors); }
public static DrawAction <T> ContainedIn <T>(Container2D <T> coll) { return((arr, x, y) => { return coll.Contains(x, y); }); }
public override bool Place(Container2D <GenSpace> grid, LayoutObject obj, Theme theme, System.Random rand, out Boxing placed) { List <Bounding> options = obj.FindRectangles(GridWidth, GridLength, true, UnitTest); options = new List <Bounding>(options.Filter((bounds) => { Counter counter = new Counter(); grid.DrawRect(new Bounding(bounds, 1), FrontTest.IfThen(Draw.Count <GenSpace>(counter))); return(counter > 0); })); if (options.Count == 0) { placed = null; return(false); } #region DEBUG if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps)) { BigBoss.Debug.w(Logs.LevelGen, "Options:"); if (GridWidth == 1 && GridLength == 1) { MultiMap <GenSpace> tmp = new MultiMap <GenSpace>(); tmp.PutAll(obj); foreach (Bounding bounds in options) { tmp.DrawRect(bounds, Draw.SetTo(GridType.INTERNAL_RESERVED_CUR, theme)); } tmp.ToLog(Logs.LevelGen); } else { foreach (Bounding bounds in options) { MultiMap <GenSpace> tmp = new MultiMap <GenSpace>(); tmp.PutAll(obj); tmp.DrawRect(bounds, Draw.SetTo(GridType.INTERNAL_RESERVED_CUR, theme)); tmp.ToLog(Logs.LevelGen); } } } #endregion // Place startpoints placed = null; return(false); //placed = options.Random(rand); placed.Expand(1); GridLocation side = GridLocation.BOTTOMRIGHT; foreach (GridLocation loc in GridLocationExt.Dirs().Randomize(rand)) { if (obj.DrawEdge(placed, loc, UnitTest, false)) { side = loc; break; } } obj.DrawEdge(placed, side, Draw.SetTo(GridType.StairPlace, theme), false); return(true); }
public Level(Container2D <GridSpace> spaces, LevelLayout layout, Theme theme, System.Random rand) { _array = spaces.Array; LoadRoomMaps(layout); UpStartPoint = layout.UpStart; DownStartPoint = layout.DownStart; Random = rand; }
public static DrawAction <GenSpace> SetTo(Container2D <GenSpace> cont, GridType type, Theme theme) { return((arr, x, y) => { cont.SetTo(x, y, type, theme); return true; }); }
public static void Write2DArray <T>(Container2D <T> array2D, string separator = " ") { for (int i = 0; i < array2D.Height; ++i) { for (int j = 0; j < array2D.Width; ++j) { Console.Write(array2D[j, i] + separator); } Console.WriteLine(); } }
public static bool IsType <T>(this Container2D <T> cont, int x, int y, GridType type) where T : IGridSpace { T space; if (cont.TryGetValue(x, y, out space)) { return(type.Equals(cont[x, y].GetGridType())); } return(type == GridType.NULL); }
public override HashSet <IAffectable> GetTargets(SpellCastInfo castInfo) { Container2D <GridSpace> level = BigBoss.Levels.Level.Array; var targetSpaces = new HashSet <GridSpace>(); foreach (GridSpace point in castInfo.TargetSpaces) { level.DrawCircle(point.X, point.Y, Radius, Draw.AddTo(targetSpaces)); } castInfo.TargetSpaces = targetSpaces.ToArray(); return(base.GetTargets(castInfo)); }
public void ToLog(Logs logs, Container2D <T> orig, params string[] customContent) { BigBoss.Debug.printHeader(logs, "Random Picker"); var tmp = new T[orig.Height, orig.Width]; foreach (Value2D <T> val in _options) { tmp[val.y, val.x] = val.val; } tmp.ToLog(logs, customContent); BigBoss.Debug.printFooter(logs, "Random Picker"); }
protected void ConstructBFS(LayoutObject obj, out Queue <Value2D <GenSpace> > queue, out Container2D <bool> visited) { visited = new MultiMap <bool>(); queue = new Queue <Value2D <GenSpace> >(); obj.GetConnectedGrid().DrawPerimeter(Draw.Not(Draw.IsType <GenSpace>(GridType.NULL)), new StrokedAction <GenSpace>() { UnitAction = Draw.SetTo <GenSpace, bool>(visited, true), StrokeAction = Draw.AddTo(queue).And(Draw.SetTo <GenSpace, bool>(visited, true)) }, false); }
public static void DrawPotentialDoors(this Container2D <GenSpace> arr, DrawAction <GenSpace> action) { DrawAction <GenSpace> check = Draw.CanDrawDoor(); arr.DrawAll(new DrawAction <GenSpace>((arr2, x, y) => { if (check(arr2, x, y)) { action(arr2, x, y); } return(true); })); }
void GenerateLevel(int depth) { LevelGenerator gen = new LevelGenerator(); gen.Theme = GetTheme(); gen.Depth = depth; gen.Rand = new System.Random(_levelSeeds[depth]); LevelLayout layout = gen.Generate(); Container2D <GridSpace> spaces = Builder.GeneratePrototypes(layout); Level level = new Level(spaces, layout, gen.Theme, gen.Rand); _levels[depth] = level; }
public SquareFinder(Container2D <T> arr, int width, int height, bool tryFlipped, StrokedAction <T> tester, Bounding scope = null) { _arr = arr; _width = width; _height = height; _tryFlipped = tryFlipped && width != height; _tester = tester; _scope = scope; if (scope == null) { _scope = arr.Bounding; } }
private void StartAlgorithm_Execute() { try { IAlgorithm algorithm; if (!CheckContainerSize()) { throw new InvalidContainerSizeException("Container is not big enough to contain biggest object. Enlarge the container."); } if (Dimensionality == AlgorithmDimensionality.TwoDimensional) { Container2D startingContainer = containerFactory.Create(algorithmProperties, ContainerWidth, ContainerHeight); algorithm = factory.Create(algorithmProperties, startingContainer); } else { Container3D startingContainer = containerFactory.Create(algorithmProperties, ContainerWidth, ContainerHeight, ContainerDepth); algorithm = factory.Create(algorithmProperties, startingContainer); } stopwatch.Reset(); var sortedObjects = SortingHelper.Sort(objectsToPack, ObjectOrdering); stopwatch.Start(); algorithm.Execute(sortedObjects); stopwatch.Stop(); var endResults = algorithm.CreateResults(); ExecutionTime = stopwatch.ElapsedMilliseconds; Quality = endResults.Quality; ContainersUsed = endResults.ContainersUsed; ObjectAmount = endResults.ObjectCount; ObjectTotalFullfilment = endResults.ObjectsTotalFulfillment; ContainerFulfillment = endResults.ContainerFulfillment; AverageFulfillmentRatio = endResults.AverageFulfillmentRatio; FulfillmentRatioStandardDeviation = endResults.FulfillmentRatioStandardDeviation; WorstFulfillment = endResults.WorstFulfillment; System.Windows.MessageBox.Show("Program successfully packed input object set.", "End of packing."); } catch (Exception err) { System.Windows.MessageBox.Show("Error during executing algorithm: " + err.Message, "Error"); } }
public override bool Place(Container2D <GenSpace> grid, LayoutObject obj, Theme theme, Random rand, out Boxing placed) { int max = Math.Max(GridWidth, GridLength); List <Boxing> options = new List <Boxing>( grid.FindBoxes( GridWidth, GridLength, GridLocation.TOP, new BoxedAction <GenSpace>( frontTest.And(Draw.ContainedIn(obj)), unitTest), true, true, obj.Bounding.Expand(max)) .Filter((box) => { Counter counter = new Counter(); bool ret = grid.DrawEdge(box, box.Front, Draw.HasAround(false, Draw.And(Draw.IsType <GenSpace>(GridType.Floor), Draw.Count <GenSpace>(counter)). Or(Draw.Walkable()))); return(ret && counter > 0); })); if (options.Count == 0) { placed = null; return(false); } #region DEBUG if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps)) { BigBoss.Debug.w(Logs.LevelGen, "Options:"); foreach (Boxing boxing in options) { MultiMap <GenSpace> tmp = new MultiMap <GenSpace>(); tmp.PutAll(obj); tmp.DrawRect(boxing, Draw.SetTo(GridType.INTERNAL_RESERVED_CUR, theme)); tmp.DrawEdge(boxing, boxing.Front, Draw.SetTo(GridType.INTERNAL_RESERVED_BLOCKED, theme)); tmp.ToLog(Logs.LevelGen); } } #endregion // Place startpoints placed = options.Random(rand); obj.DrawEdge(placed, placed.Front, Draw.Around(false, Draw.IsType <GenSpace>(GridType.Floor).IfThen(Draw.SetTo(GridType.StairPlace, theme)))); return(true); }
private IAlgorithm Create2DAlgorithm(AlgorithmProperties properties, Container2D initialContainer) { switch (properties.Family) { case (AlgorithmFamily.Shelf): return(Create2DShelfAlgorithm(properties.AlgorithmType, initialContainer)); case (AlgorithmFamily.Skyline): return(Create2DSkylineAlgorithm(properties.AlgorithmType, initialContainer)); case (AlgorithmFamily.GuillotineCut): return(Create2DGuillotineAlgorithm(properties.AlgorithmType, properties.SplittingStrategy, initialContainer)); default: throw new NotSuchAlgorithmException(); } }
public static DrawAction <T> AddTo <T>(Container2D <T> map, Point shift = null) { if (shift == null) { return((arr, x, y) => { map[x, y] = arr[x, y]; return true; }); } else { return((arr, x, y) => { map[x + shift.x, y + shift.y] = arr[x, y]; return true; }); } }
public static DrawAction <T> SetTo <T, R>(Container2D <R> container, R g, Point shift = null) { if (shift == null) { return((arr, x, y) => { container[x, y] = g; return true; }); } else { return((arr, x, y) => { container[x + shift.x, y + shift.y] = g; return true; }); } }
public Array2D(Container2D <T> rhs) : this(rhs.Bounding) { if (rhs is Array2D <T> && shift == null) { Array2D <T> rhsArr = (Array2D <T>)rhs; for (int y = 0; y < rhsArr.Height; y++) { for (int x = 0; x < rhsArr.Width; x++) { arr[y, x] = rhsArr.arr[y, x]; present[y, x] = rhsArr.present[y, x]; } } } else { PutAll(rhs); } }
public static List <Value2D <GenSpace> > PlaceSomeDoors(this Container2D <GenSpace> arr, IEnumerable <Point> points, Theme theme, System.Random rand, int desiredWallToDoorRatio = -1, Point shift = null) { if (desiredWallToDoorRatio < 0) { desiredWallToDoorRatio = LevelGenerator.desiredWallToDoorRatio; } var acceptablePoints = new MultiMap <GenSpace>(); Counter numPoints = new Counter(); DrawAction <GenSpace> call = Draw.Count <GenSpace>(numPoints).And(Draw.CanDrawDoor().IfThen(Draw.AddTo(acceptablePoints))); if (shift != null) { call = call.Shift <GenSpace>(shift.x, shift.y); } arr.DrawPoints(points, call); if (DoorRatioPicker == null) { DoorRatioPicker = new ProbabilityList <int>(); DoorRatioPicker.Add(-2, .25); DoorRatioPicker.Add(-1, .5); DoorRatioPicker.Add(0, 1); DoorRatioPicker.Add(1, .5); DoorRatioPicker.Add(2, .25); } int numDoors = numPoints / desiredWallToDoorRatio; numDoors += DoorRatioPicker.Get(rand); if (numDoors <= 0) { numDoors = 1; } List <Value2D <GenSpace> > pickedPts = acceptablePoints.GetRandom(rand, numDoors, 1); foreach (Point picked in pickedPts) { arr.SetTo(picked, GridType.Door, theme); } return(pickedPts); }
public static void MergeIn(this Container2D <GenSpace> arr, int x, int y, GenDeploy deploy, Theme theme, GridType type = GridType.Floor, bool typeOnlyDefault = true, bool themeOnlyDefault = false) { GenSpace space; if (!arr.TryGetValue(x, y, out space)) { space = new GenSpace(type, theme, x, y); arr[x, y] = space; } else { if (!themeOnlyDefault) { space.Theme = theme; } if (!typeOnlyDefault) { space.Type = type; } } space.AddDeploy(deploy, x, y); }
protected bool FindNextPathPoints(Container2D <GenSpace> map, Container2D <GenSpace> runningConnected, out LayoutObject hit, DrawAction <GenSpace> pass, Queue <Value2D <GenSpace> > curQueue, Container2D <bool> curVisited, out Value2D <GenSpace> startPoint, out Value2D <GenSpace> endPoint) { if (!map.DrawBreadthFirstSearch( curQueue, curVisited, false, Draw.IsType <GenSpace>(GridType.NULL), pass, out endPoint)) { hit = null; startPoint = null; return(false); } if (!Container.GetObjAt(endPoint, out hit)) { startPoint = null; return(false); } Container2D <bool> hitVisited; Queue <Value2D <GenSpace> > hitQueue; ConstructBFS(hit, out hitQueue, out hitVisited); curQueue.Enqueue(hitQueue); curVisited.PutAll(hitVisited); return(map.DrawBreadthFirstSearch( hitQueue, hitVisited, false, Draw.IsType <GenSpace>(GridType.NULL), pass.And(Draw.ContainedIn(runningConnected)), out startPoint)); }
private static UIComponent Create2DUIPage(RenderGroup renderGroup) { var entity = new Entity("Avalonia Screen Page " + renderGroup); var uiPage = new UIComponent { RenderGroup = renderGroup, Page = new UIPage { Name = "Screen Page " + renderGroup, RootElement = new Canvas() } }; var game = AvaloniaLocator.Current.GetService <IGame>(); var width = game.GraphicsDevice.Presenter.Description.BackBufferWidth; var height = game.GraphicsDevice.Presenter.Description.BackBufferHeight; uiPage.Resolution = new Vector3(width, height, 1000); ScreenPages.Add(renderGroup, uiPage); entity.Add(uiPage); Container2D.AddChild(entity); return(uiPage); }
public Bounding InBounds <T>(Container2D <T> arr) { return(IntersectBounds(arr.Bounding)); }
public NextFitShelf2DAlgorithm(Container2D initialContainer) : base(initialContainer) { }