1 /* 2 * Copyright 2007-2010, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef SUDOKU_FIELD_H 6 #define SUDOKU_FIELD_H 7 8 9 #include <Archivable.h> 10 #include <SupportDefs.h> 11 12 13 enum { 14 kInitialValue = 0x01, 15 }; 16 17 18 class SudokuField : public BArchivable { 19 public: 20 SudokuField(uint32 size); 21 SudokuField(const BMessage* archive); 22 SudokuField(const SudokuField& other); 23 virtual ~SudokuField(); 24 25 status_t InitCheck(); 26 27 virtual status_t Archive(BMessage* archive, bool deep) const; 28 static SudokuField* Instantiate(BMessage* archive); 29 30 status_t SetTo(char base, const char* data); 31 void SetTo(const SudokuField* other); 32 void Reset(); 33 34 bool IsSolved() const; 35 bool IsEmpty() const; 36 37 uint32 Size() const { return fSize; } 38 uint32 BlockSize() const { return fBlockSize; } 39 40 void SetHintMaskAt(uint32 x, uint32 y, uint32 hintMask); 41 uint32 HintMaskAt(uint32 x, uint32 y) const; 42 43 void SetValidMaskAt(uint32 x, uint32 y, uint32 validMask); 44 uint32 ValidMaskAt(uint32 x, uint32 y) const; 45 46 void SetFlagsAt(uint32 x, uint32 y, uint32 flags); 47 uint32 FlagsAt(uint32 x, uint32 y) const; 48 49 void SetValueAt(uint32 x, uint32 y, uint32 value, bool setSolved = false); 50 uint32 ValueAt(uint32 x, uint32 y) const; 51 52 void Dump(); 53 54 private: 55 struct field { 56 field(); 57 58 uint32 hint_mask; 59 uint32 valid_mask; 60 uint32 flags; 61 uint32 value; 62 }; 63 64 bool _ValidValueAt(uint32 x, uint32 y) const; 65 void _ComputeValidMask(uint32 x, uint32 y, bool setSolved); 66 void _UpdateValidMaskChanged(uint32 x, uint32 y, bool setSolved); 67 const field& _FieldAt(uint32 x, uint32 y) const; 68 field& _FieldAt(uint32 x, uint32 y); 69 70 uint32 fSize; 71 uint32 fBlockSize; 72 uint32 fMaxMask; 73 field* fFields; 74 }; 75 76 77 #endif // SUDOKU_FIELD_H 78