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