Skip to content

Commit 285b08f

Browse files
committed
fix knockout restart
1 parent 9a03aac commit 285b08f

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

projects/lib/src/knockouttournament.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,24 @@ bool KnockoutTournament::procceedNextGame() const
242242
{
243243
}
244244

245+
bool KnockoutTournament::resetBook(const TournamentPair* pair) const
246+
{
247+
// Second player is a BYE
248+
if (!pair->isValid())
249+
return false;
250+
251+
const int iWhite = pair->firstPlayer();
252+
const int iBlack = pair->secondPlayer();
253+
int firstScore = pair->firstScore() + Tournament::playerAt(iWhite).builder()->resumescore();
254+
int secondScore = pair->secondScore() + Tournament::playerAt(iBlack).builder()->resumescore();
255+
256+
if ((firstScore == secondScore) && (!firstScore))
257+
{
258+
return true;
259+
}
260+
return false;
261+
}
262+
245263
bool KnockoutTournament::needMoreGames(const TournamentPair* pair) const
246264
{
247265
// Second player is a BYE

projects/lib/src/knockouttournament.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class LIB_EXPORT KnockoutTournament : public Tournament
5555
virtual bool procceedNextGame() const;
5656
virtual bool shouldWeStop(int white, int black, const TournamentPair* pair) const;
5757
virtual bool shouldWeStopTour() const;
58+
virtual bool resetBook(const TournamentPair* pair) const;
5859
bool m_should_we_stop;
5960

6061
private:

projects/lib/src/tournament.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,11 @@ bool Tournament::fileExists(QString path) const
448448
}
449449
}
450450

451+
bool Tournament::resetBook(const TournamentPair* pair) const
452+
{
453+
return false;
454+
}
455+
451456
bool Tournament::shouldWeStopTour() const
452457
{
453458
QString path = "failed.txt";
@@ -747,6 +752,7 @@ void Tournament::startNextGame()
747752
return;
748753

749754
bool needToStop = false;
755+
bool needtoResetBook = false;
750756
for (;;)
751757
{
752758
needToStop = shouldWeStopTour();
@@ -766,7 +772,9 @@ void Tournament::startNextGame()
766772
break;
767773
}
768774

769-
if (!pair->hasSamePlayers(m_pair) && m_players.size() > 2)
775+
needtoResetBook = resetBook(pair);
776+
qWarning () << "CAlling resetBook ,needtoResetBook:" << needtoResetBook;
777+
if (needtoResetBook || ((!pair->hasSamePlayers(m_pair) && m_players.size() > 2)))
770778
{
771779
m_startFen.clear();
772780
m_openingMoves.clear();

projects/lib/src/tournament.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ class LIB_EXPORT Tournament : public QObject
475475
virtual bool hasGauntletRatingsOrder() const;
476476
virtual bool shouldWeStop(int white, int black, const TournamentPair* pair) const;
477477
virtual bool shouldWeStopTour() const;
478-
virtual bool fileExists(QString path) const;
478+
virtual bool resetBook(const TournamentPair* pair) const;
479+
virtual bool fileExists(QString path) const;
479480

480481

481482
private slots:

0 commit comments

Comments
 (0)