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

Contents of /queensgui/src/solutionmatrix.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 655 - (show annotations) (download)
Fri Apr 23 05:57:28 2010 UTC (14 years ago) by torben
File size: 2847 byte(s)
Code sync towards a faster implementation. The key is to avoid virtual functions and inline as many functions as posible
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 /*
22 #include "solutionmatrix.h"
23
24 SolutionMatrix::SolutionMatrix(int size)
25 {
26 m_size = size;
27 for (int i=0; i<m_size; i++)
28 for (int j=0; j<m_size; j++)
29 m_matrix[i][j] = false;
30 }
31
32
33 SolutionMatrix::~SolutionMatrix()
34 {
35 }
36
37
38 SolutionMatrix::SolutionMatrix(const SolutionMatrix& input)
39 : Solution()
40 {
41 m_size = input.m_size;
42 for (int i=0; i<m_size; i++)
43 for (int j=0; j<m_size; j++)
44 m_matrix[i][j] = input.m_matrix[i][j];
45 }
46
47
48 void SolutionMatrix::set(bool input[MAX_SIZE][MAX_SIZE])
49 {
50 for (int i=0; i<m_size; i++)
51 for (int j=0; j<m_size; j++)
52 m_matrix[i][j] = input[i][j];
53 }
54
55
56 void SolutionMatrix::rotate90()
57 {
58 bool temp[MAX_SIZE][MAX_SIZE];
59
60 for (int i=0; i<m_size; i++)
61 for (int j=0; j<m_size; j++) {
62 temp[j][(m_size-1)-i] = m_matrix[i][j];
63 }
64 set(temp);
65 }
66
67 void SolutionMatrix::mirror()
68 {
69 bool temp[MAX_SIZE][MAX_SIZE];
70
71 for (int i=0; i<m_size; i++)
72 for (int j=0; j<m_size;j++)
73 temp[i][(m_size-1)-j] = m_matrix[i][j];
74 set(temp);
75 }
76
77
78 bool SolutionMatrix::operator==(const Solution& s)
79 {
80 const SolutionMatrix& sol = dynamic_cast<const SolutionMatrix&>(s);
81
82 for (int i=0; i<m_size; i++)
83 for (int j=0; j<m_size; j++)
84 if (m_matrix[i][j] != sol.m_matrix[i][j])
85 return false;
86 return true;
87 }
88
89 bool SolutionMatrix::getMatrix(int x, int y) {
90 return m_matrix[x][y];
91 }
92
93 void SolutionMatrix::setMatrix(int x, int y, bool val) {
94 m_matrix[x][y] = val;
95 }
96
97
98 Solution* SolutionMatrix::copy()
99 {
100 return new SolutionMatrix(*this);
101 }
102 */

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20