예제 #1
0
        private void correctAgentsCollision(List <Move> preList, ref List <Move> colList /*, ref List<int> addAgentsToDelay*/)
        {
            bool hasCollision = false;

            for (int i = 0; i < colList.Count; i++)
            {
                for (int j = i + 1; j < colList.Count; j++)
                {
                    Move aMove = colList[i];
                    Move bMove = colList[j];
                    if (aMove.IsColliding(bMove))
                    {
                        if (aMove.x == preList[i].x && aMove.y == preList[i].y)
                        {
                            colList[j] = new Move(preList[j]);
                        }
                        else if (bMove.x == preList[j].x && bMove.y == preList[j].y)
                        {
                            colList[i] = new Move(preList[i]);
                        }
                        else
                        {
                            colList[j] = new Move(preList[j]);
                            colList[i] = new Move(preList[i]);
                        }
                        hasCollision = true;
                    }
                }
            }
            if (hasCollision)
            {
                correctAgentsCollision(preList, ref colList);
                return;
            }
        }
예제 #2
0
        private bool checkValidBiasPlan(LinkedList <List <Move> > plan, int bias)
        {
            LinkedListNode <List <Move> > node = plan.First;
            LinkedListNode <List <Move> > biasnode;
            List <Move> biasMove;
            List <Move> cur   = node.Value;
            bool        valid = true;

            for (int i = 0; i < plan.Count; i++)
            {
                for (int j = 0; j < bias + 1; j++)
                {
                    biasnode = node;
                    for (int p = 0; p < j && biasnode.Next != null; p++)
                    {
                        biasnode = biasnode.Next;
                    }
                    biasMove = biasnode.Value;
                    for (int aMove = 0; aMove < plan.First.Value.Count; aMove++)
                    {
                        for (int bMove = 0; bMove < plan.First.Value.Count; bMove++)
                        {
                            if (aMove == bMove)
                            {
                                continue;
                            }
                            Move agent1 = cur[aMove];
                            Move agent2 = biasMove[bMove];
                            if (agent1.IsColliding(agent2))
                            {
                                if (toPrint)
                                {
                                    Console.WriteLine("Agents " + aMove + " and " + bMove + " collides at time " + i + " bias " + j);
                                }
                                valid = false;
                            }
                        }
                    }
                }
                node = node.Next;
                if (node != null)
                {
                    cur = node.Value;
                }
            }
            if (valid)
            {
                if (toPrint)
                {
                    Console.WriteLine("A valid bias plan!");
                }
            }
            else
            {
                //if (toPrint)
                Console.WriteLine("Not a valid bias plan!");
            }
            return(valid);
        }
예제 #3
0
        /// <summary>
        /// Check if this plan collides with another plan at a given time
        /// </summary>
        /// <param name="time">The time at which to check if the collision occured</param>
        /// <param name="otherPlan">The plan to check against</param>
        public bool IsColliding(int time, SinglePlan otherPlan)
        {
            Move thisLocation  = this.GetLocationAt(time);
            Move otherLocation = otherPlan.GetLocationAt(time);

            if (thisLocation.IsColliding(otherLocation) == true) // IsColliding isn't virtual,
                                                                 // so it doesn't matter whether the moves are actually TimedMoves
                                                                 // with incorrect time
            {
                return(true);
            }

            return(false);
        }