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; }
public override IEnumerable<CrosswordQuestion> GetQuestionsForCell(CrosswordCell cell) { yield return _horizontalQuestions[cell.RowIndex]; yield return _verticalQuestions[cell.ColumnIndex]; }
public override char GetCellCharacter(CrosswordCell cell) { return _field[cell.RowIndex, cell.ColumnIndex]; }
public override void ApplyCharacter(CrosswordCell cell, char c) { _field[cell.RowIndex, cell.ColumnIndex] = c; }
public abstract void ApplyCharacter(CrosswordCell cell, char c);
public abstract IEnumerable<CrosswordQuestion> GetQuestionsForCell(CrosswordCell cell);
public abstract char GetCellCharacter(CrosswordCell cell);