enefel 1.0.107 → 1.0.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/league.js +42 -14
- package/package.json +1 -1
package/league.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
const { GAME_TYPE } = require(".");
|
|
2
2
|
const { canPlayLeague } = require("./state");
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const MIN_OPEN_SIZE = 4;
|
|
5
|
+
const GROUP_SIZE = 8;
|
|
6
|
+
const HAS_NEXT_SEASON_PLAYOFF = false;
|
|
7
|
+
const CAN_CHOOSE_TO_PARTICIPATE = false;
|
|
8
|
+
const HOME_AND_AWAY = false;
|
|
6
9
|
|
|
7
10
|
const calculateTeamsStandingForPlayoff = (flatTeams, division) => {
|
|
8
11
|
const standings = [{ teams: [] }];
|
|
@@ -75,10 +78,17 @@ const calculateTeamsStandingForPlayoff = (flatTeams, division) => {
|
|
|
75
78
|
return flatedTeams;
|
|
76
79
|
};
|
|
77
80
|
|
|
78
|
-
const calculateTeamsStandingForLeagues = (
|
|
81
|
+
const calculateTeamsStandingForLeagues = (
|
|
82
|
+
newStandings,
|
|
83
|
+
division,
|
|
84
|
+
currentSeason
|
|
85
|
+
) => {
|
|
86
|
+
const openDivision = newStandings[division.length - 1];
|
|
79
87
|
for (let i = 0; i < division.length - 1; ++i) {
|
|
80
88
|
const currentDivision = newStandings[i];
|
|
81
|
-
const nextDivision =
|
|
89
|
+
const nextDivision = currentSeason.playoff
|
|
90
|
+
? openDivision
|
|
91
|
+
: newStandings[i + 1];
|
|
82
92
|
|
|
83
93
|
const currentDivisionLastTeam =
|
|
84
94
|
currentDivision.teams[currentDivision.teams.length - 1];
|
|
@@ -87,13 +97,20 @@ const calculateTeamsStandingForLeagues = (newStandings, division) => {
|
|
|
87
97
|
|
|
88
98
|
if (nextDivision.name === GAME_TYPE.OPEN) {
|
|
89
99
|
// To avoid some teams block the open, we take the first team with canChampionship
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
)
|
|
100
|
+
|
|
101
|
+
let alreadyFind = i;
|
|
102
|
+
indexNextDivisionFirstTeam = nextDivision.teams.findIndex((t, i) => {
|
|
103
|
+
if (currentSeason.playoff && i < alreadyFind) {
|
|
104
|
+
// Fix Si CAN_CHOOSE_TO_PARTICIPATE ?
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return t.canChampionship || !CAN_CHOOSE_TO_PARTICIPATE;
|
|
108
|
+
});
|
|
93
109
|
if (indexNextDivisionFirstTeam === -1) {
|
|
94
|
-
indexNextDivisionFirstTeam = 0;
|
|
110
|
+
indexNextDivisionFirstTeam = currentSeason.playoff ? i : 0;
|
|
95
111
|
}
|
|
96
112
|
}
|
|
113
|
+
|
|
97
114
|
const nextDivisionFirstTeam =
|
|
98
115
|
nextDivision.teams[indexNextDivisionFirstTeam];
|
|
99
116
|
|
|
@@ -109,7 +126,7 @@ const calculateTeamsStandingForLeagues = (newStandings, division) => {
|
|
|
109
126
|
return flatTeams;
|
|
110
127
|
};
|
|
111
128
|
|
|
112
|
-
const calculateTeamsStandingForNextSeason = (division) => {
|
|
129
|
+
const calculateTeamsStandingForNextSeason = (division, currentSeason) => {
|
|
113
130
|
division = division.filter(
|
|
114
131
|
(d) => d.name !== GAME_TYPE.FRIENDLY && d.name !== GAME_TYPE.PLAYOFF
|
|
115
132
|
);
|
|
@@ -123,7 +140,11 @@ const calculateTeamsStandingForNextSeason = (division) => {
|
|
|
123
140
|
if (HAS_NEXT_SEASON_PLAYOFF && GROUP_SIZE * 3 < flatTeams.length) {
|
|
124
141
|
return calculateTeamsStandingForPlayoff(flatTeams, division);
|
|
125
142
|
}
|
|
126
|
-
return calculateTeamsStandingForLeagues(
|
|
143
|
+
return calculateTeamsStandingForLeagues(
|
|
144
|
+
newStandings,
|
|
145
|
+
division,
|
|
146
|
+
currentSeason
|
|
147
|
+
);
|
|
127
148
|
};
|
|
128
149
|
|
|
129
150
|
const forcastNextSeason = (flatTeams) => {
|
|
@@ -137,7 +158,10 @@ const forcastNextSeason = (flatTeams) => {
|
|
|
137
158
|
return;
|
|
138
159
|
}
|
|
139
160
|
// En playoff on n'a que les ligues A et B + open
|
|
140
|
-
if (
|
|
161
|
+
if (
|
|
162
|
+
(CAN_CHOOSE_TO_PARTICIPATE && !team.canChampionship) ||
|
|
163
|
+
(i >= 2 && HAS_NEXT_SEASON_PLAYOFF)
|
|
164
|
+
) {
|
|
141
165
|
open.push(team);
|
|
142
166
|
return;
|
|
143
167
|
}
|
|
@@ -150,8 +174,7 @@ const forcastNextSeason = (flatTeams) => {
|
|
|
150
174
|
}
|
|
151
175
|
});
|
|
152
176
|
open = [...currentGroup, ...open];
|
|
153
|
-
|
|
154
|
-
if (open.length < GROUP_SIZE) {
|
|
177
|
+
if (open.length < MIN_OPEN_SIZE) {
|
|
155
178
|
const lastDivision = groups.pop();
|
|
156
179
|
if (lastDivision) {
|
|
157
180
|
open = [...lastDivision, ...open];
|
|
@@ -182,7 +205,7 @@ const playoffNextSeason = (flatTeams) => {
|
|
|
182
205
|
// Le reste est mis en open
|
|
183
206
|
open = [...currentGroup, ...open];
|
|
184
207
|
|
|
185
|
-
if (open.length <
|
|
208
|
+
if (open.length < MIN_OPEN_SIZE) {
|
|
186
209
|
const lastDivision = groups.pop();
|
|
187
210
|
if (lastDivision) {
|
|
188
211
|
open = [...lastDivision, ...open];
|
|
@@ -240,7 +263,12 @@ function sortLeagues(a, b) {
|
|
|
240
263
|
|
|
241
264
|
module.exports = {
|
|
242
265
|
calculateTeamsStandingForNextSeason,
|
|
266
|
+
CAN_CHOOSE_TO_PARTICIPATE,
|
|
267
|
+
GROUP_SIZE,
|
|
268
|
+
HAS_NEXT_SEASON_PLAYOFF,
|
|
243
269
|
hasCalendar,
|
|
270
|
+
HOME_AND_AWAY,
|
|
271
|
+
MIN_OPEN_SIZE,
|
|
244
272
|
playoffNextSeason,
|
|
245
273
|
sortLeagues,
|
|
246
274
|
tournament,
|