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

Annotation of /queensgui/src/solutionint.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20