Exemplo n.º 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;
        }
Exemplo n.º 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());
        }
Exemplo n.º 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 },
            });
        }
Exemplo n.º 4
0
 private void PrintIfWatchingCell(Board.Cell cell, Board board)
 => boardPrinter.Print(board);
Exemplo n.º 5
0
 private void LogCellMove(Board.Cell cell, string message)
 => feedback.Information($"{message} (Cell: {cell.ParentParentSection.X},{cell.ParentParentSection.Y}/{cell.X},{cell.Y})");
Exemplo n.º 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);
Exemplo n.º 7
0
 public static IEnumerable <Board.Cell> GetAllCellsInSection(this Board board, Board.Cell cell)
 => GetAllCellsInSection(cell.ParentParentSection);
Exemplo n.º 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);
Exemplo n.º 9
0
 protected virtual void WriteCellValue(Board.Cell cell, string value)
 {
     Write(value);
 }