Example #1
0
        public bool Transverse(Stack <Direction> directions, Dictionary <Pos, HexCell> lookup)
        {
            if (directions.Count == 0)
            {
                White = !White;
                return(White);
            }
            else
            {
                var currentDirection = directions.Pop();
                switch (currentDirection)
                {
                case Direction.NE:
                    if (NE is null)
                    {
                        Pos location = new(Pos.X + 1, Pos.Y + 1);
                        NE = lookup.ContainsKey(location) ? lookup[location] : new HexCell(location, true, lookup);
                    }
                    return(NE.Transverse(directions, lookup));

                case Direction.E:
                    if (E is null)
                    {
                        Pos location = new (Pos.X + 2, Pos.Y);
                        E = lookup.ContainsKey(location) ? lookup[location] : new HexCell(location, true, lookup);
                    }
                    return(E.Transverse(directions, lookup));

                case Direction.SE:
                    if (SE is null)
                    {
                        Pos location = new(Pos.X + 1, Pos.Y - 1);
                        SE = lookup.ContainsKey(location) ? lookup[location] : new HexCell(location, true, lookup);
                    }
                    return(SE.Transverse(directions, lookup));

                case Direction.SW:
                    if (SW is null)
                    {
                        Pos location = new(Pos.X - 1, Pos.Y - 1);
                        SW = lookup.ContainsKey(location) ? lookup[location] : new HexCell(location, true, lookup);
                    }
                    return(SW.Transverse(directions, lookup));

                case Direction.W:
                    if (W is null)
                    {
                        Pos location = new(Pos.X - 2, Pos.Y);
                        W = lookup.ContainsKey(location) ? lookup[location] : new HexCell(location, true, lookup);
                    }
                    return(W.Transverse(directions, lookup));

                case Direction.NW:
                    if (NW is null)
                    {
                        Pos location = new(Pos.X - 1, Pos.Y + 1);
                        NW = lookup.ContainsKey(location) ? lookup[location] : new HexCell(location, true, lookup);
                    }
                    return(NW.Transverse(directions, lookup));

                default:
                    return(true);
                }
            }
        }