예제 #1
0
 public List<PointField> DoUpdate(bool oneloop = false)
 {
     var list = new List<PointField>();
     while (_newEntries.Count > 0)
     {
         _currentlyChecking = _newEntries.Dequeue();
         var connectedItems = GetConnectedItems(_currentlyChecking);
         if (connectedItems.Count > 1)
         {
             var 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;
 }
예제 #2
0
        private List<Point> GetConnectedItems(GametileUpdate update)
        {
            var list = new List<Point>();
            var x = update.X;
            var 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;
            }
        }
예제 #3
0
        private IEnumerable<LinkedList<AStarSolver<GameField>.PathNode>> handleListOfConnectedPoints(
            List<Point> pointList,
            GametileUpdate update)
        {
            var list = new List<LinkedList<AStarSolver<GameField>.PathNode>>();
            var num = 0;

            {
                foreach (var 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;
            }
        }