public void FullSizeIsInclusiveOfRange() { var grid = new GrowingGrid <bool>(false, new Point(0, 2), new Point(0, 5), 3, true, true); Assert.Equal(3, grid.FullWidth); Assert.Equal(6, grid.FullHeight); }
public Solver(GrowingGrid <char> grid, GridPreview <char> renderer, HeaderValue treeHitHeader, Point direction) { _totalHeight = grid.FullHeight; Grid = grid; Renderer = renderer; TreeHitHeader = treeHitHeader; _direction = direction; }
public GrowingGridEvent(GrowingGrid <T> growingGrid, int up, int right, int down, int left) { Grid = growingGrid; Up = up; Right = right; Down = down; Left = left; }
public void CheckRight_DoesntGrow() { var grid = new GrowingGrid <bool>(false, new Point(-2, 2), new Point(-5, 5), 3, true, true); grid[2, 0] = true; Assert.Equal(true, grid[2, 0]); Assert.Equal(0, grid.GrowthTimesRight); Assert.Equal(0, grid.GrowthTimes); }
public void OffsetedHasRightMinMax() { var grid = new GrowingGrid <bool>(false, new Point(-2, 2), new Point(-5, 5), 3, true, true); Assert.Equal(-2, grid.MinX); Assert.Equal(2, grid.MaxX); Assert.Equal(-5, grid.MinY); Assert.Equal(5, grid.MaxY); }
public void CheckDown_DoesntGrow() { var grid = new GrowingGrid <bool>(false, new Point(-2, 2), new Point(-5, 5), 3, true, true); grid[0, -5] = true; Assert.Equal(true, grid[0, -5]); Assert.Equal(0, grid.GrowthTimesDown); Assert.Equal(0, grid.GrowthTimes); }
//----------------------------------------------------------------- private void OnGridGrow(GrowingGrid <char> .GrowingGridEvent growingEvent) { var grid = growingEvent.Grid; if (growingEvent.Right != 0 && _inputGrid != null) { grid.AddGrid(grid.FullWidth - growingEvent.Right, 0, _inputGrid, GridAxes.XY); } }
/*public struct NodeItem * { * public string Key; * public int Quantity; * * public NodeItem(string key, int quantity) * { * Key = key; * Quantity = quantity; * } * }*/ // ------------------------------------------- public static GrowingGrid <char> ReadGrowingGrid(string input, char lineseparator, char defaultValue) { var grid = ParseCharGrid(input, lineseparator); var xRange = new Point(0, grid.GetLength(0)); var yRange = new Point(0, grid.GetLength(1)); var growingGrid = new GrowingGrid <char>(defaultValue, xRange, yRange, grid.Length, true, true); growingGrid.AddGrid(0, 0, grid, GridAxes.XY); return(growingGrid); }
public void LookingAtAllCorner_UsedSizeShouldBeLikeFull() { var grid = new GrowingGrid <bool>(false, new Point(0, 2), new Point(0, 5), 3, true, true); grid[0, 0] = true; grid[0, 2] = true; grid[2, 5] = true; grid[2, 5] = true; Assert.Equal(grid.FullWidth, grid.UsedWidth); Assert.Equal(grid.FullHeight, grid.UsedHeight); }
public void OffsetedAddGrid() { var grid = new GrowingGrid <int>(0, new Point(0, 2), new Point(0, 5), 10, true, true); grid.AddGrid(1, 1, SmallSquare, GridAxes.YX); Assert.Equal(1, grid[1, 1]); Assert.Equal(2, grid[2, 1]); Assert.Equal(3, grid[2, 2]); Assert.Equal(4, grid[1, 2]); }
public void AddGridOnGrowth() { var grid = new GrowingGrid <int>(0, new Point(0, 2), new Point(0, 5), 10, true, true); grid.OnGridGrown = DoAddGridOnGrowth; Assert.Equal(1, grid[3, 0]); Assert.Equal(2, grid[4, 0]); Assert.Equal(3, grid[4, 1]); Assert.Equal(4, grid[3, 1]); }
public void LookingAtAllCorner_ShouldNotMakeAnyResize() { var grid = new GrowingGrid <bool>(false, new Point(0, 2), new Point(0, 5), 3, true, true); grid[0, 0] = true; grid[0, 5] = true; grid[2, 5] = true; grid[2, 5] = true; Assert.Equal(0, grid.GrowthTimesUp); Assert.Equal(0, grid.GrowthTimesRight); Assert.Equal(0, grid.GrowthTimesDown); Assert.Equal(0, grid.GrowthTimesLeft); }
public void LookingAtAllCorner_HaveTheRightMinMaxXY() { var grid = new GrowingGrid <bool>(false, new Point(0, 2), new Point(0, 5), 3, true, true); grid[0, 0] = true; grid[0, 2] = true; grid[2, 5] = true; grid[2, 5] = true; Assert.Equal(0, grid.MinX); Assert.Equal(2, grid.MaxX); Assert.Equal(0, grid.MinY); Assert.Equal(5, grid.MaxY); }
public void SimpleAddGrid() { var grid = new GrowingGrid <int>(0, new Point(0, 2), new Point(0, 5), 10, true, true); var gridToAdd = new int[, ] { { 1, 0, 2 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 4, 0, 3 } }; grid.AddGrid(0, 0, gridToAdd, GridAxes.YX); Assert.Equal(1, grid[0, 0]); Assert.Equal(2, grid[2, 0]); Assert.Equal(3, grid[2, 5]); Assert.Equal(4, grid[0, 5]); }
public void GrowLeftOnce_With2TimeGrowthSize() { var grid = new GrowingGrid <bool>(false, new Point(0, 2), new Point(0, 5), 10, true, true); grid[-16, 0] = true; Assert.Equal(0, grid.GrowthTimesUp); Assert.Equal(0, grid.GrowthTimesRight); Assert.Equal(0, grid.GrowthTimesDown); Assert.Equal(1, grid.GrowthTimesLeft); Assert.Equal(-20, grid.MinX); Assert.Equal(2, grid.MaxX); Assert.Equal(23, grid.FullWidth); }
public void GrowTwiceRight_IsTwiceBiggerToTheRight() { var grid = new GrowingGrid <bool>(false, new Point(0, 2), new Point(0, 5), 10, true, true); grid[3, 0] = true; grid[20, 0] = true; Assert.Equal(0, grid.GrowthTimesUp); Assert.Equal(2, grid.GrowthTimesRight); Assert.Equal(0, grid.GrowthTimesDown); Assert.Equal(0, grid.GrowthTimesLeft); Assert.Equal(23, grid.FullWidth); Assert.Equal(6, grid.FullHeight); }
public void GrowDownOnce_With2TimeGrowthSize() { var grid = new GrowingGrid <bool>(false, new Point(0, 2), new Point(0, 5), 10, true, true); grid[0, -16] = true; Assert.Equal(0, grid.GrowthTimesUp); Assert.Equal(0, grid.GrowthTimesRight); Assert.Equal(1, grid.GrowthTimesDown); Assert.Equal(0, grid.GrowthTimesLeft); Assert.Equal(-20, grid.MinY); Assert.Equal(5, grid.MaxY); Assert.Equal(26, grid.FullHeight); }
public void GrowRight_IsBiggerToTheRight() { var grid = new GrowingGrid <bool>(false, new Point(0, 2), new Point(0, 5), 10, true, true); grid[3, 0] = true; Assert.Equal(0, grid.GrowthTimesUp); Assert.Equal(1, grid.GrowthTimesRight); Assert.Equal(0, grid.GrowthTimesDown); Assert.Equal(0, grid.GrowthTimesLeft); Assert.Equal(0, grid.MinX); Assert.Equal(12, grid.MaxX); Assert.Equal(13, grid.FullWidth); Assert.Equal(6, grid.FullHeight); Assert.Equal(0, grid.MinY); Assert.Equal(5, grid.MaxY); }
//----------------------------------------------------------------- public override long Part1(string input) { var worldmap = new GrowingGrid <char>('~', new Point(-20, 20), new Point(-20, 20), 20, true, true); if (_gridPreview != null) { _gridPreview.Grid = worldmap; } worldmap[0, 0] = '@'; _gridPreview?.Update(); var instructions = ParseInput(input); int shipX = 0; int shipY = 0; var direction = Direction.Est; foreach (var instruction in instructions) { Console.WriteLine(instruction.Direction + " " + instruction.Amount); worldmap[shipX, shipY] = '!'; switch (instruction.Direction) { case 'N': shipY -= instruction.Amount; break; case 'S': shipY += instruction.Amount; break; case 'W': shipX -= instruction.Amount; break; case 'E': shipX += instruction.Amount; break; case 'L': for (int i = 0; i < instruction.Amount / 90; i++) { direction = direction.Left(); } break; case 'R': for (int i = 0; i < instruction.Amount / 90; i++) { direction = direction.Right(); } break; case 'F': var movement = direction.ToPoint() * instruction.Amount; shipX += movement.X; shipY += movement.Y; break; } worldmap[shipX, shipY] = '@'; Console.WriteLine("-> Ship : " + new Point(shipX, shipY) + " - " + direction); if (_gridPreview != null) { _gridPreview.Offset = new Point(shipX - _gridPreview.Viewport.Width / 2, shipY - _gridPreview.Viewport.Height / 2); } _gridPreview?.Update(); } return(new Point(shipX, shipY).DistanceManhattan(Point.ZERO)); }
//----------------------------------------------------------------- //78648 Too high public override long Part2(string input) { var worldmap = new GrowingGrid <char>('~', new Point(-20, 20), new Point(-20, 20), 20, true, true); if (_gridPreview != null) { _gridPreview.Grid = worldmap; } worldmap[0, 0] = '@'; _gridPreview?.Update(); var instructions = ParseInput(input); int shipX = 0; int shipY = 0; var waypoint = new Point(10, -1); foreach (var instruction in instructions) { Console.WriteLine(instruction.Direction + " " + instruction.Amount); if (_gridPreview != null) { worldmap[shipX, shipY] = '!'; } switch (instruction.Direction) { case 'N': waypoint.Y -= instruction.Amount; break; case 'S': waypoint.Y += instruction.Amount; break; case 'W': waypoint.X -= instruction.Amount; break; case 'E': waypoint.X += instruction.Amount; break; case 'L': for (int i = 0; i < instruction.Amount / 90; i++) { waypoint = waypoint.RotateRight(); } break; case 'R': for (int i = 0; i < instruction.Amount / 90; i++) { waypoint = waypoint.RotateLeft(); } break; case 'F': shipX += waypoint.X * instruction.Amount; shipY += waypoint.Y * instruction.Amount; break; } if (_gridPreview != null) { worldmap[shipX, shipY] = '@'; } Console.WriteLine("-> Ship : " + new Point(shipX, shipY) + " - WP: " + waypoint); if (_gridPreview != null) { _gridPreview.Offset = new Point(shipX - _gridPreview.Viewport.Width / 2, shipY - _gridPreview.Viewport.Height / 2); } //_gridPreview?.Update(); } return(new Point(shipX, shipY).DistanceManhattan(Point.ZERO)); }
private void DoAddGridOnGrowth(GrowingGrid <int> .GrowingGridEvent obj) { obj.Grid.AddGrid(obj.Grid.FullWidth - obj.Right, 0, SmallSquare, GridAxes.YX); }