示例#1
0
        public void Should_return_the_right_direction()
        {
            HexCoords NECoord  = new HexCoords(1, -1);
            HexCoords ECoord   = new HexCoords(1, 0);
            HexCoords SECoord  = new HexCoords(0, 1);
            HexCoords SWCoord  = new HexCoords(-1, 1);
            HexCoords WCoord   = new HexCoords(-1, 0);
            HexCoords NWCoord  = new HexCoords(0, -1);
            HexCoords coords   = HexCoords.Zero;
            var       neighbor = coords.Direction(HexDirection.NE);

            Assert.AreEqual(NECoord, neighbor);

            neighbor = coords.Direction(HexDirection.E);
            Assert.AreEqual(ECoord, neighbor);

            neighbor = coords.Direction(HexDirection.SE);
            Assert.AreEqual(SECoord, neighbor);

            neighbor = coords.Direction(HexDirection.SW);
            Assert.AreEqual(SWCoord, neighbor);

            neighbor = coords.Direction(HexDirection.W);
            Assert.AreEqual(WCoord, neighbor);

            neighbor = coords.Direction(HexDirection.NW);
            Assert.AreEqual(NWCoord, 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());
        }