public ValuePoint(ValuePoint p) : base(p) { Value = p.Value; }
public int Part2(string input) { var res = 0; var isInt = int.TryParse(input, out var stop); if (input.IsNullOrEmpty() || !isInt) { return(res); } var currentPoint = new ValuePoint(0, 0, 1); var stepSize = 1; var points = new List <ValuePoint> { new ValuePoint(currentPoint) }; if (points.Last().Value > stop) { return(points.Last().Value); } while (true) { foreach (var action in _lstActions) { switch (action) { case ActionTypeEnum.IncreaseStepSize: stepSize++; break; case ActionTypeEnum.MoveRight: for (var i = 0; i < stepSize; i++) { currentPoint = new ValuePoint(currentPoint); currentPoint.X++; currentPoint.Value = CalculateValue(points, currentPoint); points.Add(new ValuePoint(currentPoint)); if (points.Last().Value > stop) { return(points.Last().Value); } } break; case ActionTypeEnum.MoveTop: for (var i = 0; i < stepSize; i++) { currentPoint = new ValuePoint(currentPoint); currentPoint.Y++; currentPoint.Value = CalculateValue(points, currentPoint); points.Add(new ValuePoint(currentPoint)); if (points.Last().Value > stop) { return(points.Last().Value); } } break; case ActionTypeEnum.MoveLeft: for (var i = 0; i < stepSize; i++) { currentPoint = new ValuePoint(currentPoint); currentPoint.X--; currentPoint.Value = CalculateValue(points, currentPoint); points.Add(new ValuePoint(currentPoint)); if (points.Last().Value > stop) { return(points.Last().Value); } } break; case ActionTypeEnum.MoveBottom: for (var i = 0; i < stepSize; i++) { currentPoint = new ValuePoint(currentPoint); currentPoint.Y--; currentPoint.Value = CalculateValue(points, currentPoint); points.Add(new ValuePoint(currentPoint)); if (points.Last().Value > stop) { return(points.Last().Value); } } break; default: throw new ArgumentOutOfRangeException(); } } } }