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

Contents of /queensgui/src/containervector.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 15 - (show annotations) (download)
Wed Jul 25 19:39:37 2007 UTC (16 years, 9 months ago) by torben
File size: 2852 byte(s)
Corrected the totalSolutions() of all container classes


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 "containervector.h"
21
22 #include <memory>
23
24
25 ContainerVector::ContainerVector(GUIUpdate* update) : SolutionContainer(update)
26 {
27 total = 0;
28 }
29
30
31 ContainerVector::~ContainerVector()
32 {
33 }
34
35 int ContainerVector::numSolutions()
36 {
37 return solutions.size();
38 }
39
40 int ContainerVector::totalSolutions()
41 {
42 return total;
43 }
44
45
46 void ContainerVector::uniqueSolutions()
47 {
48 for (int i=1;i<=4;i++) {
49 if (m_halt)
50 return;
51 uniqueSolutionsWorker(i,false);
52 uniqueSolutionsWorker(i,true);
53 }
54 }
55
56 void ContainerVector::uniqueSolutionsWorker(int rot,bool mirror)
57 {
58 int match_count;
59
60 if (total == -1)
61 total = solutions.size();
62
63 std::vector<boost::shared_ptr<Solution> > buf;
64 for (unsigned int i=0; i<solutions.size(); i++) {
65 if (m_halt)
66 return;
67 match_count = 0;
68
69 std::auto_ptr<Solution> tmp ( solutions[i]->copy());
70 if (mirror)
71 tmp->mirror();
72 for (int k=0;k<rot;k++)
73 tmp->rotate90();
74
75 //unders�g kun resten af m�ngden, start ved i
76 for (unsigned int j=i+1; j<solutions.size();j++) {
77 if ( *tmp == *solutions[j] ) {
78 match_count++;
79 break;
80 }
81 }
82 if (match_count < 1)
83 {
84 buf.push_back( boost::shared_ptr<Solution>(tmp->copy()) );
85 m_uniqueRemoved ++;
86 m_update->duplicateRemoved();
87 }
88 }
89 solutions = buf;
90 }
91
92
93
94 void ContainerVector::addSolution(Solution* sol)
95 {
96 solutions.push_back( boost::shared_ptr<Solution>(sol) );
97 total++;
98 }
99
100 Solution* ContainerVector::solution(int index)
101 {
102 return solutions[index].get() ;
103 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20