예제 #1
0
        public void Should_calculate_direction_correctly()
        {
            var coord    = new HexCoords(0, 0);
            var neighbor = new HexCoords(0, 1);

            Assert.AreEqual(1, HexCoords.Distance(coord, neighbor));

            neighbor = new HexCoords(0, 1);
            Assert.AreEqual(1, HexCoords.Distance(coord, neighbor));

            neighbor = new HexCoords(-1, 1);
            Assert.AreEqual(1, HexCoords.Distance(coord, neighbor));

            neighbor = new HexCoords(1, 0);
            Assert.AreEqual(1, HexCoords.Distance(coord, neighbor));

            neighbor = new HexCoords(-1, 0);
            Assert.AreEqual(1, HexCoords.Distance(coord, neighbor));

            neighbor = new HexCoords(1, -1);
            Assert.AreEqual(1, HexCoords.Distance(coord, neighbor));

            neighbor = new HexCoords(0, -1);
            Assert.AreEqual(1, HexCoords.Distance(coord, neighbor));
        }
예제 #2
0
        int CalculateSteps(string input)
        {
            HexCoords[] dirs = input.Split(',').Select(
                s => HexCoords.Direction(s)).ToArray();
            HexCoords coords = new HexCoords();
            int       max    = 0;

            foreach (HexCoords dir in dirs)
            {
                coords.x += dir.x;
                coords.y += dir.y;
                coords.z += dir.z;
                max       = Math.Max(max, coords.Distance());
            }
            Console.Write("Max: {0}", max);
            return(coords.Distance());
        }