Skip to content

Commit

Permalink
Merge branch 'pretty-output'
Browse files Browse the repository at this point in the history
  • Loading branch information
yapavelkurochkin committed Oct 17, 2016
2 parents 2d1d1a0 + 80555ea commit 6cb9a81
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void LeagueMainWindow::loadTournament( QString fName )
{
if ( !fName.isNull() ) {
tourn = Tournament::fromFile( fName );
if ( tourn ) {
if ( tourn && tourn->isValid() ) {
_history->reset( tourn );
newTournamentWidget( tourn );

Expand Down
2 changes: 1 addition & 1 deletion gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LeagueMainWindow : public QMainWindow
QAction *loadT, *newT, *saveT, *about,
*ratings, *exportT, *undoT, *redoT,
*breakADBC, *breakACBD, *breakABCD;
Tournament* tourn;
Tournament* tourn;
QString progName;
TournamentHistory* _history;

Expand Down
6 changes: 5 additions & 1 deletion gui/qplayoff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ QList<Group*> QPlayoffAlgo::buildGroups( unsigned int stage,
wg = new SwissGroup( 1, stage, permutePlayers( toppls ) );
lg = new SwissGroup( 1 + toppls.count(), stage, permutePlayers( botpls ) );
lg->setQualif( prevGroups.at(0)->isQualif() );

groups << wg << lg;

foreach( Group *g, groups ) {
dynamic_cast< SwissGroup* >(g)->permuteMatches( breakAlgo() );
}

return groups;
}

Expand Down
4 changes: 4 additions & 0 deletions gui/rrplayoff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ QList<Group*> RRPlayoffAlgo::buildGroups( unsigned int stage,
}
}

foreach( Group *g, groups ) {
dynamic_cast< SwissGroup* >(g)->permuteMatches( breakAlgo() );
}

return groups;
}

Expand Down
45 changes: 33 additions & 12 deletions gui/swissgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,19 @@ QList< Group* > SwissGroup::split( ) const
if ( w.count() & 1 ) w << byePlayer;
if ( l.count() & 1 ) l << byePlayer;

const TournAlgo *a = _tournData->algo();
Q_CHECK_PTR( a );

// winners group
SwissGroup *wg = new SwissGroup( _fromPlace, _stage + 1,
a->permutePlayers( w ) );

ret << new SwissGroup( _fromPlace, _stage + 1, w );
// loosers group
SwissGroup *lg = new SwissGroup( _fromPlace + _players.count() / 2,
_stage + 1, a->permutePlayers( l ) );

lg->setQualif( isQualif() );

ret << wg << lg;
ret << new SwissGroup( _fromPlace + _players.count() / 2,
_stage + 1, l );

foreach( Group *g, ret ) {
const TournAlgo *a = _tournData->algo();
Q_CHECK_PTR( a );

g->setTournData( _tournData );
g->setQualif( isQualif() );
dynamic_cast<SwissGroup*>(g)->permuteMatches( a->breakAlgo() );
}

return ret;
Expand Down Expand Up @@ -170,3 +166,28 @@ bool SwissGroup::lessThan(const Group* g1, const Group* g2)
}
}

/* redorder matches so that this group will be simply splitted by
* winners and loosers, without permuation
* \todo this function should be in TournAlgo class... like permutePlayers()
*/
void SwissGroup::permuteMatches( BreakAlgo::Algo br )
{
if ( _matches.count() <= 2 ) {
// nothing to permute
return;
}

MatchList tmp = _matches;
_matches.clear();

for ( int i = 0; i < tmp.count() / 2; i ++ ) {
if ( br == BreakAlgo::ADBC ) {
_matches << tmp.at( i ) << tmp.at( tmp.count() - i - 1 );
} else if ( br == BreakAlgo::ACBD ) {
_matches << tmp.at( i ) << tmp.at( tmp.count() / 2 + i );
} else {
// no changes
_matches << tmp.at( i*2 ) << tmp.at( i*2 + 1 );
}
}
}
2 changes: 2 additions & 0 deletions gui/swissgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class SwissGroup : public Group
static bool lessThan(const Group* g1, const Group* g2);

QString type() const { return "swiss"; }

void permuteMatches( BreakAlgo::Algo br );
};


Expand Down
3 changes: 1 addition & 2 deletions gui/tournament.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Tournament : public QObject {

void update( );

bool isValid() const { return _magic == TOURN_MAGIC_NUMBER; }
signals:
void newSwissGroupCreated( SwissGroup* g );
void tournamentChanged( Tournament* t );
Expand All @@ -56,8 +57,6 @@ class Tournament : public QObject {
QString _fileName;
/*<< file which corresponds to this tournament */

bool isValid() const { return _magic == TOURN_MAGIC_NUMBER; }

friend QDataStream &operator>>(QDataStream &, Tournament&);
friend QDataStream &operator<<(QDataStream &, const Tournament&);
};
Expand Down

0 comments on commit 6cb9a81

Please sign in to comment.