Beispiel #1
0
 public bool CollidesWith(CarOverlapData timeWindow)
 {
     if (xposition == timeWindow.xposition)
     {
         return(false);
     }
     return(IsSameAs(timeWindow) ?
            true : OverlapsWith(timeWindow));
 }
Beispiel #2
0
        private bool WillAny3CarsBlockPlayer(List <ACarType> carsWhichCanMoveNow)
        {
            // box in which 3 cars shouldn't be present simultaneously
            var miny = player.position.y - bufferInYaxis.value;
            var maxy = player.position.y + bufferInYaxis.value;

            // in this dictionary, for any key, value shouldn't be 3 or more
            Dictionary <string, int> KcarName_VnumberOfOverlaps = new Dictionary <string, int>();

            List <CarOverlapData> timeWindows = new List <CarOverlapData>();

            foreach (var car in carsWhichCanMoveNow.Union(carsWhichCanMove.Values))
            {
                // 1. in game cars are moving downwards
                // 2. miny is calculated by subtracting from player's position.
                // this means that miny is actually the maximum distance for car.
                // and vice-versa
                var minDistanceTheCarNeedsToTravel = Math.Abs(maxy - car.transform.position.y);
                var maxDistanceTheCarNeedsToTravel = Math.Abs(miny - car.transform.position.y);

                // this is the time window for which car would be in the box
                // 3 of these windows shouldn't overlap.
                var minTime       = minDistanceTheCarNeedsToTravel / car.Speed;
                var maxTime       = maxDistanceTheCarNeedsToTravel / car.Speed;
                var newTimeWindow = new CarOverlapData
                {
                    id        = car.Name,
                    xposition = car.transform.position.x,
                    max       = maxTime,
                    min       = minTime
                };

                foreach (var timeWindow in timeWindows)
                {
                    if (!newTimeWindow.CollidesWith(timeWindow))
                    {
                        continue;
                    }
                    if (!KcarName_VnumberOfOverlaps.ContainsKey(timeWindow.id))
                    {
                        KcarName_VnumberOfOverlaps.Add(timeWindow.id, 0);
                    }
                    KcarName_VnumberOfOverlaps[timeWindow.id]++;
                    if (KcarName_VnumberOfOverlaps[timeWindow.id] >= 3)
                    {
                        return(true);
                    }
                }

                timeWindows.Add(newTimeWindow);
            }

            return(false);
        }
Beispiel #3
0
            public bool OverlapsWith(CarOverlapData timeWindow)
            {
                if (max > timeWindow.min && max <= timeWindow.max)
                {
                    return(true);
                }

                if (min >= timeWindow.min && min < timeWindow.max)
                {
                    return(true);
                }

                return(false);
            }
Beispiel #4
0
 public bool IsSameAs(CarOverlapData timeWindow)
 {
     return(min == timeWindow.min && max == timeWindow.max);
 }