Skip to content

Commit 6c4c827

Browse files
committed
Made knockout work
1 parent fa25c20 commit 6c4c827

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

projects/cli/src/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,19 @@ void addEngineScore(QVariantMap *engineMap, QString name, int value)
143143
{
144144
if (engineMap->size())
145145
{
146+
int found = 0;
146147
for (QVariantMap::const_iterator iter = engineMap->begin(); iter != engineMap->end(); ++iter) {
147148
if (iter.key() == name)
148149
{
150+
found = 1;
149151
int score = iter.value().toInt();
150152
score += value;
151153
engineMap->insert(name, score);
152154
}
153155
}
156+
if (! found) {
157+
engineMap->insert(name, value);
158+
}
154159
}
155160
else
156161
{

projects/lib/src/knockouttournament.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ QList<int> KnockoutTournament::firstRoundPlayers() const
7171
for (int i = seedCount; i < n; i++)
7272
{
7373
unseeded << i;
74+
players << i;
7475
}
7576

77+
/*
7678
while (!unseeded.isEmpty())
7779
{
7880
int i = Mersenne::random() % unseeded.size();
79-
players << unseeded.takeAt(i);
8081
}
81-
82+
*/
8283
return players;
8384
}
8485

@@ -108,12 +109,16 @@ void KnockoutTournament::initializePairing()
108109
all[byeIndex] = player;
109110
}
110111
else
111-
all[index] = player;
112+
all[i] = player;
112113
}
113114

114115
QList<TournamentPair*> pairs;
116+
int j = 0;
115117
for (int i = 0; i < x; i += 2)
116-
pairs.append(pair(all.at(i), all.at(i + 1)));
118+
{
119+
pairs.append(pair(all.at(j), all.at(x -j - 1)));
120+
j++;
121+
}
117122

118123
m_rounds.clear();
119124
m_rounds << pairs;
@@ -174,7 +179,20 @@ bool KnockoutTournament::areAllGamesFinished() const
174179

175180
bool KnockoutTournament::shouldWeStopTour() const
176181
{
177-
return m_should_we_stop_global;
182+
QString path = "failed.txt";
183+
184+
if (!fileExists(path))
185+
{
186+
return m_should_we_stop_global;
187+
}
188+
else
189+
{
190+
qWarning () << " \n *************************************************************** \n" <<
191+
" We stopped before game#::" <<
192+
" Look at failed.txt" <<
193+
" \n *************************************************************** \n";
194+
return true;
195+
}
178196
}
179197

180198
bool KnockoutTournament::shouldWeStop(int iWhite, int iBlack, const TournamentPair* pair) const
@@ -280,6 +298,10 @@ TournamentPair* KnockoutTournament::nextPair(int gameNumber)
280298
nextRound << pair(winners.at(i), winners.at(i + 1));
281299
}
282300
m_rounds << nextRound;
301+
if (currentRound() == 1)
302+
{
303+
return nullptr;
304+
}
283305
setCurrentRound(currentRound() + 1);
284306

285307
for (TournamentPair* pair : qAsConst(nextRound))

0 commit comments

Comments
 (0)