Example #1
0
        private void TerminateGroup(Group group)
        {
            foreach (var cell in group.Cells)
            {
                var column = field[cell.X];
                column.Remove(cell);
                for (int i = cell.Y; i < column.Count; i++)
                {
                    column[i].SetY(i);
                }
            }

            group.OnTerminate();
        }
Example #2
0
 public bool CanTerminate(Group group)
 {
     return group.StarsCount >= minStars;
 }
Example #3
0
        private IEnumerable<Group> RebuildGroups()
        {
            foreach (var colomn in field)
            {
                foreach (var cell in colomn)
                {
                    cell.Group = null;
                }
            }

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < field[x].Count; y++)
                {
                    var cell = field[x][y];
                    if (cell.Group != null) continue;

                    var group = new Group(cell);
                    var stack = new Stack<Cell>(GetFilteredCells(cell));

                    while (stack.Count > 0)
                    {
                        var curCell = stack.Pop();
                        group.AddCell(curCell);
                        foreach (var item in GetFilteredCells(curCell))
                        {
                            stack.Push(item);
                        }
                    }

                    group.Cells.ForEach(c => c.UpdateConnections());

                    yield return group;
                }
            }
        }