예제 #1
0
        private bool Attempt(Crossword crossword, CrosswordCell cell, IDictionary<CrosswordCell, List<char>> unresolvedCells)
        {
            var characters = unresolvedCells[cell];
            var questions = crossword.GetQuestionsForCell(cell).ToArray();
            foreach (var character in characters)
            {
                crossword.ApplyCharacter(cell, character);
                if (!CheckQuestions(crossword, questions))
                {
                    continue;
                }

                if (crossword.GetCells().All(c => crossword.GetCellCharacter(c) != 0))
                {
                    return true;
                }

                foreach (var affectedCell in crossword.GetQuestionsForCell(cell).SelectMany(crossword.GetCellsForQuestion).Where(c => crossword.GetCellCharacter(c) == 0))
                {
                    if (Attempt(crossword, affectedCell, unresolvedCells))
                    {
                        return true;
                    }
                }
            }

            crossword.ApplyCharacter(cell, '\0');
            return false;
        }
예제 #2
0
 public override IEnumerable<CrosswordQuestion> GetQuestionsForCell(CrosswordCell cell)
 {
     yield return _horizontalQuestions[cell.RowIndex];
     yield return _verticalQuestions[cell.ColumnIndex];
 }
예제 #3
0
 public override char GetCellCharacter(CrosswordCell cell)
 {
     return _field[cell.RowIndex, cell.ColumnIndex];
 }
예제 #4
0
 public override void ApplyCharacter(CrosswordCell cell, char c)
 {
     _field[cell.RowIndex, cell.ColumnIndex] = c;
 }
예제 #5
0
 public abstract void ApplyCharacter(CrosswordCell cell, char c);
예제 #6
0
 public abstract IEnumerable<CrosswordQuestion> GetQuestionsForCell(CrosswordCell cell);
예제 #7
0
 public abstract char GetCellCharacter(CrosswordCell cell);