Skip to content

Commit

Permalink
feat: equal teams
Browse files Browse the repository at this point in the history
Signed-off-by: Dup4 <lyuzhi.pan@gmail.com>
  • Loading branch information
Dup4 committed Dec 27, 2023
1 parent 6a4a0e5 commit 628b923
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 28 deletions.
11 changes: 11 additions & 0 deletions packages/apps/board/src/components/board/OptionsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ function onConfirm() {
v-model="rankOptions.battleOfGiants.enable"
/>

<span
text-sm font-medium
text-gray-900 dark:text-gray-300
>
Equal Teams
</span>

<TheCheckbox
v-model="rankOptions.battleOfGiants.equalTeams"
/>

<!-- <span
text-sm font-medium
text-gray-900 dark:text-gray-300
Expand Down
73 changes: 45 additions & 28 deletions packages/apps/board/src/components/board/Standings.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { GiantsType } from "@xcpcio/core";
import type { Rank, Team } from "@xcpcio/core";
import type { Rank } from "@xcpcio/core";
import { GiantsType, Team } from "@xcpcio/core";
const props = defineProps<{
rank: Rank,
Expand Down Expand Up @@ -45,47 +45,39 @@ const giantTeams = computed(() => {
let blueCnt = 0;
let redCnt = 0;
const res: GiantTeam[] = [];
for (const t of props.rank.teams) {
const giantsType = (() => {
if (blueCnt < battleOfGiants.topX) {
if (blueTeam.filterOrganizationMap.has(t.organization)) {
blueCnt++;
return GiantsType.BLUE;
if (
blueTeam.filterOrganizationMap.has(t.organization)
|| blueTeam.filterTeamMap.has(t.id)
) {
if (blueCnt >= battleOfGiants.topX) {
return null;
}
if (blueTeam.filterTeamMap.has(t.id)) {
blueCnt++;
return GiantsType.BLUE;
}
blueCnt++;
return GiantsType.BLUE;
}
if (redCnt < battleOfGiants.topX) {
if (redTeam.filterOrganizationMap.has(t.organization)) {
redCnt++;
return GiantsType.RED;
if (
redTeam.filterOrganizationMap.has(t.organization)
|| redTeam.filterTeamMap.has(t.id)
) {
if (redCnt >= battleOfGiants.topX) {
return null;
}
if (redTeam.filterTeamMap.has(t.id)) {
redCnt++;
return GiantsType.RED;
}
return null;
redCnt++;
return GiantsType.RED;
}
return null;
})();
if (giantsType === null) {
continue;
}
const gt = {
team: t,
giantsType: giantsType as GiantsType,
};
res.push(gt);
if (giantsType === GiantsType.BLUE) {
blueTeam.teams.push(t);
} else {
Expand All @@ -97,6 +89,31 @@ const giantTeams = computed(() => {
}
}
if (battleOfGiants.equalTeams) {
while (blueTeam.teams.length < redTeam.teams.length) {
redTeam.teams.pop();
}
while (redTeam.teams.length < blueTeam.teams.length) {
blueTeam.teams.pop();
}
}
const res: GiantTeam[] = [...blueTeam.teams.map((t) => {
return {
team: t,
giantsType: GiantsType.BLUE,
};
}), ...redTeam.teams.map((t) => {
return {
team: t,
giantsType: GiantsType.RED,
};
})];
res.sort((lhs, rhs) => {
return Team.compare(lhs.team, rhs.team);
});
return res;
});
Expand Down
2 changes: 2 additions & 0 deletions packages/libs/core/src/battle-of-giants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export class Giants {
export class BattleOfGiants {
enable: boolean;
topX: number;
equalTeams: boolean;
persist: boolean;

blueTeam: Giants;
Expand All @@ -102,6 +103,7 @@ export class BattleOfGiants {
constructor() {
this.enable = false;
this.topX = 5;
this.equalTeams = true;
this.persist = false;

this.blueTeam = new Giants(GiantsType.BLUE);
Expand Down

0 comments on commit 628b923

Please sign in to comment.