Skip to content

Commit

Permalink
cold countries scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
inker committed Sep 2, 2024
1 parent 55f5f81 commit 4b5b061
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/engine/dfs/ls/generateSchedule/getFirstSuitableMatchday.ts
Original file line number Diff line number Diff line change
@@ -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 ({
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -9,6 +10,7 @@ const NUM_WORKERS = Math.max(1, navigator.hardwareConcurrency >> 1);

interface Team {
readonly name: string;
readonly country: UefaCountry;
}

export default ({
Expand Down
3 changes: 3 additions & 0 deletions src/engine/dfs/ls/generateSchedule/index.ts
Original file line number Diff line number Diff line change
@@ -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<T extends Team>({
Expand Down

0 comments on commit 4b5b061

Please sign in to comment.