From 1d8591b1ff4b0a4267473bf758657aa906037b34 Mon Sep 17 00:00:00 2001 From: gyboth Date: Sun, 10 Apr 2005 11:13:19 +0000 Subject: [PATCH] Bye prefers uppler leagues. --- src/fixture.c | 34 ++++++++++++++++++++++++++++++++++ src/fixture.h | 3 +++ src/start_end.c | 2 ++ 3 files changed, 39 insertions(+) diff --git a/src/fixture.c b/src/fixture.c index 967aa09a..d6605a07 100644 --- a/src/fixture.c +++ b/src/fixture.c @@ -459,12 +459,15 @@ fixture_write_knockout_round(Cup *cup, gint cup_round, GPtrArray *teams) teams = misc_randomise_g_pointer_array(teams); if(bye_len != 0) + { + fixture_sort_teams_bye(teams, bye_len); for(i=0;iname->str); */ g_ptr_array_add(cup->bye, g_ptr_array_index(teams, len - bye_len + i)); } + } else free_g_ptr_array(&cup->bye); @@ -996,3 +999,34 @@ fixture_get_index(const Fixture *fix) return -1; } + +/** Move teams from upper leagues to the beginning of the + array so that they get the bye. + @param teams The randomised array of teams. + @param bye_len The number of teams that get a bye. + @return A new array. */ +void +fixture_sort_teams_bye(GPtrArray *teams, gint bye_len) +{ + gint i, j, moved = 0; + GPtrArray *new_array = g_ptr_array_new(); + + for(i=0;ilen;i++) + for(j=teams->len - 1; j >= 0; j--) + if(((Team*)g_ptr_array_index(teams, j))->clid == lig(i).id && moved < bye_len) + { + g_ptr_array_add(new_array, g_ptr_array_index(teams, j)); + g_ptr_array_remove_index(teams, j); + moved++; + } + else if(moved == bye_len) + { + break; + break; + } + + for(i=0;ilen;i++) + g_ptr_array_add(teams, g_ptr_array_index(new_array, i)); + + g_ptr_array_free(new_array, TRUE); +} diff --git a/src/fixture.h b/src/fixture.h index 72c192d5..b86a4f81 100644 --- a/src/fixture.h +++ b/src/fixture.h @@ -115,4 +115,7 @@ fixture_get_coming(const Team *tm); gint fixture_get_index(const Fixture *fix); +void +fixture_sort_teams_bye(GPtrArray *teams, gint bye_len); + #endif diff --git a/src/start_end.c b/src/start_end.c index d923c015..951333d0 100644 --- a/src/start_end.c +++ b/src/start_end.c @@ -77,6 +77,8 @@ start_write_variables(void) season = week = week_round = 1; cur_user = 0; + + /*d*/ /* week=24; week_round = 2; */ for(i=0;ilen;i++)