diff --git a/src/engine/dfs/ls/generateSchedule/getFirstSuitableMatchday.ts b/src/engine/dfs/ls/generateSchedule/getFirstSuitableMatchday.ts index 261615bc..fc008af8 100644 --- a/src/engine/dfs/ls/generateSchedule/getFirstSuitableMatchday.ts +++ b/src/engine/dfs/ls/generateSchedule/getFirstSuitableMatchday.ts @@ -1,11 +1,14 @@ import { range, shuffle } from 'lodash'; import { findFirstSolution } from '#utils/backtrack'; +import { type UefaCountry } from '#model/types'; +import coldCountries from '#engine/predicates/uefa/utils/coldCountries'; import teamsSharingStadium from './teamsSharingStadium'; interface Team { readonly name: string; + readonly country: UefaCountry; } export default ({ @@ -34,6 +37,12 @@ export default ({ } } + // TODO: pass season + const isFromColdCountry = coldCountries(0); + const coldTeams = new Set( + range(teams.length).filter(i => isFromColdCountry(teams[i])), + ); + let record = 0; const numMatchesByMatchday = Array.from( @@ -93,6 +102,10 @@ export default ({ return true; } + if (md === numMatchdays - 1 && coldTeams.has(h)) { + return true; + } + for (let b = 0; b < 2; ++b) { const loc = b === 0 ? 'h' : 'a'; const t = b === 0 ? h : a; diff --git a/src/engine/dfs/ls/generateSchedule/getFirstSuitableMatchday.wrapper.ts b/src/engine/dfs/ls/generateSchedule/getFirstSuitableMatchday.wrapper.ts index dba0f7ec..1a578d60 100644 --- a/src/engine/dfs/ls/generateSchedule/getFirstSuitableMatchday.wrapper.ts +++ b/src/engine/dfs/ls/generateSchedule/getFirstSuitableMatchday.wrapper.ts @@ -1,6 +1,7 @@ import { remove, sample, shuffle } from 'lodash'; import raceWorkers from '#utils/raceWorkers'; +import { type UefaCountry } from '#model/types'; import { type Func } from './getFirstSuitableMatchday.worker'; import teamsSharingStadium from './teamsSharingStadium'; @@ -9,6 +10,7 @@ const NUM_WORKERS = Math.max(1, navigator.hardwareConcurrency >> 1); interface Team { readonly name: string; + readonly country: UefaCountry; } export default ({ diff --git a/src/engine/dfs/ls/generateSchedule/index.ts b/src/engine/dfs/ls/generateSchedule/index.ts index 3b744220..d6c27108 100644 --- a/src/engine/dfs/ls/generateSchedule/index.ts +++ b/src/engine/dfs/ls/generateSchedule/index.ts @@ -1,10 +1,13 @@ import { keyBy, uniq } from 'lodash'; +import { type UefaCountry } from '#model/types'; + import getFirstSuitableMatchday from './getFirstSuitableMatchday.wrapper'; interface Team { readonly id: string; readonly name: string; + readonly country: UefaCountry; } export default async function generateSchedule({