From 63f975069e96b2a423b6c00b7e63692162b63b16 Mon Sep 17 00:00:00 2001 From: gyboth Date: Sat, 3 Mar 2007 18:24:26 +0000 Subject: [PATCH] Minor two_week_matches bug fixed. --- src/fixture.c | 28 ++++++++++++++++++++++++++-- src/fixture.h | 4 ++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/fixture.c b/src/fixture.c index 57ee63f4..b4c3bef2 100644 --- a/src/fixture.c +++ b/src/fixture.c @@ -453,7 +453,8 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round, week_number = first_week; for(i=0;i 0 && !query_league_cup_matchday_in_two_match_week(two_match_weeks, i + 1)) + if(i > 0 && !query_league_cup_matchday_in_two_match_week(two_match_weeks, + fixture_count_matchdays(fixtures) + 1)) week_number += week_gap; fixture_write_round_robin_matchday(fixtures, cup_round, teams, i, @@ -466,7 +467,8 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round, week_number += rr_break; for(i = 0; i < len - 1; i++) { - if(i > 0 && !query_league_cup_matchday_in_two_match_week(two_match_weeks, len + i)) + if(i > 0 && !query_league_cup_matchday_in_two_match_week(two_match_weeks, + fixture_count_matchdays(fixtures) + i)) week_number += week_gap; week_round_number = @@ -1384,3 +1386,25 @@ fixture_get_goals_to_win(const Fixture *fix, const Team *tm) return return_value; } + +/** Count how many matchdays there are in + a fixture array. */ +gint +fixture_count_matchdays(const GArray *fixtures) +{ + gint i; + gint count = 0; + + for(i=1;ilen;i++) + { + if((g_array_index(fixtures, Fixture, i).week_number != + g_array_index(fixtures, Fixture, i - 1).week_number) || + (g_array_index(fixtures, Fixture, i).week_round_number != + g_array_index(fixtures, Fixture, i - 1).week_round_number)) + count++; + } + + /** If there were fixtures, we counted one matchday too few + because we only counted the matchday transitions. */ + return count + (fixtures->len != 0); +} diff --git a/src/fixture.h b/src/fixture.h index 44f70267..f39672e8 100644 --- a/src/fixture.h +++ b/src/fixture.h @@ -156,4 +156,8 @@ fixture_get_season_results(void); gint fixture_get_goals_to_win(const Fixture *fix, const Team *tm); +gint +fixture_count_matchdays(const GArray *fixtures); + + #endif