示例#1
0
        private List <List <CellState> > FindSolution(WorkingCopy assignments, Nonogram n, List <List <List <CellState> > > cellStates)
        {
            int nullIndex = assignments.AssignedRows.FindIndex(x => x == null);

            if (nullIndex < 0)
            {
                if (!containsErrors(assignments, n))
                {
                    return(assignments.AssignedRows);
                }
                else
                {
                    return(null);
                }
            }
            var rowVariants = cellStates[nullIndex];
            var workingCopy = assignments.Clone() as WorkingCopy;

            foreach (var value in rowVariants)
            {
                workingCopy.AssignedRows[nullIndex] = value;
                if (containsErrors(assignments, n))
                {
                    continue;
                }
                var resultsSearch = FindSolution(workingCopy, n, cellStates);
                if (resultsSearch != null)
                {
                    return(resultsSearch);
                }
            }
            return(null);
        }