Britbot
Location Britbot.Group.GetLocation ( ) [inline]

Returns the average location for this group.

Returns:
Returns the average location for this group

Definition at line 184 of file Group.cs.

        {
            //assigning X and Y to hold the sum
            int x = 0;
            int y = 0;

            if (this.Pirates == null)
                this.Pirates = new ObservableCollection<int>();

            foreach (int pirate in this.Pirates)
            {
                x += Bot.Game.GetMyPirate(pirate).Loc.Col;
                y += Bot.Game.GetMyPirate(pirate).Loc.Row;
            }

            try
            {
                return new Location(y / this.Pirates.Count, x / this.Pirates.Count);
            }
            catch (DivideByZeroException) // altough pirates count shouldn't be 0, just in case
            {
                return new Location(0, 0);
            }
        }