Exemplo n.º 1
0
        private void CreateCells(string puzzleString)
        {
            var parsedString = ParseString(puzzleString);

            for (var i = 1; i <= 9; i++)
            {
                Rows.Add(CreateCellCollection(i));
                Columns.Add(CreateCellCollection(i));
                Groups.Add(CreateCellCollection(i));
            }

            for (var i = 0; i < 9; i++)
            {
                for (var j = 0; j < 9; j++)
                {
                    var cell = string.IsNullOrEmpty(puzzleString) ? GetCell(i, j) :
                               GetCell(i, j, parsedString[i, j]);
                    cell.Puzzle = this;
                    Rows[i].Cells.Add(cell);
                    Columns[j].Cells.Add(cell);
                    AllCells.Add(cell);

                    var k = GetGroupIndex(i, j);
                    cell.Location.Group = Groups[k];
                    Groups[k].Cells.Add(cell);
                }
            }
            NonInitialCells = AllCells.Where(cell => !cell.IsInitialCell);
        }
Exemplo n.º 2
0
    public bool HasLegalMove(Board board)
    {
        foreach (var from in AllCells.Where(c => c > 3))
        {
            if (board[from] != White)
            {
                continue;
            }

            if (HasLegalMove(board, from))
            {
                return(true);
            }
        }

        return(false);
    }