diff --git a/src/apps/sudoku/SudokuField.cpp b/src/apps/sudoku/SudokuField.cpp index 286adf5bff..62a3ddcd54 100644 --- a/src/apps/sudoku/SudokuField.cpp +++ b/src/apps/sudoku/SudokuField.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2007-2010, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. */ @@ -224,7 +224,7 @@ SudokuField::Dump() bool -SudokuField::IsSolved() +SudokuField::IsSolved() const { for (uint32 y = 0; y < fSize; y++) { for (uint32 x = 0; x < fSize; x++) { @@ -237,6 +237,20 @@ SudokuField::IsSolved() } +bool +SudokuField::IsEmpty() const +{ + for (uint32 y = 0; y < fSize; y++) { + for (uint32 x = 0; x < fSize; x++) { + if (ValueAt(x, y) != 0) + return false; + } + } + + return true; +} + + void SudokuField::SetHintMaskAt(uint32 x, uint32 y, uint32 hintMask) { diff --git a/src/apps/sudoku/SudokuField.h b/src/apps/sudoku/SudokuField.h index 10e84f0921..bd270e30bb 100644 --- a/src/apps/sudoku/SudokuField.h +++ b/src/apps/sudoku/SudokuField.h @@ -1,5 +1,5 @@ /* - * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2007-2010, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. */ #ifndef SUDOKU_FIELD_H @@ -14,6 +14,7 @@ enum { kInitialValue = 0x01, }; + class SudokuField : public BArchivable { public: SudokuField(uint32 size); @@ -30,7 +31,8 @@ public: void SetTo(const SudokuField* other); void Reset(); - bool IsSolved(); + bool IsSolved() const; + bool IsEmpty() const; uint32 Size() const { return fSize; } uint32 BlockSize() const { return fBlockSize; } @@ -71,4 +73,5 @@ private: field* fFields; }; + #endif // SUDOKU_FIELD_H diff --git a/src/apps/sudoku/SudokuWindow.cpp b/src/apps/sudoku/SudokuWindow.cpp index a7365cd1b0..9768b6fea1 100644 --- a/src/apps/sudoku/SudokuWindow.cpp +++ b/src/apps/sudoku/SudokuWindow.cpp @@ -288,6 +288,9 @@ SudokuWindow::SudokuWindow() fProgressWindow = new ProgressWindow(this, new BMessage(kMsgAbortSudokuGenerator)); + + if (fSudokuView->Field()->IsEmpty()) + PostMessage(kMsgGenerateSudoku); }