+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ @for (game of result.games; track $index; let i = $index) {
+
+
+
+
+
+ }
+
+
+
+ @for (gameNum of [1, 2, 3]; track gameNum) {
+
+
+
+ }
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
diff --git a/src/app/components/match-result/match-result.component.ts b/src/app/components/match-result/match-result.component.ts
index 85f68c1..d5a62ba 100644
--- a/src/app/components/match-result/match-result.component.ts
+++ b/src/app/components/match-result/match-result.component.ts
@@ -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
}
}