1 /* 2 * Copyright 2007-2012, 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 bool IsValueCompleted(uint32 value) const; 37 Size()38 uint32 Size() const { return fSize; } BlockSize()39 uint32 BlockSize() const { return fBlockSize; } 40 41 void SetHintMaskAt(uint32 x, uint32 y, 42 uint32 hintMask); 43 uint32 HintMaskAt(uint32 x, uint32 y) const; 44 bool HasHint(uint32 x, uint32 y, uint32 value) const; 45 46 void SetValidMaskAt(uint32 x, uint32 y, 47 uint32 validMask); 48 uint32 ValidMaskAt(uint32 x, uint32 y) const; 49 bool IsValid(uint32 x, uint32 y, uint32 value) const; 50 51 void SetFlagsAt(uint32 x, uint32 y, uint32 flags); 52 uint32 FlagsAt(uint32 x, uint32 y) const; 53 bool IsInitialValue(uint32 x, uint32 y) const; 54 55 void SetValueAt(uint32 x, uint32 y, uint32 value, 56 bool setSolved = false); 57 uint32 ValueAt(uint32 x, uint32 y) const; 58 59 void Dump(); 60 61 private: 62 struct field { 63 field(); 64 65 uint32 hint_mask; 66 uint32 valid_mask; 67 uint32 flags; 68 uint32 value; 69 }; 70 71 bool _ValidValueAt(uint32 x, uint32 y) const; 72 void _ComputeValidMask(uint32 x, uint32 y, 73 bool setSolved); 74 void _UpdateValidMaskChanged(uint32 x, uint32 y, 75 bool setSolved); 76 const field& _FieldAt(uint32 x, uint32 y) const; 77 field& _FieldAt(uint32 x, uint32 y); 78 79 private: 80 uint32 fSize; 81 uint32 fBlockSize; 82 uint32 fMaxMask; 83 field* fFields; 84 }; 85 86 87 #endif // SUDOKU_FIELD_H 88