Beispiel #1
0
        private void UpdateBorder(Point position, Fraction owner, bool deepSearch = true)
        {
            bool isBorder = false;
            SquareRadiusForeach rectangleForeach = new SquareRadiusForeach(position, 1, _grid.Width, _grid.Height);

            rectangleForeach.ForEach((x, y, data) =>
            {
                Point point = new Point(x, y);
                Fraction compareFraction = null;
                if (_territoryLinker.ContainsKey(point))
                {
                    compareFraction = _territoryLinker[point];
                }

                if (compareFraction != owner)
                {
                    isBorder = true;
                }
                if (deepSearch)
                {
                    UpdateBorder(point, compareFraction, false);
                }
            });

            if (isBorder)
            {
                _borders.Add(position);
            }
            else
            {
                _borders.Remove(position);
            }
        }
Beispiel #2
0
        public void FindNeighboredListener(FindNeighboredEvent findNeighbored)
        {
            HashSet <Fraction> _neighboredFraction = new HashSet <Fraction>();
            List <Point>       _neighbors          = new List <Point>();

            SquareRadiusForeach rectangleForeach =
                new SquareRadiusForeach(findNeighbored.Center, 1, _grid.Width, _grid.Height, true);

            rectangleForeach.ForEach((x, y, data) =>
            {
                Point point = new Point(x, y);
                Fraction compareFraction = null;
                if (_territoryLinker.ContainsKey(point))
                {
                    compareFraction = _territoryLinker[point];
                }
                _neighboredFraction.Add(compareFraction);
                _neighbors.Add(point);
            });

            findNeighbored.Neighbors         = _neighbors;
            findNeighbored.NeighborFractions = _neighboredFraction;
            findNeighbored.Success           = true;
        }