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

Annotation of /queensgui/src/solution.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations) (download)
Thu Jul 19 22:26:42 2007 UTC (16 years, 10 months ago) by torben
File size: 2761 byte(s)
First steps towards enabling multiple solution types...

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     matrix[i][j] = false;
29     }
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     matrix[i][j] = input.matrix[i][j];
43     }
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     matrix[i][j] = input[i][j];
51     }
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     temp[j][(m_size-1)-i] = matrix[i][j];
61     }
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     temp[i][(m_size-1)-j] = matrix[i][j];
72     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     if (matrix[i][j] != sol.matrix[i][j])
81     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     if (matrix[i][j] == sol.matrix[i][j])
91     matchcount++;
92     if (matchcount == (m_size*2) )
93     return false;
94     else
95     return true;
96     }
97    
98 torben 2 Solution* Solution::copy()
99     {
100     return new Solution(*this);
101     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20