public static string PrintSudokuResult(SudokuLog sudokuResult) { var sb = new StringBuilder(); PrintSudokuResult(sudokuResult, sb, ""); return(sb.ToString()); }
private static void PrintSudokuResult(SudokuLog sudokuResult, StringBuilder sb, string cap) { sb.Append(cap); sb.Append(sudokuResult.ToString()); foreach (var sr in sudokuResult.ChildSudokuResult) { PrintSudokuResult(sr, sb, cap + " "); } }
public override void SolveHouse(IBoard <C> board, IHouse <C> house, SudokuLog sudokuResult) { // Key = BaseValue, Anz Possible Dictionary <int, List <C> > nakedMore = new Dictionary <int, List <C> >(); foreach (C c in house) { int val = c.CandidateValue; if (!nakedMore.ContainsKey(val)) { nakedMore.Add(val, new List <C>()); } nakedMore[val].Add(c); } foreach (KeyValuePair <int, List <C> > kv in nakedMore) { if (kv.Value.Count > 5) { return; } int count = kv.Value.First().Candidates.Count; if (kv.Value.Count == count) { string st = "Naked" + count; SudokuLog cresult = sudokuResult.CreateChildResult(); cresult.EventInfoInResult = new SudokuEvent { Value = 0, ChangedCellBase = house, Action = CellAction.RemoveCandidate, SolveTechnik = st, }; bool found = false; foreach (C c in house) { if (kv.Value.Contains(c)) { continue; } ICell kvc = kv.Value.First(); foreach (int d in kvc.Candidates) { found |= c.RemoveCandidate(d, cresult); } } if (!found) { sudokuResult.ChildSudokuResult.Remove(cresult); } } } }
/// <summary> /// Set a digit at cell. /// </summary> /// <param name="row">Row Range from 0-8 or 'A'-'I' or 'a'-'i'</param> /// <param name="col">Column</param> /// <param name="digit">Digit</param> public static SudokuLog SetDigit <C>(this IBoard <C> board, int row, int col, int digit) where C : ICell { var currentRow = row; var lowRow = (int)'A'; // 65 if (row >= lowRow) // If row is greater or equal than 65 (ASCII of 'A') the row-value could be a char instead of an int. { currentRow = (int)char.ToUpper((char)row); currentRow -= lowRow; } var sudokuResult = new SudokuLog { EventInfoInResult = new SudokuEvent { ChangedCellBase = null, Action = CellAction.SetDigitInt, SolveTechnik = "SetDigit", } }; if (currentRow < 0 || currentRow > Consts.DIMENSIONSQUARE) { sudokuResult.Successful = false; sudokuResult.ErrorMessage = $"row must be between 1 and {Consts.DIMENSIONSQUARE} or between 'a' and '{((char)(lowRow + Consts.DIMENSIONSQUARE))}'"; return(sudokuResult); } if (col < 0 || col > Consts.DIMENSIONSQUARE) { sudokuResult.Successful = false; sudokuResult.ErrorMessage = $"col must be between 0 and '{Consts.DIMENSIONSQUARE - 1}'"; return(sudokuResult); } if (digit < 1 || digit > Consts.DIMENSIONSQUARE) { sudokuResult.Successful = false; sudokuResult.ErrorMessage = $"digit must be between 0 and '{Consts.DIMENSIONSQUARE - 1}'"; return(sudokuResult); } return(board.SetDigit((currentRow * Consts.DIMENSIONSQUARE) + col, digit)); }
/// <summary> /// Initializes a new instance of the <see cref="SudokuHistoryItem" /> class. /// </summary> /// <remarks>Create a small clone of the board.</remarks> /// <param name="board">Current board</param> /// <param name="cell">Last changed Cell</param> /// <param name="sudokuResult">associated log entry</param> public SudokuHistoryItem(Board board, ICell cell, SudokuLog sudokuResult) { if (cell == null) { CellID = -1; Digit = -1; } else { CellID = cell.ID; Digit = cell.Digit; } SudokuResults = sudokuResult; if (board == null) { Percent = 0; } else { BoardInt = new System.Collections.ObjectModel.ReadOnlyCollection <int>(board.CreateSimpleBoard()); Percent = board.SolvePercent; } }
/// <inheritdoc /> public abstract void SolveHouse(IBoard <C> board, IHouse <C> house, SudokuLog sudokuResult);