diff --git a/src/apps/sudoku/SudokuView.cpp b/src/apps/sudoku/SudokuView.cpp index c26e2f9b22..87ba676d0e 100644 --- a/src/apps/sudoku/SudokuView.cpp +++ b/src/apps/sudoku/SudokuView.cpp @@ -1130,6 +1130,8 @@ SudokuView::_ToggleValue(uint32 x, uint32 y, uint32 value, uint32 field) fField->SetValueAt(x, y, value + 1); BMessenger(this).SendMessage(kMsgCheckSolved); + _RemoveHintValues(x, y, value); + // allow dragging to remove the hint from other fields fLastHintValueSet = false; fLastHintValue = value; @@ -1172,6 +1174,44 @@ SudokuView::_ToggleHintValue(uint32 x, uint32 y, uint32 hintX, uint32 hintY, } +void +SudokuView::_RemoveHintValues(uint32 atX, uint32 atY, uint32 value) +{ + // Remove all hints in the same block + uint32 blockSize = fField->BlockSize(); + uint32 blockX = (atX / blockSize) * blockSize; + uint32 blockY = (atY / blockSize) * blockSize; + uint32 valueMask = 1UL << value; + + for (uint32 y = blockY; y < blockY + blockSize; y++) { + for (uint32 x = blockX; x < blockX + blockSize; x++) { + if (x != atX && y != atY) + _RemoveHintValue(x, y, valueMask); + } + } + + // Remove all hints from the vertical and horizontal lines + + for (uint32 i = 0; i < fField->Size(); i++) { + if (i != atX) + _RemoveHintValue(i, atY, valueMask); + if (i != atY) + _RemoveHintValue(atX, i, valueMask); + } +} + + +void +SudokuView::_RemoveHintValue(uint32 x, uint32 y, uint32 valueMask) +{ + uint32 hintMask = fField->HintMaskAt(x, y); + if ((hintMask & valueMask) != 0) { + fField->SetHintMaskAt(x, y, hintMask & ~valueMask); + _InvalidateField(x, y); + } +} + + void SudokuView::_SetAllHints() { diff --git a/src/apps/sudoku/SudokuView.h b/src/apps/sudoku/SudokuView.h index 5929fe5a41..c0d00ede58 100644 --- a/src/apps/sudoku/SudokuView.h +++ b/src/apps/sudoku/SudokuView.h @@ -111,6 +111,10 @@ private: void _ToggleHintValue(uint32 x, uint32 y, uint32 hintX, uint32 hintY, uint32 value, uint32 field); + void _RemoveHintValues(uint32 atX, uint32 atY, + uint32 value); + void _RemoveHintValue(uint32 x, uint32 y, + uint32 valueMask); void _SetAllHints(); void _Solve(); void _SolveSingle();