示例#1
0
        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;
        }
示例#2
0
        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());
        }
示例#3
0
        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 },
            });
        }
示例#4
0
 private void PrintIfWatchingCell(Board.Cell cell, Board board)
 => boardPrinter.Print(board);
示例#5
0
 private void LogCellMove(Board.Cell cell, string message)
 => feedback.Information($"{message} (Cell: {cell.ParentParentSection.X},{cell.ParentParentSection.Y}/{cell.X},{cell.Y})");
示例#6
0
 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);
示例#7
0
 public static IEnumerable <Board.Cell> GetAllCellsInSection(this Board board, Board.Cell cell)
 => GetAllCellsInSection(cell.ParentParentSection);
示例#8
0
 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);
 }