1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2024-12-17 02:39:14 +01:00

Cup fixture scheduling.

This commit is contained in:
gyboth 2009-01-03 11:24:00 +00:00
parent e50b88ace7
commit 85daf78d89
7 changed files with 46 additions and 23 deletions

View File

@ -100,6 +100,7 @@ cup_choose_team_new(void)
new.generate = FALSE;
new.skip_group_check = FALSE;
new.from_table = 0;
new.preload = TRUE;
return new;
}
@ -259,7 +260,7 @@ cup_get_choose_team_league_cup(const CupChooseTeam *ct,
cup round. If necessary, teams are generated and stored in the teams
array of the cup round. */
void
cup_get_team_pointers(Cup *cup, gint round)
cup_get_team_pointers(Cup *cup, gint round, gboolean preload)
{
#ifdef DEBUG
printf("cup_get_team_pointers\n");
@ -272,19 +273,18 @@ cup_get_team_pointers(Cup *cup, gint round)
if(debug > 60)
g_print("cup_get_team_pointers %s round %d\n", cup->name, round);
if(teams->len > 0)
g_warning("cup_get_team_pointers: round %d in cup %s has non-empty team pointers array.",
round, cup->name);
for(i=0;i<cup_round->choose_teams->len;i++)
if(g_array_index(cup_round->choose_teams, CupChooseTeam, i).generate)
cup_load_choose_team_generate(
cup, cup_round,
&g_array_index(cup_round->choose_teams, CupChooseTeam, i));
else
cup_load_choose_team(
cup, teams,
&g_array_index(cup_round->choose_teams, CupChooseTeam, i));
if(g_array_index(cup_round->choose_teams, CupChooseTeam, i).preload == preload)
{
if(g_array_index(cup_round->choose_teams, CupChooseTeam, i).generate)
cup_load_choose_team_generate(
cup, cup_round,
&g_array_index(cup_round->choose_teams, CupChooseTeam, i));
else
cup_load_choose_team(
cup, teams,
&g_array_index(cup_round->choose_teams, CupChooseTeam, i));
}
if(cup_round->teams->len > 0)
while(teams->len + cup_round->teams->len > cup_round->new_teams)

View File

@ -47,7 +47,7 @@ void
cup_reset(Cup *cup);
void
cup_get_team_pointers(Cup *cup, gint round);
cup_get_team_pointers(Cup *cup, gint round, gboolean preload);
void
cup_load_choose_team_generate(Cup *cup, CupRound *cup_round, const CupChooseTeam *ct);

View File

@ -138,6 +138,11 @@ typedef struct
/** Whether to skip the checking if a team participates in other
of the same cup groupcups. */
gboolean skip_group_check;
/** Whether to load the choose_team when the cup fixtures for the
first cup round are written or only when the cup round the choose_team
belongs to is scheduled. Default: TRUE. */
gboolean preload;
} CupChooseTeam;
/** Structure representing a cup. */

View File

@ -113,7 +113,8 @@ fixture_write_cup_fixtures(Cup *cup)
gint i;
cup_get_team_pointers(cup, 0);
for(i=0;i<cup->rounds->len;i++)
cup_get_team_pointers(cup, i, TRUE);
if(g_array_index(cup->rounds, CupRound, 0).round_robin_number_of_groups > 0)
fixture_write_cup_round_robin(
@ -174,7 +175,7 @@ fixture_update(Cup *cup)
}
new_round = &g_array_index(cup->rounds, CupRound, round + 1);
cup_get_team_pointers(cup, round + 1);
cup_get_team_pointers(cup, round + 1, FALSE);
for(i=0;i<new_round->team_ptrs->len;i++)
g_ptr_array_add(teams, g_ptr_array_index(new_round->team_ptrs, i));
@ -305,7 +306,9 @@ fixture_winner_of(const Fixture *fix, gboolean team_id)
cupround = &g_array_index(cup_from_clid(fix->clid)->rounds,
CupRound, fix->round);
if(cupround->replay != 0 || !cupround->home_away)
if(cupround->replay != 0 ||
!cupround->home_away ||
cupround->round_robin_number_of_groups > 0)
winner_idx = (math_sum_int_array(&(fix->result[0][0]), 3) <
math_sum_int_array(&(fix->result[1][0]), 3));
else
@ -964,12 +967,14 @@ fixture_get_first_leg(const Fixture *fix, gboolean silent)
gint i;
Fixture *first_leg = NULL;
const GArray *fixtures = cup_from_clid(fix->clid)->fixtures;
for(i=0;i<cup_from_clid(fix->clid)->fixtures->len;i++)
if(g_array_index(cup_from_clid(fix->clid)->fixtures, Fixture, i).round == fix->round &&
g_array_index(cup_from_clid(fix->clid)->fixtures, Fixture, i).team_ids[0] == fix->team_ids[1] &&
g_array_index(cup_from_clid(fix->clid)->fixtures, Fixture, i).team_ids[1] == fix->team_ids[0])
first_leg = &g_array_index(cup_from_clid(fix->clid)->fixtures, Fixture, i);
if(g_array_index(cup_from_clid(fix->clid)->rounds, CupRound, fix->round).round_robin_number_of_groups == 0)
for(i=0;i<fixtures->len;i++)
if(g_array_index(fixtures, Fixture, i).round == fix->round &&
g_array_index(fixtures, Fixture, i).team_ids[0] == fix->team_ids[1] &&
g_array_index(fixtures, Fixture, i).team_ids[1] == fix->team_ids[0])
first_leg = &g_array_index(fixtures, Fixture, i);
if(first_leg == NULL && !silent)
g_warning("fixture_get_first_leg: didn't find first leg match; cup %s round %d\n",

View File

@ -52,7 +52,7 @@ typedef struct
} PromRelElement;
/**
An element representing promotion/relegation games.
An struct representing promotion/relegation games.
*/
typedef struct
{

View File

@ -69,6 +69,7 @@
#define TAG_CHOOSE_TEAM_GENERATE "generate"
#define TAG_CHOOSE_TEAM_SKIP_GROUP_CHECK "skip_group_check"
#define TAG_CHOOSE_TEAM_FROM_TABLE "from_table"
#define TAG_CHOOSE_TEAM_PRELOAD "preload"
#define ATT_NAME_CUP_ROUND_WAIT_ROUND "round"
@ -118,6 +119,7 @@ enum XmlCupStates
STATE_CHOOSE_TEAM_GENERATE,
STATE_CHOOSE_TEAM_SKIP_GROUP_CHECK,
STATE_CHOOSE_TEAM_FROM_TABLE,
STATE_CHOOSE_TEAM_PRELOAD,
STATE_END
};
@ -257,6 +259,8 @@ xml_cup_read_start_element (GMarkupParseContext *context,
state = STATE_CHOOSE_TEAM_SKIP_GROUP_CHECK;
else if(strcmp(element_name, TAG_CHOOSE_TEAM_FROM_TABLE) == 0)
state = STATE_CHOOSE_TEAM_FROM_TABLE;
else if(strcmp(element_name, TAG_CHOOSE_TEAM_PRELOAD) == 0)
state = STATE_CHOOSE_TEAM_PRELOAD;
else
g_warning("xml_cup_read_start_element: unknown tag: %s; I'm in state %d\n",
element_name, state);
@ -339,6 +343,7 @@ xml_cup_read_end_element (GMarkupParseContext *context,
strcmp(element_name, TAG_CHOOSE_TEAM_RANDOMLY) == 0 ||
strcmp(element_name, TAG_CHOOSE_TEAM_SKIP_GROUP_CHECK) == 0 ||
strcmp(element_name, TAG_CHOOSE_TEAM_FROM_TABLE) == 0 ||
strcmp(element_name, TAG_CHOOSE_TEAM_PRELOAD) == 0 ||
strcmp(element_name, TAG_CHOOSE_TEAM_GENERATE) == 0)
state = STATE_CHOOSE_TEAM;
else if(strcmp(element_name, TAG_CUP) != 0)
@ -446,6 +451,8 @@ xml_cup_read_text (GMarkupParseContext *context,
new_choose_team.skip_group_check = int_value;
else if(state == STATE_CHOOSE_TEAM_FROM_TABLE)
new_choose_team.from_table = int_value;
else if(state == STATE_CHOOSE_TEAM_PRELOAD)
new_choose_team.preload = int_value;
}
/**

View File

@ -50,6 +50,7 @@ enum
TAG_CUP_CHOOSE_TEAM_GENERATE,
TAG_CUP_CHOOSE_TEAM_SKIP_GROUP_CHECK,
TAG_CUP_CHOOSE_TEAM_FROM_TABLE,
TAG_CUP_CHOOSE_TEAM_PRELOAD,
TAG_CUP_ROUND,
TAG_CUP_ROUND_NEW_TEAMS,
TAG_CUP_ROUND_BYES,
@ -174,6 +175,7 @@ xml_loadsave_cup_end_element (GMarkupParseContext *context,
tag == TAG_CUP_CHOOSE_TEAM_GENERATE ||
tag == TAG_CUP_CHOOSE_TEAM_SKIP_GROUP_CHECK ||
tag == TAG_CUP_CHOOSE_TEAM_FROM_TABLE ||
tag == TAG_CUP_CHOOSE_TEAM_PRELOAD ||
tag == TAG_CUP_CHOOSE_TEAM_RANDOMLY)
state = TAG_CUP_CHOOSE_TEAM;
else if(tag == TAG_CUP_ROUND_HOME_AWAY ||
@ -280,6 +282,8 @@ xml_loadsave_cup_text (GMarkupParseContext *context,
new_choose_team.skip_group_check = int_value;
else if(state == TAG_CUP_CHOOSE_TEAM_FROM_TABLE)
new_choose_team.from_table = int_value;
else if(state == TAG_CUP_CHOOSE_TEAM_PRELOAD)
new_choose_team.preload = int_value;
else if(state == TAG_CUP_ROUND_HOME_AWAY)
new_round.home_away = int_value;
else if(state == TAG_CUP_ROUND_NEW_TEAMS)
@ -562,6 +566,8 @@ xml_loadsave_cup_write_choose_team(FILE *fil, const CupChooseTeam *choose_team)
TAG_CUP_CHOOSE_TEAM_SKIP_GROUP_CHECK, I2);
xml_write_int(fil, choose_team->from_table,
TAG_CUP_CHOOSE_TEAM_FROM_TABLE, I2);
xml_write_int(fil, choose_team->preload,
TAG_CUP_CHOOSE_TEAM_PRELOAD, I2);
fprintf(fil, "%s</_%d>\n", I1, TAG_CUP_CHOOSE_TEAM);
}