/[projects]/queensgui/src/solutionmatrix.cpp
ViewVC logotype

Contents of /queensgui/src/solutionmatrix.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (show annotations) (download)
Fri Jul 20 16:58:04 2007 UTC (16 years, 9 months ago) by torben
File size: 2840 byte(s)
* SolutionMatrix.{h|cpp}: cleanup clean
* SolutionInt.{h|cpp}: cleanup and finally made rotate90() work correctly
* QueensMain.cpp: minor visual corrections to pop-up menu


1 /***************************************************************************
2 * Copyright (C) 2005 by Torben Nielsen *
3 * torben@t-hoerup.dk *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21 #include "solutionmatrix.h"
22
23 SolutionMatrix::SolutionMatrix(int size)
24 {
25 m_size = size;
26 for (int i=0; i<m_size; i++)
27 for (int j=0; j<m_size; j++)
28 m_matrix[i][j] = false;
29 }
30
31
32 SolutionMatrix::~SolutionMatrix()
33 {
34 }
35
36
37 SolutionMatrix::SolutionMatrix(const SolutionMatrix& input)
38 : Solution()
39 {
40 m_size = input.m_size;
41 for (int i=0; i<m_size; i++)
42 for (int j=0; j<m_size; j++)
43 m_matrix[i][j] = input.m_matrix[i][j];
44 }
45
46
47 void SolutionMatrix::set(bool input[MAX_SIZE][MAX_SIZE])
48 {
49 for (int i=0; i<m_size; i++)
50 for (int j=0; j<m_size; j++)
51 m_matrix[i][j] = input[i][j];
52 }
53
54
55 void SolutionMatrix::rotate90()
56 {
57 bool temp[MAX_SIZE][MAX_SIZE];
58
59 for (int i=0; i<m_size; i++)
60 for (int j=0; j<m_size; j++) {
61 temp[j][(m_size-1)-i] = m_matrix[i][j];
62 }
63 set(temp);
64 }
65
66 void SolutionMatrix::mirror()
67 {
68 bool temp[MAX_SIZE][MAX_SIZE];
69
70 for (int i=0; i<m_size; i++)
71 for (int j=0; j<m_size;j++)
72 temp[i][(m_size-1)-j] = m_matrix[i][j];
73 set(temp);
74 }
75
76
77 bool SolutionMatrix::operator==(const Solution& s)
78 {
79 const SolutionMatrix& sol = dynamic_cast<const SolutionMatrix&>(s);
80
81 for (int i=0; i<m_size; i++)
82 for (int j=0; j<m_size; j++)
83 if (m_matrix[i][j] != sol.m_matrix[i][j])
84 return false;
85 return true;
86 }
87
88 bool SolutionMatrix::getMatrix(int x, int y) {
89 return m_matrix[x][y];
90 }
91
92 void SolutionMatrix::setMatrix(int x, int y, bool val) {
93 m_matrix[x][y] = val;
94 }
95
96
97 Solution* SolutionMatrix::copy()
98 {
99 return new SolutionMatrix(*this);
100 }

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20