private void AddPossibleValues(Board board, Board.Cell cell, IReadOnlyCollection <Board.Cell> cells) { var cellSolveData = new CellSolveData(); foreach (var value in GetAllValues(board)) { if (!cells.Any(c => c.Value.HasValue && c.Value == value) && cellSolveData.PossibleValues.All(p => p != value)) { cellSolveData.PossibleValues.Add(value); } } allCellData[cell.CellId] = cellSolveData; }
private void BuildPossibleValuesForCell(Board board, Board.Cell cell) { if (cell.Value.HasValue) { return; } var cellsInRow = board.GetCellsInRow(cell); var cellsInColumn = board.GetCellsInColumn(cell); var cellsInSection = board.GetAllCellsInSection(cell); var allRelevantCells = cellsInRow.Concat(cellsInColumn).Concat(cellsInSection).Distinct(); AddPossibleValues(board, cell, allRelevantCells.ToArray()); }
private void ApplyInitialValue(Board targetBoard, Board.Cell sourceCell, int sectionX, int sectionY, int cellX, int cellY) { if (!sourceCell.Value.HasValue) { return; } var targetCell = targetBoard.Sections[sectionX, sectionY].Cells[cellX, cellY]; targetCell.SetFixedValue(sourceCell.Value.Value); feedback.Information($"Initial value set to {sourceCell.Value}", new Dictionary <string, object> { { "Section X", sectionX }, { "Section Y", sectionY }, { "Cell X", cellX }, { "Cell Y", cellY }, { "Initial Value", sourceCell.Value }, }); }
private void PrintIfWatchingCell(Board.Cell cell, Board board) => boardPrinter.Print(board);
private void LogCellMove(Board.Cell cell, string message) => feedback.Information($"{message} (Cell: {cell.ParentParentSection.X},{cell.ParentParentSection.Y}/{cell.X},{cell.Y})");
public static IEnumerable <Board.Cell> GetCellsInColumn(this Board board, Board.Cell cell) => board.GetAllCells() .Where(c => c.X == cell.X && c.ParentParentSection.X == cell.ParentParentSection.X);
public static IEnumerable <Board.Cell> GetAllCellsInSection(this Board board, Board.Cell cell) => GetAllCellsInSection(cell.ParentParentSection);
public static IEnumerable <Board.Cell> GetCellsInRow(this Board board, Board.Cell cell) => board.GetAllCells() .Where(c => c.Y == cell.Y && c.ParentParentSection.Y == cell.ParentParentSection.Y);
protected virtual void WriteCellValue(Board.Cell cell, string value) { Write(value); }