Beispiel #1
0
        public List<PointField> DoUpdate(bool oneloop = false)
        {
            List<PointField> list = new List<PointField>();

            while (_newEntries.Count > 0)
            {
                _currentlyChecking = _newEntries.Dequeue();

                List<Point> connectedItems = GetConnectedItems(_currentlyChecking);

                if (connectedItems.Count > 1)
                {
                    IEnumerable<LinkedList<AStarSolver<GameField>.XPathNode>> list2 = HandleListOfConnectedPoints(connectedItems, _currentlyChecking);

                    list.AddRange(list2.Where(current => current.Count >= 4).Select(FindClosed).Where(pointField => true));
                }

                _currentField[_currentlyChecking.Y, _currentlyChecking.X] = _currentlyChecking.Value;
            }

            return list;
        }
Beispiel #2
0
        private List<Point> GetConnectedItems(GametileUpdate update)
        {
            List<Point> list = new List<Point>();
            int x = update.X;
            int y = update.Y;

            if (_diagonal)
            {
                if (this[y - 1, x - 1] && _currentField[y - 1, x - 1] == update.Value)
                    list.Add(new Point(x - 1, y - 1));

                if (this[y - 1, x + 1] && _currentField[y - 1, x + 1] == update.Value)
                    list.Add(new Point(x + 1, y - 1));

                if (this[y + 1, x - 1] && _currentField[y + 1, x - 1] == update.Value)
                    list.Add(new Point(x - 1, y + 1));

                if (this[y + 1, x + 1] && _currentField[y + 1, x + 1] == update.Value)
                    list.Add(new Point(x + 1, y + 1));
            }

            if (this[y - 1, x] && _currentField[y - 1, x] == update.Value)
                list.Add(new Point(x, y - 1));

            if (this[y + 1, x] && _currentField[y + 1, x] == update.Value)
                list.Add(new Point(x, y + 1));

            if (this[y, x - 1] && _currentField[y, x - 1] == update.Value)
                list.Add(new Point(x - 1, y));

            if (this[y, x + 1] && _currentField[y, x + 1] == update.Value)
                list.Add(new Point(x + 1, y));

            return list;
        }
Beispiel #3
0
        private IEnumerable<LinkedList<AStarSolver<GameField>.XPathNode>> HandleListOfConnectedPoints(List<Point> pointList, GametileUpdate update)
        {
            List<LinkedList<AStarSolver<GameField>.XPathNode>> list = new List<LinkedList<AStarSolver<GameField>.XPathNode>>();
            int num = 0;

            foreach (Point current in pointList)
            {
                num++;

                if (num == pointList.Count / 2 + 1)
                    return list;

                list.AddRange(
                    pointList.Where(current2 => !(current == current2))
                        .Select(current2 => _astarSolver.Search(current2, current))
                        .Where(linkedList => linkedList != null));
            }

            return list;
        }