Esempio n. 1
0
        public void Test_1()
        {
            var gridStr =
                @"None|Blue|Blue|Blue|Blue|Blue|None
4
R:R|R:B|R:R|R:B|R:R|R:B|R:R
R:R|R:B|R:R|R:L|R:L|R:L|R:R
R:G|R:D|R:G|R:D|R:G|R:L|R:G
R:L|R:L|R:L|R:L|R:G|R:L|R:G
R:R|R:L|R:L|R:L|R:R|R:B|R:R";
            var grid = GridGenerator.GetGrid(gridStr);
            // var swaps = GridAnalyzer.GetPossibleSwaps(grid);
            var killed = GridAnalyzer.GetGeneratedCells(new List <CellItem>()
            {
                grid[0, 3],
                grid[1, 3],
                grid[1, 4],
                grid[2, 3],
                grid[2, 4],
                grid[3, 1],
                grid[3, 3],
                grid[3, 4],
                grid[3, 1],
                grid[4, 1],
                grid[5, 1],
                grid[5, 2],
                grid[5, 3]
            });
        }
Esempio n. 2
0
        public CollapseResult Collapse(List <CellItem> additional = null, List <CellItem> generated = null)
        {
            if (generated == null)
            {
                generated = new List <CellItem>();
            }
            if (additional == null)
            {
                additional = new List <CellItem>();
            }
            var collapsing = GetCollapsingCells();
            var inCollapse = new List <CellItem>();

            foreach (var cellItem in collapsing)
            {
                inCollapse.AddRange(ActionFactory.GetBehaviour(cellItem).Action(SwapType.Kill, inCollapse.ToList()));
            }
            var result   = inCollapse.Union(additional).Distinct().ToList();
            var newItems = GridAnalyzer.GetGeneratedCells(result);

            generated.AddRange(newItems);
            foreach (var cellItem in result)
            {
                this[cellItem.Position.X, cellItem.Position.Y] = null;
            }
            foreach (var cellItem in newItems)
            {
                this[cellItem.Position.X, cellItem.Position.Y] = cellItem;
            }

            for (int i = 0; i < Width; i++)
            {
                for (int j = 1; j < Height; j++)
                {
                    var moveUp = j;
                    while (moveUp > 0 && this[i, moveUp] != null && this[i, moveUp - 1] == null)
                    {
                        this[i, moveUp - 1] = this[i, moveUp];
                        this[i, moveUp]     = null;
                        moveUp--;
                    }
                }
            }

            var ret = new CollapseResult(Width);

            ret.Append(result);
            return(ret);
        }