17 |
* Free Software Foundation, Inc., * |
* Free Software Foundation, Inc., * |
18 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 |
***************************************************************************/ |
***************************************************************************/ |
20 |
#ifndef SOLUTION_H |
#ifndef SOLUTIONINT_H |
21 |
#define SOLUTION_H |
#define SOLUTIONINT_H |
22 |
|
|
23 |
|
//#include <solution.h> |
24 |
#include "config.h" |
#include "config.h" |
25 |
|
|
26 |
/** |
class Solution |
|
@author Torben Nielsen |
|
|
*/ |
|
|
class Solution |
|
27 |
{ |
{ |
28 |
public: |
public: |
29 |
virtual ~Solution() {} |
Solution(int size); |
30 |
|
|
31 |
|
~Solution(); |
32 |
|
|
33 |
|
//bool getMatrix(int x, int y); |
34 |
|
bool getMatrix(int x, int y) { |
35 |
|
return (m_matrix[x] == y); |
36 |
|
} |
37 |
|
|
38 |
|
|
39 |
|
//void setMatrix(int x, int y, bool val); |
40 |
|
void setMatrix(int x, int y, bool val) { |
41 |
|
if (val == true) |
42 |
|
m_matrix[x] = y; |
43 |
|
else |
44 |
|
m_matrix[x] = -1; |
45 |
|
} |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
//bool operator ==(const Solution& sol); |
50 |
|
bool operator ==(const Solution& s) |
51 |
|
{ |
52 |
|
const Solution& sol = dynamic_cast<const Solution&>(s); |
53 |
|
for (int i=0; i<m_size; i++) |
54 |
|
if (m_matrix[i] != sol.m_matrix[i]) |
55 |
|
return false; |
56 |
|
return true; |
57 |
|
} |
58 |
|
|
59 |
|
Solution* copy(); |
60 |
|
|
61 |
|
//void mirror(); |
62 |
|
void mirror() { |
63 |
|
unsigned char temp[MAX_SIZE]; |
64 |
|
for (int i=0; i<m_size; i++) |
65 |
|
temp[i] = (m_size-1) - m_matrix[i]; |
66 |
|
set( temp ); |
67 |
|
} |
68 |
|
|
69 |
|
//void rotate90(); |
70 |
|
void rotate90() { |
71 |
|
unsigned char temp[MAX_SIZE]; |
72 |
|
for (int i=0; i<m_size; i++) { |
73 |
|
int x = i; |
74 |
|
int y = m_matrix[i]; |
75 |
|
temp[y] = (m_size-1) - x; |
76 |
|
} |
77 |
|
set( temp); |
78 |
|
} |
79 |
|
|
|
virtual void rotate90() = 0; |
|
|
virtual void mirror() = 0; |
|
|
|
|
|
virtual Solution* copy() = 0; |
|
|
|
|
|
virtual bool operator==(const Solution& sol) = 0; |
|
|
//virtual bool operator!=(const Solution& sol) = 0; |
|
|
virtual bool getMatrix(int x, int y) = 0; |
|
|
virtual void setMatrix(int x, int y, bool val) = 0; |
|
80 |
|
|
81 |
int size() {return m_size;}; |
int size() {return m_size;}; |
82 |
void setSize(int size) {m_size = size;}; |
void setSize(int size) {m_size = size;}; |
83 |
|
private: |
84 |
void print(); |
explicit Solution(const Solution& input); |
85 |
void print(bool debug, int row, int col); |
//void set(unsigned char[MAX_SIZE]); |
86 |
|
void set(unsigned char input[MAX_SIZE]) { |
87 |
|
for (int i=0; i<m_size; i++) |
88 |
|
m_matrix[i] = input[i]; |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
unsigned char m_matrix[MAX_SIZE]; |
94 |
protected: |
protected: |
95 |
int m_size; |
int m_size; |
96 |
Solution& operator=(Solution& s); |
|
97 |
}; |
}; |
98 |
|
|
99 |
#endif |
#endif |