diff --git a/src/containers/LeagueStage/index.tsx b/src/containers/LeagueStage/index.tsx index 4a23f97b..ad35ff29 100644 --- a/src/containers/LeagueStage/index.tsx +++ b/src/containers/LeagueStage/index.tsx @@ -28,10 +28,11 @@ const MatrixWrapper = styled.div` `; interface Props { + season: number; pots: readonly (readonly Team[])[]; } -function LeagueStage({ pots: initialPots }: Props) { +function LeagueStage({ season, pots: initialPots }: Props) { const numMatchdays = initialPots.length * 2; const numMatches = useMemo(() => { @@ -80,9 +81,9 @@ function LeagueStage({ pots: initialPots }: Props) { useEffect(() => { const formPairings = async () => { const generator = generatePairings({ + season, pots, numMatchdays: 8, - isMatchPossible: (a, b) => a.country !== b.country, }); for await (const pickedMatch of generator) { setPairings(prev => [...prev, pickedMatch]); diff --git a/src/engine/dfs/ls/generatePairings/index.ts b/src/engine/dfs/ls/generatePairings/index.ts index 48224762..0fcb68e4 100644 --- a/src/engine/dfs/ls/generatePairings/index.ts +++ b/src/engine/dfs/ls/generatePairings/index.ts @@ -1,22 +1,23 @@ import { range, shuffle } from 'lodash'; -import { type Country } from '#model/types'; +import { type UefaCountry } from '#model/types'; +import incompatibleCountries from '#engine/predicates/uefa/utils/incompatibleCountries'; import generateFull from './generateFull'; import getFirstSuitableMatch from './getFirstSuitableMatch.wrapper'; interface Team { - country: Country; + country: UefaCountry; } export default async function* generatePairings({ + season, pots, numMatchdays, - isMatchPossible, }: { + season: number; pots: readonly (readonly T[])[]; numMatchdays: number; - isMatchPossible: (h: T, a: T) => boolean; }) { const teams = pots.flat(); const numTeamsPerPot = pots[0].length; @@ -28,7 +29,16 @@ export default async function* generatePairings({ allGames = [...allGames, ...allGames.map(([a, b]) => [b, a] as const)]; - allGames = allGames.filter(([h, a]) => isMatchPossible(teams[h], teams[a])); + const isCountryIncompatibleWith = incompatibleCountries(season); + + allGames = allGames.filter(([h, a]) => { + const hTeam = teams[h]; + const aTeam = teams[a]; + const isImpossible = + hTeam.country === aTeam.country || + isCountryIncompatibleWith(hTeam)(aTeam); + return !isImpossible; + }); const matches: (readonly [number, number])[] = [];