match-result simplification

This commit is contained in:
2025-10-29 00:09:14 +01:00
parent 1f55acecd0
commit 335577fa4d
2 changed files with 75 additions and 77 deletions

View File

@@ -51,6 +51,7 @@ import {Tournament} from "../../model/tournament";
export class MatchResultComponent {
result: Result = new Result();
isValidResult: number = 0;
constructor(@Inject(MAT_DIALOG_DATA) public data: {match: Match, tournament: Tournament, event: Event, group: Group, round: Round}) {
this.result.matchId = this.data.match.id;
@@ -79,13 +80,18 @@ export class MatchResultComponent {
this.result.games[game - 1].score2 = 21;
}
this.validateResult();
}
onAnnulerenClick() {
this.dialogRef.close();
}
validateResult(): number {
complementScores() {
// console.log("in complementScores");
}
validateResult(): void {
let valid : boolean = true;
valid &&= this.gameValid(this.result.games[0].score1, this.result.games[0].score2);
valid &&= this.gameValid(this.result.games[1].score1, this.result.games[1].score2);
@@ -94,7 +100,7 @@ export class MatchResultComponent {
valid &&= this.gameValid(this.result.games[2].score1, this.result.games[2].score2);
}
return valid ? this.matchResult(this.result) : 0;
this.isValidResult = valid ? this.matchResult(this.result) : 0;
}
gameValid(score1: number, score2: number): boolean {
@@ -117,29 +123,31 @@ export class MatchResultComponent {
}
matchResult(result: Result): number {
let gameBalance = 0;
if (result.games[0].score1 < result.games[0].score2) {
gameBalance--;
} else {
gameBalance++;
}
if (result.games[1].score1 < result.games[1].score2) {
gameBalance--;
} else {
gameBalance++;
}
let team1Wins = 0;
let team2Wins = 0;
if (Math.abs(gameBalance) == 2 && (result.games[2].score1 != undefined || result.games[2].score2 != undefined)) {
return 0;
}
// Count wins for games 1 and 2
if (result.games[0].score1 > result.games[0].score2) team1Wins++;
else team2Wins++;
if (result.games[2].score1 != undefined && result.games[2].score2 != undefined) {
if (result.games[2].score1 < result.games[2].score2) {
gameBalance--;
} else {
gameBalance++;
if (result.games[1].score1 > result.games[1].score2) team1Wins++;
else team2Wins++;
// If match is already decided (2-0), game 3 shouldn't have scores
if (Math.max(team1Wins, team2Wins) == 2) {
if (result.games[2].score1 != undefined || result.games[2].score2 != undefined) {
return 0; // Invalid
}
return team1Wins > team2Wins ? 1 : -1;
}
return Math.sign(gameBalance);
// Match is 1-1, check game 3
if (result.games[2].score1 != undefined && result.games[2].score2 != undefined) {
if (result.games[2].score1 > result.games[2].score2) team1Wins++;
else team2Wins++;
return team1Wins > team2Wins ? 1 : -1;
}
return 0; // Incomplete
}
}