Added two match weeks for cup rounds.

This commit is contained in:
gyboth 2007-02-18 13:04:19 +00:00
parent 0dc9ec97f3
commit 906784e061
9 changed files with 96 additions and 23 deletions

View File

@ -105,6 +105,9 @@ cup_round_new(void)
new.round_robin_number_of_groups = 0; new.round_robin_number_of_groups = 0;
new.round_robin_number_of_advance = 0; new.round_robin_number_of_advance = 0;
new.round_robin_number_of_best_advance = 0; new.round_robin_number_of_best_advance = 0;
new.two_match_weeks[0] = g_array_new(FALSE, FALSE, sizeof(gint));
new.two_match_weeks[1] = g_array_new(FALSE, FALSE, sizeof(gint));
new.two_match_week = FALSE;
new.tables = g_array_new(FALSE, FALSE, sizeof(Table)); new.tables = g_array_new(FALSE, FALSE, sizeof(Table));
new.choose_teams = g_array_new(FALSE, FALSE, sizeof(CupChooseTeam)); new.choose_teams = g_array_new(FALSE, FALSE, sizeof(CupChooseTeam));
new.teams = g_array_new(FALSE, FALSE, sizeof(Team)); new.teams = g_array_new(FALSE, FALSE, sizeof(Team));
@ -719,9 +722,6 @@ cup_get_first_week_of_cup_round(Cup *cup, gint cup_round)
return cup_get_first_week_of_cup_round(cup, cup_round); return cup_get_first_week_of_cup_round(cup, cup_round);
} }
/* main_exit_program(EXIT_FIRST_WEEK_ERROR, */
/* "cup_get_first_week_of_cup_round: first week of cup %s cup round %d is not positive (%d).\nPlease lower the week gap or set a later last week.\n", */
/* cup->name, cup_round, week_number); */
return week_number; return week_number;
} }
@ -746,9 +746,11 @@ cup_get_last_week_from_first(const Cup *cup, gint first_week)
gint gint
cup_get_matchdays_in_cup_round(const Cup *cup, gint round) cup_get_matchdays_in_cup_round(const Cup *cup, gint round)
{ {
gint i;
const CupRound *cup_round = &g_array_index(cup->rounds, CupRound, round); const CupRound *cup_round = &g_array_index(cup->rounds, CupRound, round);
gint number_of_teams = -1; gint number_of_teams = -1;
gint number_of_matchdays = -1; gint number_of_matchdays = -1;
gint diff;
if(cup_round->round_robin_number_of_groups > 0) if(cup_round->round_robin_number_of_groups > 0)
{ {
@ -761,11 +763,18 @@ cup_get_matchdays_in_cup_round(const Cup *cup, gint round)
else else
number_of_matchdays = number_of_teams; number_of_matchdays = number_of_teams;
if (g_array_index(cup->rounds, CupRound, round).home_away) if (cup_round->home_away)
number_of_matchdays *= 2; number_of_matchdays *= 2;
for(i=0;i<cup_round->two_match_weeks[0]->len;i++)
{
diff = g_array_index(cup_round->two_match_weeks[1], gint, i) -
g_array_index(cup_round->two_match_weeks[0], gint, i);
number_of_matchdays -= ((diff + diff % 2) / 2);
}
} }
else if(g_array_index(cup->rounds, CupRound, round).home_away) else if(cup_round->home_away)
number_of_matchdays = 2; number_of_matchdays = 2 - cup_round->two_match_week;
else else
number_of_matchdays = 1; number_of_matchdays = 1;

View File

@ -68,6 +68,13 @@ typedef struct
the value is negative) with respect to the previous cup round and the value is negative) with respect to the previous cup round and
the week gap. Default: 0. */ the week gap. Default: 0. */
gint delay; gint delay;
/** Here we store intervals of fixtures during which
there should be two matches in a week instead of one.
This is only relevant in round robin rounds. */
GArray *two_match_weeks[2];
/** Whether the two matches of a home/away round are
played in one week. */
gboolean two_match_week;
/** The teams that got loaded for this cup round. /** The teams that got loaded for this cup round.
Mostly this only happens in the first round. */ Mostly this only happens in the first round. */
GArray *teams; GArray *teams;

View File

@ -55,6 +55,13 @@ file_add_support_directory_recursive (const gchar *directo
if(newdir == NULL) if(newdir == NULL)
return; return;
/* Ignore .svn directories */
if(g_strrstr(directory, ".svn"))
{
g_dir_close(newdir);
return;
}
add_pixmap_directory(directory); add_pixmap_directory(directory);
support_directories = g_list_prepend (support_directories, support_directories = g_list_prepend (support_directories,
g_strdup (directory)); g_strdup (directory));
@ -250,7 +257,8 @@ file_check_home_dir_get_definition_dir(const gchar *dirname, const gchar *basena
sprintf(buf, "%s%s%s", dirname, G_DIR_SEPARATOR_S, sprintf(buf, "%s%s%s", dirname, G_DIR_SEPARATOR_S,
(gchar*)g_ptr_array_index(dir_contents, i)); (gchar*)g_ptr_array_index(dir_contents, i));
if(g_file_test(buf, G_FILE_TEST_IS_DIR)) if(g_file_test(buf, G_FILE_TEST_IS_DIR) &&
!g_strrstr(buf, ".svn"))
{ {
sprintf(buf2, "%s%s%s", basename, G_DIR_SEPARATOR_S, sprintf(buf2, "%s%s%s", basename, G_DIR_SEPARATOR_S,
(gchar*)g_ptr_array_index(dir_contents, i)); (gchar*)g_ptr_array_index(dir_contents, i));

View File

@ -403,6 +403,7 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round,
Cup *cup = NULL; Cup *cup = NULL;
gint len = teams->len; gint len = teams->len;
GArray *fixtures = NULL; GArray *fixtures = NULL;
GArray **two_match_weeks;
Team team_temp; Team team_temp;
gboolean odd_fixtures = FALSE; gboolean odd_fixtures = FALSE;
@ -412,6 +413,7 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round,
{ {
league = (League*)league_cup; league = (League*)league_cup;
fixtures = league->fixtures; fixtures = league->fixtures;
two_match_weeks = league->two_match_weeks;
clid = league->id; clid = league->id;
first_week = (fixtures->len == 0) ? league->first_week : first_week = (fixtures->len == 0) ? league->first_week :
g_array_index(fixtures, Fixture, fixtures->len - 1).week_number + g_array_index(fixtures, Fixture, fixtures->len - 1).week_number +
@ -426,6 +428,7 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round,
first_week = cup_get_first_week_of_cup_round(cup, cup_round); first_week = cup_get_first_week_of_cup_round(cup, cup_round);
week_gap = cup->week_gap; week_gap = cup->week_gap;
fixtures = cup->fixtures; fixtures = cup->fixtures;
two_match_weeks = g_array_index(cup->rounds, CupRound, cup_round).two_match_weeks;
clid = cup->id; clid = cup->id;
home_advantage = (!g_array_index(cup->rounds, CupRound, cup_round).neutral); home_advantage = (!g_array_index(cup->rounds, CupRound, cup_round).neutral);
rr_break = week_gap; rr_break = week_gap;
@ -450,7 +453,7 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round,
week_number = first_week; week_number = first_week;
for(i=0;i<len - 1;i++) for(i=0;i<len - 1;i++)
{ {
if(i > 0 && !query_league_matchday_in_two_match_week(league, i + 1)) if(i > 0 && !query_league_cup_matchday_in_two_match_week(two_match_weeks, i + 1))
week_number += week_gap; week_number += week_gap;
fixture_write_round_robin_matchday(fixtures, cup_round, teams, i, fixture_write_round_robin_matchday(fixtures, cup_round, teams, i,
@ -463,7 +466,7 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round,
week_number += rr_break; week_number += rr_break;
for(i = 0; i < len - 1; i++) for(i = 0; i < len - 1; i++)
{ {
if(i > 0 && !query_league_matchday_in_two_match_week(league, len + i)) if(i > 0 && !query_league_cup_matchday_in_two_match_week(two_match_weeks, len + i))
week_number += week_gap; week_number += week_gap;
week_round_number = week_round_number =
@ -544,7 +547,7 @@ fixture_write_knockout_round(Cup *cup, gint cup_round, GPtrArray *teams)
{ {
gint i, len = teams->len; gint i, len = teams->len;
gint first_week = cup_get_first_week_of_cup_round(cup, cup_round); gint first_week = cup_get_first_week_of_cup_round(cup, cup_round);
gint week_round_number; gint week_number, week_round_number;
CupRound *round = &g_array_index(cup->rounds, CupRound, cup_round); CupRound *round = &g_array_index(cup->rounds, CupRound, cup_round);
gint bye_len = (round->byes == -1) ? gint bye_len = (round->byes == -1) ?
math_get_bye_len(len) : round->byes; math_get_bye_len(len) : round->byes;
@ -592,12 +595,13 @@ fixture_write_knockout_round(Cup *cup, gint cup_round, GPtrArray *teams)
if(round->home_away) if(round->home_away)
{ {
week_number = (round->two_match_week) ?
first_week : first_week + cup->week_gap;
week_round_number = week_round_number =
fixture_get_free_round(first_week + cup->week_gap, teams, -1, -1); fixture_get_free_round(week_number, teams, -1, -1);
for(i=0; i<=(teams->len - 2) / 2; i++) for(i=0; i<=(teams->len - 2) / 2; i++)
fixture_write(cup->fixtures, (Team*)g_ptr_array_index(teams, 2 * i + 1), fixture_write(cup->fixtures, (Team*)g_ptr_array_index(teams, 2 * i + 1),
(Team*)g_ptr_array_index(teams, 2 * i), (Team*)g_ptr_array_index(teams, 2 * i), week_number,
first_week + cup->week_gap,
week_round_number, cup->id, cup_round, 0, week_round_number, cup->id, cup_round, 0,
!round->neutral, TRUE, TRUE); !round->neutral, TRUE, TRUE);
} }

View File

@ -492,6 +492,10 @@ free_cup(Cup *cup)
free_gchar_ptr(cup->sid); free_gchar_ptr(cup->sid);
for(i=0;i<cup->rounds->len;i++) for(i=0;i<cup->rounds->len;i++)
{
free_g_array(&g_array_index(cup->rounds, CupRound, i).two_match_weeks[0]);
free_g_array(&g_array_index(cup->rounds, CupRound, i).two_match_weeks[1]);
if(g_array_index(cup->rounds, CupRound, i).round_robin_number_of_groups > 0) if(g_array_index(cup->rounds, CupRound, i).round_robin_number_of_groups > 0)
{ {
for(j=0;j<g_array_index(cup->rounds, CupRound, i).tables->len;j++) for(j=0;j<g_array_index(cup->rounds, CupRound, i).tables->len;j++)
@ -505,6 +509,7 @@ free_cup(Cup *cup)
free_teams_array(&g_array_index(cup->rounds, CupRound, i).teams, FALSE); free_teams_array(&g_array_index(cup->rounds, CupRound, i).teams, FALSE);
g_ptr_array_free(g_array_index(cup->rounds, CupRound, i).team_ptrs, TRUE); g_ptr_array_free(g_array_index(cup->rounds, CupRound, i).team_ptrs, TRUE);
} }
}
free_g_array(&cup->rounds); free_g_array(&cup->rounds);
free_g_array(&cup->fixtures); free_g_array(&cup->fixtures);

View File

@ -858,18 +858,15 @@ query_leagues_active_in_country(void)
/** Find out whether a given matchday should occur in the same week /** Find out whether a given matchday should occur in the same week
as the one before or a full week later. */ as the one before or a full week later. */
gboolean gboolean
query_league_matchday_in_two_match_week(const League *league, gint matchday) query_league_cup_matchday_in_two_match_week(GArray **two_match_weeks, gint matchday)
{ {
gint i; gint i;
if(league == NULL) for(i=0;i<two_match_weeks[0]->len;i++)
return FALSE;
for(i=0;i<league->two_match_weeks[0]->len;i++)
{ {
if(g_array_index(league->two_match_weeks[0], gint, i) < matchday && if(g_array_index(two_match_weeks[0], gint, i) < matchday &&
matchday <= g_array_index(league->two_match_weeks[1], gint, i) && matchday <= g_array_index(two_match_weeks[1], gint, i) &&
(matchday - g_array_index(league->two_match_weeks[0], gint, i)) % 2 == 1) (matchday - g_array_index(two_match_weeks[0], gint, i)) % 2 == 1)
return TRUE; return TRUE;
} }

View File

@ -134,6 +134,6 @@ gboolean
query_leagues_active_in_country(void); query_leagues_active_in_country(void);
gboolean gboolean
query_league_matchday_in_two_match_week(const League *league, gint matchday); query_league_cup_matchday_in_two_match_week(GArray **two_match_weeks, gint matchday);
#endif #endif

View File

@ -58,6 +58,9 @@
#define TAG_CUP_ROUND_NUMBER_OF_GROUPS "number_of_groups" #define TAG_CUP_ROUND_NUMBER_OF_GROUPS "number_of_groups"
#define TAG_CUP_ROUND_NUMBER_OF_ADVANCE "number_of_advance" #define TAG_CUP_ROUND_NUMBER_OF_ADVANCE "number_of_advance"
#define TAG_CUP_ROUND_NUMBER_OF_BEST_ADVANCE "number_of_best_advance" #define TAG_CUP_ROUND_NUMBER_OF_BEST_ADVANCE "number_of_best_advance"
#define TAG_CUP_ROUND_TWO_MATCH_WEEK_START "two_match_week_start"
#define TAG_CUP_ROUND_TWO_MATCH_WEEK_END "two_match_week_end"
#define TAG_CUP_ROUND_TWO_MATCH_WEEK "two_match_week"
#define TAG_CHOOSE_TEAMS "choose_teams" #define TAG_CHOOSE_TEAMS "choose_teams"
#define TAG_CHOOSE_TEAM "choose_team" #define TAG_CHOOSE_TEAM "choose_team"
#define TAG_CHOOSE_TEAM_SID "choose_team_sid" #define TAG_CHOOSE_TEAM_SID "choose_team_sid"
@ -96,6 +99,9 @@ enum XmlCupStates
STATE_CUP_ROUND_NUMBER_OF_GROUPS, STATE_CUP_ROUND_NUMBER_OF_GROUPS,
STATE_CUP_ROUND_NUMBER_OF_ADVANCE, STATE_CUP_ROUND_NUMBER_OF_ADVANCE,
STATE_CUP_ROUND_NUMBER_OF_BEST_ADVANCE, STATE_CUP_ROUND_NUMBER_OF_BEST_ADVANCE,
STATE_CUP_ROUND_TWO_MATCH_WEEK_START,
STATE_CUP_ROUND_TWO_MATCH_WEEK_END,
STATE_CUP_ROUND_TWO_MATCH_WEEK,
STATE_CHOOSE_TEAMS, STATE_CHOOSE_TEAMS,
STATE_CHOOSE_TEAM, STATE_CHOOSE_TEAM,
STATE_CHOOSE_TEAM_SID, STATE_CHOOSE_TEAM_SID,
@ -185,6 +191,12 @@ xml_cup_read_start_element (GMarkupParseContext *context,
state = STATE_CUP_ROUND_NUMBER_OF_ADVANCE; state = STATE_CUP_ROUND_NUMBER_OF_ADVANCE;
else if(strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_BEST_ADVANCE) == 0) else if(strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_BEST_ADVANCE) == 0)
state = STATE_CUP_ROUND_NUMBER_OF_BEST_ADVANCE; state = STATE_CUP_ROUND_NUMBER_OF_BEST_ADVANCE;
else if(strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK_START) == 0)
state = STATE_CUP_ROUND_TWO_MATCH_WEEK_START;
else if(strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK_END) == 0)
state = STATE_CUP_ROUND_TWO_MATCH_WEEK_END;
else if(strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK) == 0)
state = STATE_CUP_ROUND_TWO_MATCH_WEEK;
else if(strcmp(element_name, TAG_CHOOSE_TEAMS) == 0) else if(strcmp(element_name, TAG_CHOOSE_TEAMS) == 0)
state = STATE_CHOOSE_TEAMS; state = STATE_CHOOSE_TEAMS;
else if(strcmp(element_name, TAG_CHOOSE_TEAM) == 0) else if(strcmp(element_name, TAG_CHOOSE_TEAM) == 0)
@ -246,6 +258,9 @@ xml_cup_read_end_element (GMarkupParseContext *context,
strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_GROUPS) == 0 || strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_GROUPS) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_ADVANCE) == 0 || strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_ADVANCE) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_BEST_ADVANCE) == 0 || strcmp(element_name, TAG_CUP_ROUND_NUMBER_OF_BEST_ADVANCE) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK_START) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK_END) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_TWO_MATCH_WEEK) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_NEW_TEAMS) == 0 || strcmp(element_name, TAG_CUP_ROUND_NEW_TEAMS) == 0 ||
strcmp(element_name, TAG_CUP_ROUND_BYES) == 0 || strcmp(element_name, TAG_CUP_ROUND_BYES) == 0 ||
strcmp(element_name, TAG_CHOOSE_TEAMS) == 0) strcmp(element_name, TAG_CHOOSE_TEAMS) == 0)
@ -333,6 +348,12 @@ xml_cup_read_text (GMarkupParseContext *context,
new_round.round_robin_number_of_advance = int_value; new_round.round_robin_number_of_advance = int_value;
else if(state == STATE_CUP_ROUND_NUMBER_OF_BEST_ADVANCE) else if(state == STATE_CUP_ROUND_NUMBER_OF_BEST_ADVANCE)
new_round.round_robin_number_of_best_advance = int_value; new_round.round_robin_number_of_best_advance = int_value;
else if(state == STATE_CUP_ROUND_TWO_MATCH_WEEK_START)
g_array_append_val(new_round.two_match_weeks[0], int_value);
else if(state == STATE_CUP_ROUND_TWO_MATCH_WEEK_END)
g_array_append_val(new_round.two_match_weeks[1], int_value);
else if(state == STATE_CUP_ROUND_TWO_MATCH_WEEK)
new_round.two_match_week = int_value;
else if(state == STATE_CHOOSE_TEAM_SID) else if(state == STATE_CHOOSE_TEAM_SID)
misc_string_assign(&new_choose_team.sid, buf); misc_string_assign(&new_choose_team.sid, buf);
else if(state == STATE_CHOOSE_TEAM_NUMBER_OF_TEAMS) else if(state == STATE_CHOOSE_TEAM_NUMBER_OF_TEAMS)

View File

@ -62,6 +62,9 @@ enum
TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS,
TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE,
TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE,
TAG_CUP_ROUND_TWO_MATCH_WEEK_START,
TAG_CUP_ROUND_TWO_MATCH_WEEK_END,
TAG_CUP_ROUND_TWO_MATCH_WEEK,
TAG_CUP_TEAM_ID_BYE, TAG_CUP_TEAM_ID_BYE,
TAG_CUP_TEAM_NAME, TAG_CUP_TEAM_NAME,
TAG_CUP_NEXT_FIXTURE_UPDATE_WEEK, TAG_CUP_NEXT_FIXTURE_UPDATE_WEEK,
@ -166,7 +169,10 @@ xml_loadsave_cup_end_element (GMarkupParseContext *context,
tag == TAG_CUP_ROUND_RANDOMISE_TEAMS || tag == TAG_CUP_ROUND_RANDOMISE_TEAMS ||
tag == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS || tag == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS ||
tag == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE || tag == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE ||
tag == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE) tag == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE ||
tag == TAG_CUP_ROUND_TWO_MATCH_WEEK_START ||
tag == TAG_CUP_ROUND_TWO_MATCH_WEEK_END ||
tag == TAG_CUP_ROUND_TWO_MATCH_WEEK)
state = TAG_CUP_ROUND; state = TAG_CUP_ROUND;
else if(tag != TAG_CUP) else if(tag != TAG_CUP)
g_warning("xml_loadsave_cup_end_element: unknown tag: %s; I'm in state %d\n", g_warning("xml_loadsave_cup_end_element: unknown tag: %s; I'm in state %d\n",
@ -276,6 +282,12 @@ xml_loadsave_cup_text (GMarkupParseContext *context,
new_round.round_robin_number_of_advance = int_value; new_round.round_robin_number_of_advance = int_value;
else if(state == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE) else if(state == TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE)
new_round.round_robin_number_of_best_advance = int_value; new_round.round_robin_number_of_best_advance = int_value;
else if(state == TAG_CUP_ROUND_TWO_MATCH_WEEK_START)
g_array_append_val(new_round.two_match_weeks[0], int_value);
else if(state == TAG_CUP_ROUND_TWO_MATCH_WEEK_END)
g_array_append_val(new_round.two_match_weeks[1], int_value);
else if(state == TAG_CUP_ROUND_TWO_MATCH_WEEK)
new_round.two_match_week = int_value;
} }
void void
@ -410,6 +422,16 @@ xml_loadsave_cup_write_round(FILE *fil, const gchar *prefix, const Cup *cup, gin
TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE, I1); TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE, I1);
xml_write_int(fil, cup_round->round_robin_number_of_best_advance, xml_write_int(fil, cup_round->round_robin_number_of_best_advance,
TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE, I1); TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE, I1);
xml_write_int(fil, cup_round->two_match_week,
TAG_CUP_ROUND_TWO_MATCH_WEEK, I1);
for(i=0;i<cup_round->two_match_weeks[0]->len;i++)
{
xml_write_int(fil, g_array_index(cup_round->two_match_weeks[0], gint, i),
TAG_CUP_ROUND_TWO_MATCH_WEEK_START, I1);
xml_write_int(fil, g_array_index(cup_round->two_match_weeks[0], gint, i),
TAG_CUP_ROUND_TWO_MATCH_WEEK_END, I1);
}
for(i=0;i<cup_round->tables->len;i++) for(i=0;i<cup_round->tables->len;i++)
{ {