Skip to content

Commit

Permalink
update function signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
inker committed Sep 17, 2023
1 parent bbfba25 commit ec3edbc
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 18 deletions.
23 changes: 15 additions & 8 deletions src/engine/backtracking/gs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,31 @@ function anyGroupPossible<T>(
return newGroups.some((_, i) => anyGroupPossible(newSource, newGroups, newPicked, i, predicate))
}

export const allPossibleGroups = <T>(
interface Input<T> {
pots: ReadonlyDoubleArray<T>,
groups: ReadonlyDoubleArray<T>,
picked: T,
predicate: Predicate<T>,
) => {
}

export const allPossibleGroups = <T>({
pots,
groups,
picked,
predicate,
}: Input<T>) => {
const source = pots.flat()
return groups
.map((_, i) => i)
.filter(i => anyGroupPossible(source, groups, picked, i, predicate))
}

export const firstPossibleGroup = <T>(
pots: ReadonlyDoubleArray<T>,
groups: ReadonlyDoubleArray<T>,
picked: T,
predicate: Predicate<T>,
) => {
export const firstPossibleGroup = <T>({
pots,
groups,
picked,
predicate,
}: Input<T>) => {
const source = pots.flat()
return groups.findIndex((_, i) => anyGroupPossible(source, groups, picked, i, predicate))
}
15 changes: 11 additions & 4 deletions src/engine/backtracking/ko.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Predicate } from 'engine/backtracking/gs'
import { type FixedArray } from 'model/types'

type OneOrTwo<T> = readonly [T] | readonly [T, T]

Expand Down Expand Up @@ -38,12 +39,18 @@ function anyRunnersUp<T>(
.some(item => anyGroupWinners(item, [groupWinners, newRunnersUp], newMatchups, predicate))
}

// eslint-disable-next-line import/prefer-default-export
export const getPossiblePairings = <T>(
[groupWinners, runnersUp]: readonly (readonly T[])[],
interface Input<T> {
pots: FixedArray<readonly T[], 2>,
matchups: readonly OneOrTwo<T>[],
predicate: Predicate<T>,
): number[] =>
}

// eslint-disable-next-line import/prefer-default-export
export const getPossiblePairings = <T>({
pots: [groupWinners, runnersUp],
matchups,
predicate,
}: Input<T>): number[] =>
groupWinners
.map((item, i) => i)
.filter(i => anyGroupWinners(groupWinners[i], [groupWinners, runnersUp], matchups, predicate))
7 changes: 6 additions & 1 deletion src/pages/cl/gs/allPossibleGroupsWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ const func = (data: GsWorkerData<Team>) => {
} = data

const predicate = getPredicateMemoized(season, pots.length)
return allPossibleGroups(pots, groups, selectedTeam, predicate)
return allPossibleGroups({
pots,
groups,
picked: selectedTeam,
predicate,
})
}

export type Func = ExposedFuncType<typeof func>
Expand Down
7 changes: 6 additions & 1 deletion src/pages/cl/gs/firstPossibleGroupWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ const func = (data: GsWorkerData<Team>) => {
} = data

const predicate = getPredicateMemoized(season, pots.length)
return firstPossibleGroup(pots, groups, selectedTeam, predicate)
return firstPossibleGroup({
pots,
groups,
picked: selectedTeam,
predicate,
})
}

export type Func = ExposedFuncType<typeof func>
Expand Down
6 changes: 5 additions & 1 deletion src/pages/cl/ko/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ const func = (data: KoWorkerData<Team>) => {
} = data

const predicate = getPredicateMemoized(season)
return getPossiblePairings(pots, matchups, predicate)
return getPossiblePairings({
pots,
matchups,
predicate,
})
}

export type Func = ExposedFuncType<typeof func>
Expand Down
7 changes: 6 additions & 1 deletion src/pages/el/gs/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ const func = (data: GsWorkerData<Team>) => {
} = data

const predicate = getPredicateMemoized(season, pots.length)
return firstPossibleGroup(pots, groups, selectedTeam, predicate)
return firstPossibleGroup({
pots,
groups,
picked: selectedTeam,
predicate,
})
}

export type Func = ExposedFuncType<typeof func>
Expand Down
6 changes: 5 additions & 1 deletion src/pages/el/ko/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ const func = (data: KoWorkerData<Team>) => {
} = data

const predicate = getPredicateMemoized(season)
return getPossiblePairings(pots, matchups, predicate)
return getPossiblePairings({
pots,
matchups,
predicate,
})
}

export type Func = ExposedFuncType<typeof func>
Expand Down
7 changes: 6 additions & 1 deletion src/pages/wc/gs/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ const func = (data: GsWorkerData<Team>) => {
...groups.flat(),
]
const predicate = getPredicateMemoized(season, teams)
return firstPossibleGroup(pots, groups, selectedTeam, predicate)
return firstPossibleGroup({
pots,
groups,
picked: selectedTeam,
predicate,
})
}

export type Func = ExposedFuncType<typeof func>
Expand Down

0 comments on commit ec3edbc

Please sign in to comment.