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