Skip to content

Commit

Permalink
Allow creating play-offs for a winner stays on flyer
Browse files Browse the repository at this point in the history
  • Loading branch information
phrasmotica committed Apr 30, 2024
1 parent 9dd3570 commit cd5adf8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
2 changes: 0 additions & 2 deletions src/components/play/DebugButtons.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ const autoComplete = () => {
nextFixture.value,
tables.value[0].id,
fixtureRaceTo,
standings.value,
fixturesCanBeDrawn.value)
flyerStore.addPhaseEvent(currentPhase.value, message)
Expand All @@ -131,7 +130,6 @@ const autoCompleteRemaining = () => {
currentPhase.value,
tables.value[0].id,
fixtureRaceTo,
standings.value,
fixturesCanBeDrawn.value)
const message = phaseEvents.phaseAutoCompleted()
Expand Down
2 changes: 1 addition & 1 deletion src/components/play/FixtureScoreForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const updateScores = (finish: boolean) => {
})
if (isFinishedEarly) {
flyerStore.finishEarly(currentPhase.value, standings.value)
flyerStore.cancelRemaining()
}
hide()
Expand Down
3 changes: 2 additions & 1 deletion src/components/results/ResultsButtons.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const {
const {
isRoundRobin,
isWinnerStaysOn,
} = usePhaseSpecification(mainPhase.value)
const {
Expand Down Expand Up @@ -72,7 +73,7 @@ const canCreatePlayOff = computed(() => {
<DebugButtons v-if="!isHistoric && uiStore.isDebugMode"
class="mb-2" />

<Button v-if="!isHistoric && isRoundRobin"
<Button v-if="!isHistoric && (isRoundRobin || isWinnerStaysOn)"
class="mb-2"
severity="warning"
:label="t('results.createPlayOff')"
Expand Down
4 changes: 3 additions & 1 deletion src/composables/useRankings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Fixture } from "@/data/Fixture"
import type { Phase } from "@/data/Phase"
import type { Player } from "@/data/Player"
import type { PlayerRecord } from "@/data/PlayerRecord"
import { TieBreaker, Format } from "@/data/Specification"
import { Format, TieBreaker } from "@/data/Specification"
import type { TieBreakerInfo } from "@/data/TieBreakerInfo"

const POINTS_PER_WIN = 3
Expand Down Expand Up @@ -96,6 +96,8 @@ export const useRankings = () => {
return q.wins - p.wins
}

// MEDIUM: prefer fewer losses if it's winner-stays-on

return 0
}

Expand Down
22 changes: 8 additions & 14 deletions src/stores/flyer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,6 @@ export const useFlyerStore = defineStore("flyer", () => {
return false
}

const finishEarly = (phase: Phase, ranking: PlayerRecord[]) => {
if (phase.settings.format !== Format.WinnerStaysOn) {
return
}

cancelRemaining()
finish(ranking)
}

const cancelRemaining = () => {
if (!flyer.value) {
return
Expand Down Expand Up @@ -444,7 +435,6 @@ export const useFlyerStore = defineStore("flyer", () => {
fixture: Fixture,
tableId: string,
dummyScore: number,
currentRanking: PlayerRecord[],
allowDraws: boolean,
) => {
console.debug("Auto-completing fixture " + fixture.id)
Expand All @@ -470,21 +460,26 @@ export const useFlyerStore = defineStore("flyer", () => {
addPhaseEvent(phase, `Fixture ${fixture.id} was auto-completed.`, PhaseEventLevel.Internal)

if (isFinishedEarly) {
finishEarly(phase, currentRanking)
cancelRemaining()
return true
}

return false
}

const autoCompletePhase = (
phase: Phase,
tableId: string,
dummyScore: number,
currentRanking: PlayerRecord[],
allowDraws: boolean,
) => {
const fixtures = phase.rounds.flatMap(r => r.fixtures)

for (const f of fixtures.filter(f => !f.startTime)) {
autoCompleteFixture(phase, f, tableId, dummyScore, currentRanking, allowDraws)
const isFinishedEarly = autoCompleteFixture(phase, f, tableId, dummyScore, allowDraws)
if (isFinishedEarly) {
break
}
}

addPhaseEvent(phase, `${phase.settings.name} was auto-completed.`, PhaseEventLevel.Internal)
Expand Down Expand Up @@ -534,7 +529,6 @@ export const useFlyerStore = defineStore("flyer", () => {
updateScores,
addTable,
generateRound,
finishEarly,
finishPhase,
cancelRemaining,
addPlayOff,
Expand Down

0 comments on commit cd5adf8

Please sign in to comment.