Example #1
0
        public string GetAdjacentTeleport()
        {
            var teleport = Teleports.FirstOrDefault(tel => Utilities.CalculateManhattanDistance(tel.Value.Position, Position) == 1);

            if (!teleport.Equals(default(KeyValuePair <Coordinate, Node>)))
            {
                return(TeleportIDs.First(tid => tid.Value.Contains(teleport.Value)).Key);
            }
            else
            {
                return(string.Empty);
            }
        }
Example #2
0
        public Node(int x, int y, NodeType type, char symbol)
        {
            Position = new Coordinate(x, y);
            Type     = type;
            Symbol   = symbol;
            List <Coordinate> sides = GetSides(x, y);

            if (type == NodeType.PATH)
            {
                Field.Add(Position, this);

                foreach (var side in sides)
                {
                    if (Field.ContainsKey(side))
                    {
                        AddEdge(Field[side]);
                    }
                }
            }
            else
            {
                Teleports.Add(Position, this);

                foreach (var side in sides)
                {
                    if (Teleports.ContainsKey(side))
                    {
                        Node teleport = Teleports[side];
                        if (symbol == 'A' && teleport.Symbol == 'A')
                        {
                            Type              = NodeType.START;
                            teleport.Type     = NodeType.START;
                            Soulmate          = teleport;
                            teleport.Soulmate = this;
                        }
                        else if (symbol == 'Z' && teleport.Symbol == 'Z')
                        {
                            Type              = NodeType.END;
                            teleport.Type     = NodeType.END;
                            Soulmate          = teleport;
                            teleport.Soulmate = this;
                        }
                        else
                        {
                            string telId = string.Concat(new[] { symbol, teleport.Symbol });

                            var pair = new List <Node> {
                                this, teleport
                            };
                            if (TeleportIDs.ContainsKey(telId))
                            {
                                TeleportIDs[telId].AddRange(pair);
                            }
                            else
                            {
                                TeleportIDs.Add(telId, pair);
                            }
                        }
                    }
                }
            }
        }