* Added SudokuField::IsEmpty() method.

* The window now automatically generates a new sudoku if empty on start.
* Made SudokuField::IsSolved() const.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35519 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2010-02-19 09:16:11 +00:00
parent 73cb8df07e
commit 2b9ec0a9aa
3 changed files with 24 additions and 4 deletions

View File

@ -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)
{

View File

@ -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

View File

@ -288,6 +288,9 @@ SudokuWindow::SudokuWindow()
fProgressWindow = new ProgressWindow(this,
new BMessage(kMsgAbortSudokuGenerator));
if (fSudokuView->Field()->IsEmpty())
PostMessage(kMsgGenerateSudoku);
}