Пример #1
0
        public SeatNode GetSeatFor(Person person)
        {
            SeatNode rv = null;

            List <SeatNode> nodesToVisit = new List <SeatNode>
            {
                head
            };

            var visitedNodes = new List <SeatNode>();

            while (nodesToVisit.Count > 0)
            {
                var currentNode = nodesToVisit[0];
                visitedNodes.Add(currentNode);
                if (currentNode.IsSeated(person))
                {
                    rv = currentNode;
                    break;
                }
                else
                {
                    for (int i = 0; i < currentNode.connectedSeats.Count; ++i)
                    {
                        var connectedNode = currentNode.connectedSeats[i];

                        // Add connected node if we haven't already visited it
                        bool alreadyVisited = false;
                        for (int j = 0; j < visitedNodes.Count; ++j)
                        {
                            if (visitedNodes[j] == connectedNode)
                            {
                                alreadyVisited = true;
                                break;
                            }
                        }

                        if (!alreadyVisited)
                        {
                            nodesToVisit.Add(connectedNode);
                        }
                    }
                    nodesToVisit.RemoveAt(0);
                }
            }

            return(rv);
        }
Пример #2
0
 private void Start()
 {
     seatNode = new _2020Vision.SeatNode(this);
 }