public void ClearValue(int x, int y) { // Clear the specified value _digits[x, y].ClearValue(); // Create a new board to apply all the exclusions properly (vs. attempting to undo them) var board = new Board(this); // Take over the new board's digits _digits = board._digits; }
public static Board FromString(string basis) { // Create a new board from an 81-character string that specifies the board's values left-to-right, top-to-bottom var board = new Board(); int i = 0; for (var y = 0; y < Size; y++) { for (var x = 0; x < Size; x++) { if (' ' != basis[i]) { board.SetValue(x, y, basis[i] - '0', Digit.Kind.Given); } i++; } } return board; }
private void Initialize(Board basis) { // Initialize each digit _digits = new Digit[Size, Size]; for (var y = 0; y < Size; y++) { for (var x = 0; x < Size; x++) { _digits[x, y] = new Digit(); } } if (null != basis) { // Copy the digits of the specified board for (var y = 0; y < Size; y++) { for (var x = 0; x < Size; x++) { var digit = basis.GetDigit(x, y); if (digit.ValueKnown) { SetValue(x, y, digit.KnownValue, digit.DigitKind); } } } } }
public Board(Board basis) { // Copy specified board Initialize(basis); }
private void UpdateDisplay(Board board) { // Update the value and candidate numbers according to the specified board for (var y = 0; y < Board.Size; y++) { for (var x = 0; x < Board.Size; x++) { var digit = board.GetDigit(x, y); _values[x, y].Text = (digit.ValueKnown ? digit.KnownValue.ToString() : " "); for (var z = 0; z < 9; z++) { _candidates[x, y, z].Text = (digit.ValueKnown ? " " : (digit.CouldBe(z + 1) ? (z + 1).ToString() : " ")); } } } // Incorporate the specified board and layout _board = board; Layout(); }