1 #ifndef __PUZGEN_H__
2 #define __PUZGEN_H__
3 
4 
5 #include <string>
6 #include <list>
7 #include <iostream>
8 #include "iconset.h"
9 
10 
11 #define PUZZLE_SIZE 6
12 
13 
14 typedef short SolvedPuzzle[PUZZLE_SIZE][PUZZLE_SIZE];
15 
16 
17 class Possibilities
18 {
19     private:
20         short pos[PUZZLE_SIZE][PUZZLE_SIZE][PUZZLE_SIZE];
21 
22     public:
23         Possibilities();
24         Possibilities(std::istream &stream);
25 
26     public:
27         void exclude(int col, int row, int element);
28         void set(int col, int row, int element);
29         bool isPossible(int col, int row, int element);
30         bool isDefined(int col, int row);
31         int getDefined(int col, int row);
32         int getPosition(int row, int element);
33         bool isSolved();
34         void print();
35         bool isValid(SolvedPuzzle &puzzle);
36         void makePossible(int col, int row, int element);
37         void save(std::ostream &stream);
38         void reset();
39         void checkSingles(int row);
40 };
41 
42 
43 class Rule
44 {
45     public:
46         typedef enum {
47             SHOW_VERT,
48             SHOW_HORIZ,
49             SHOW_NOTHING
50         } ShowOptions;
51 
52     public:
~Rule()53         virtual ~Rule() { };
54 
55     public:
56         virtual std::wstring getAsText() = 0;
57         virtual bool apply(Possibilities &pos) = 0;
applyOnStart()58         virtual bool applyOnStart() { return false; };
getShowOpts()59         virtual ShowOptions getShowOpts() { return SHOW_NOTHING; };
60         virtual void draw(int x, int y, IconSet &iconSet, bool highlight) = 0;
61         virtual void save(std::ostream &stream) = 0;
62 };
63 
64 
65 typedef std::list<Rule*> Rules;
66 
67 
68 void genPuzzle(SolvedPuzzle &puzzle, Rules &rules);
69 void openInitial(Possibilities &possib, Rules &rules);
70 Rule* genRule(SolvedPuzzle &puzzle);
71 void getHintsQty(Rules &rules, int &vert, int &horiz);
72 Rule* getRule(Rules &rules, int no);
73 
74 void savePuzzle(SolvedPuzzle &puzzle, std::ostream &stream);
75 void loadPuzzle(SolvedPuzzle &puzzle, std::istream &stream);
76 void saveRules(Rules &rules, std::ostream &stream);
77 void loadRules(Rules &rules, std::istream &stream);
78 
79 
80 #endif
81 
82