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

Annotation of /queensgui/src/containervector.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20