public bool Repair(Gene[,] sheet, Stock stock, ShapeCut reserved) { var sheetPoints = Enumerable.Range(Origin.X - MaxRepairDistance / 2, Origin.X + MaxRepairDistance / 2) .SelectMany(x => Enumerable.Range(Origin.Y - MaxRepairDistance / 2, Origin.Y + MaxRepairDistance / 2).Select(y => new Point(x, y))) .Where(p => p.X >= 0 && p.X < sheet.GetLength(0) && p.Y >= 0 && p.Y < sheet.GetLength(1)) .Where(p => sheet[p.X, p.Y] == null) .Where(p => p.ManhattanDistance(Origin) <= MaxRepairDistance) .OrderBy(p => p.ManhattanDistance(Origin) + p.ManhattanDistance(new Point(0, Origin.Y))) .ToArray(); foreach (var point in sheetPoints) { Origin = point; foreach (var rotation in Template.Rotations) { Rotation = rotation; var pheno = Phenotype(); if (pheno.IsInBounds(stock) && !pheno.Intersects(reserved)) { var conflict = pheno.Place(sheet, this); if (conflict == null) { pheno.UnPlace(sheet); return(true); } } } } return(false); }
public Gene( ShapeTemplate shapeTemplate, Point origin, ClockwiseRotation absoluteRotation ) { Template = shapeTemplate; Origin = origin; Rotation = absoluteRotation; }
public ShapeTemplateRotated FromRotation(ClockwiseRotation rotation) { var rotatedRefPoints = new List <Point>(ReferencePoints); for (int i = 0; i < (int)rotation; i++) { rotatedRefPoints = rotatedRefPoints.Select(p => new Point(p.Y, -p.X)).ToList(); } return(new ShapeTemplateRotated(rotatedRefPoints, StockWidth)); }
public void CreepRandomize(int stockLength) { var rotations = Template.Rotations; Rotation = CmnRandom.Random.NextFrom(rotations); var template = Template.TemplateAt(Rotation); int absXVal = CmnRandom.Random.NextBiased(0 - template.MinX, stockLength - template.MaxX - 1, Origin.X); int absYVal = CmnRandom.Random.NextBiased(0 - template.MinY, template.StockWidth - template.MaxY - 1, Origin.Y); Origin = new Point(absXVal, absYVal); }
public T(int xPosition, int yPosition, ConsoleColor color = ConsoleColor.DarkMagenta, ClockwiseRotation rotation = ClockwiseRotation.Zero) : base(xPosition, yPosition, color, rotation) { _shape = ShapeBuilder.GetShapeArray(this); }
public ShapeTemplateRotated TemplateAt(ClockwiseRotation rotation) { return(templates[rotation]); }
public void RotateRandomize() { var rotations = Template.Rotations; Rotation = CmnRandom.Random.NextFrom(rotations); }
protected Tetromino(int xPosition, int yPosition, ConsoleColor color, ClockwiseRotation rotation = ClockwiseRotation.Zero) { Position = new Position(xPosition, yPosition); Color = color; ClockwiseRotation = rotation; }
public ShapeCut(Point origin, ShapeTemplate template, ClockwiseRotation rotation) { Origin = origin; Rotation = rotation; Template = template; }