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

Annotation of /queensgui/src/solution.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations) (download)
Thu Jul 19 23:44:01 2007 UTC (16 years, 10 months ago) by torben
File size: 2927 byte(s)
Renamed solution{list,vector,hash,nmvector} to container{...}


1 torben 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     #include "solution.h"
21    
22    
23     Solution::Solution(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 torben 4 m_matrix[i][j] = false;
29 torben 1 }
30    
31    
32     Solution::~Solution()
33     {
34     }
35    
36    
37     Solution::Solution(const Solution &input)
38     {
39     m_size = input.m_size;
40     for (int i=0; i<m_size; i++)
41     for (int j=0; j<m_size; j++)
42 torben 4 m_matrix[i][j] = input.m_matrix[i][j];
43 torben 1 }
44    
45    
46     void Solution::set(bool input[MAX_SIZE][MAX_SIZE])
47     {
48     for (int i=0; i<m_size; i++)
49     for (int j=0; j<m_size; j++)
50 torben 4 m_matrix[i][j] = input[i][j];
51 torben 1 }
52    
53    
54     void Solution::rotate90()
55     {
56     bool temp[MAX_SIZE][MAX_SIZE];
57    
58     for (int i=0; i<m_size; i++)
59     for (int j=0; j<m_size; j++) {
60 torben 4 temp[j][(m_size-1)-i] = m_matrix[i][j];
61 torben 1 }
62     set(temp);
63     }
64    
65     void Solution::mirror()
66     {
67     bool temp[MAX_SIZE][MAX_SIZE];
68    
69     for (int i=0; i<m_size; i++)
70     for (int j=0; j<m_size;j++)
71 torben 4 temp[i][(m_size-1)-j] = m_matrix[i][j];
72 torben 1 set(temp);
73     }
74    
75    
76     bool Solution::operator==(const Solution& sol)
77     {
78     for (int i=0; i<m_size; i++)
79     for (int j=0; j<m_size; j++)
80 torben 4 if (m_matrix[i][j] != sol.m_matrix[i][j])
81 torben 1 return false;
82     return true;
83     }
84    
85     bool Solution::operator!=(const Solution& sol)
86     {
87     int matchcount = 0;
88     for (int i=0; i<m_size; i++)
89     for (int j=0; j<m_size; j++)
90 torben 4 if (m_matrix[i][j] == sol.m_matrix[i][j])
91 torben 1 matchcount++;
92     if (matchcount == (m_size*2) )
93     return false;
94     else
95     return true;
96     }
97    
98 torben 4 bool Solution::getMatrix(int x, int y) {
99     return m_matrix[x][y];
100     }
101    
102     void Solution::setMatrix(int x, int y, bool val) {
103     m_matrix[x][y] = val;
104     }
105    
106    
107 torben 2 Solution* Solution::copy()
108     {
109     return new Solution(*this);
110     }

Properties

Name Value
svn:eol-style native
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20