Britbot
static internal List<Location> Britbot.Group.GenerateRingLocations ( Location  pivot,
int  ringOrdinal 
) [inline, static, private]

Get the ring of the specified index relative to the given pivot.

Parameters:
pivotThe ring's center
ringOrdinalthe index of the ring
Exceptions:
InvalidLocationExceptionThis method will throw this exception if a location it generated is not passable
Returns:

Definition at line 660 of file Group.cs.

        {
            //check if the ring index is OK
            if (ringOrdinal < 0)
                throw new InvalidRingException("Ring ordinal must be non-negative");

            //create a list of this ring's locations
            List<Location> ring = new List<Location>(ringOrdinal * 4);
            int a = pivot.Row;
            int b = pivot.Col;

            //this solves the equation I described in the calculations folder
            for (int x = a - ringOrdinal; x <= a + ringOrdinal; x++)
            {
                //first solution
                Location y1 =
                    new Location(x,
                        (int)
                            ((2 * b +
                              Math.Sqrt(4 * Math.Pow(b, 2) +
                                        4 * (Math.Pow(ringOrdinal - Math.Abs(a - x), 2) - Math.Pow(b, 2)))) / 2));

                //if the location is nit passable, throw an expection (caught by the calling function)
                if (!Bot.Game.IsInMap(y1) || !Bot.Game.IsPassable(y1))
                    throw new InvalidLocationException("Location is not passable!");

                //add the location to the ring
                ring.Add(y1);

                //second solution
                Location y2 =
                    new Location(x,
                        (int)
                            ((2 * b -
                              Math.Sqrt(4 * Math.Pow(b, 2) +
                                        4 * (Math.Pow(ringOrdinal - Math.Abs(a - x), 2) - Math.Pow(b, 2)))) / 2));

                //if the location is nit passable, throw an expection (caught by the calling function)
                if (!Bot.Game.IsInMap(y2) || !Bot.Game.IsPassable(y2))
                    throw new InvalidLocationException("Location is not passable!");

                //Check for duplicates
                if (y1.Col != y2.Col || y1.Row != y2.Row)
                    //if the two solution are different, add the second one
                    ring.Add(y2);
            }
            //return the list of location of the ring
            return ring;
        }