示例#1
0
 public void NeighborDistances(
     out int outStartingDistance,
     out int outEndingDistance)
 {
     outStartingDistance = StartingPoint.PrevDistance();
     outEndingDistance   = EndingPoint.NextDistance();
 }
示例#2
0
        public bool WasInjured()
        {
            var theResult = StartingPoint.IsHunted() || EndingPoint.IsHunted();

            if (StartingPoint.IsHunted() && !_injuryRegistry[0])
            {
                _distance         += StartingPoint.PrevDistance();
                _injuryRegistry[0] = true;
            }

            if (EndingPoint.IsHunted() && !_injuryRegistry[1])
            {
                _distance         += EndingPoint.NextDistance();
                _injuryRegistry[1] = true;
            }

            return(theResult);
        }
示例#3
0
        public CPoint Injure(
            CSegmentPool inOwningPool,
            int inPoolIdx)
        {
            CPoint thePointToHunt = null, thePointToInfect = null;
            int    whichEndToHunt = 0; // Init to 'no end'. 1: starting, 2: ending

            // Prefere to depart, so first check if there is any touched points?
            // It's NOT good, because we need to look forward and if there is the possiblility
            //      for moving forward, then try to avoid the point, which was shared by the
            //      prev injured segment!!
            // So if we can move forward ? How we can check about this fact?
            //      (use index to see if this is the last point
            //just check the prev segment and
            // NO No NO!!!!
            // We need to introduce a new concept: InfectedPoint
            //  In a segment, when we haunt an end_point then the other point is 'Infected'
            //      and when we are checking for touch_points, then we choose them only if
            //      it is NOT infected
            if (StartingPoint.IsTouched() && !StartingPoint.IsInfected())
            {
                thePointToHunt   = StartingPoint;
                thePointToInfect = EndingPoint;
                whichEndToHunt   = 1;
            }
            else if (EndingPoint.IsTouched())
            {
                thePointToHunt   = EndingPoint;
                whichEndToHunt   = 2;
                thePointToInfect = StartingPoint;
            }
            else
            {
                // Do the wounding process
                // Look at the neighbors:
                NeighborDistances(out var theStartPrevDist, out var theEndNextDist);
                if (theStartPrevDist == theEndNextDist)
                {
                    // Since the points are sorted, so the starting_point < ending (always!)
                    thePointToHunt   = StartingPoint;
                    whichEndToHunt   = 1;
                    thePointToInfect = EndingPoint;
                }
                else if (theStartPrevDist < theEndNextDist)
                {
                    thePointToHunt   = EndingPoint;
                    whichEndToHunt   = 2;
                    thePointToInfect = StartingPoint;
                }
                else // theStartPrevDist > theEndNextDist
                {
                    thePointToHunt   = StartingPoint;
                    whichEndToHunt   = 1;
                    thePointToInfect = EndingPoint;
                }
            }

            thePointToHunt?.Hunt();
            thePointToInfect?.Infect();

            // Now recalculate the distance, considering the hunted point
            // But what if all two points was haunted?! Hey: The Distance = PrevDist + ThisDist + NextDist
            // Determine the most recently hunted point and then add its relevant neighbor to the distance

            switch (whichEndToHunt)
            {
            case 1:
                _distance         += StartingPoint.PrevDistance();
                _injuryRegistry[0] = true;
                break;


            case 2:
                _distance         += EndingPoint.NextDistance();
                _injuryRegistry[1] = true;
                break;
            }


            return(thePointToHunt);
        }