Example #1
0
        static HexCoordinate Parse(string line)
        {
            Queue <char>  tokens = new Queue <char>(line);
            HexCoordinate hex    = new HexCoordinate(0, 0, 0);

            while (tokens.Count > 0)
            {
                char token = tokens.Dequeue();
                switch (token)
                {
                case 'e':
                    hex = hex.Add(East);
                    break;

                case 'w':
                    hex = hex.Add(West);
                    break;

                case 'n':
                    token = tokens.Dequeue();
                    hex   = hex.Add(token == 'w' ? NorthWest : NorthEast);
                    break;

                case 's':
                    token = tokens.Dequeue();
                    hex   = hex.Add(token == 'w' ? SouthWest : SouthEast);
                    break;

                default:
                    throw new FormatException("Invalid hex string");
                }
            }

            return(hex);
        }
Example #2
0
        static IEnumerable <HexCoordinate> Neighbors(this HexCoordinate hex)
        {
            yield return(hex.Add(East));

            yield return(hex.Add(West));

            yield return(hex.Add(NorthEast));

            yield return(hex.Add(NorthWest));

            yield return(hex.Add(SouthEast));

            yield return(hex.Add(SouthWest));
        }