Пример #1
0
        private string Part2(IEnumerable <KeyValuePair <char, int> > input)
        {
            var position = new Vector2Int(0, 0);
            var waypoint = new Vector2Int(10, 1);

            foreach (var(key, value) in input)
            {
                switch (key)
                {
                case 'F':
                    position += waypoint * value;
                    break;

                case 'L':
                    waypoint = waypoint.RotateBy(value);
                    break;

                case 'R':
                    waypoint = waypoint.RotateBy(-value);
                    break;

                default:
                {
                    var direction = Enum.Parse <Direction>(key.ToString(), true);
                    waypoint += direction.GetStep() * value;
                    break;
                }
                }
            }

            position = position.Abs();
            var answer = position.x + position.y;

            return(answer.ToString());
        }
Пример #2
0
    public static int DistMHTo(this Vector2Int from, Vector2Int to)
    {
        Vector2Int v2 = from - to;

        v2 = v2.Abs();
        return(v2.x + v2.y);
    }
Пример #3
0
    public int GetRank(Vector2Int coordinate)
    {
        // Get the distance from the front rank
        Vector2Int frontOrigin = GetFrontOrigin();
        Vector2Int delta       = frontOrigin - coordinate;

        // Delete information in the axis we don't care about
        delta *= facing.Abs();

        // Remaining axis contains rank
        return(delta.Abs().MaxAxisMagnitude());
    }
Пример #4
0
        public static void ForEach(this Vector2Int thisVector, Action <Vector2Int> thisAction)
        {
            Vector2Int absVector = thisVector.Abs();
            Vector2Int direction = new Vector2Int(
                thisVector.x.Normalized(),
                thisVector.y.Normalized()
                );

            for (int x = 0; x <= absVector.x; x++)
            {
                for (int y = 0; y <= absVector.y; y++)
                {
                    thisAction(Vector2Int.Scale(new Vector2Int(x, y), direction));
                }
            }
        }