enefel 1.0.78 → 1.0.82

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/elo.js ADDED
@@ -0,0 +1,35 @@
1
+ const ELO_START = 1000;
2
+ const FACTOR = 32;
3
+ const RESULT_WIN = 1;
4
+ const RESULT_LOST = -1;
5
+ const RESULT_DRAW = 0;
6
+
7
+ function getRatingDelta(myRating, opponentRating, myGameResult) {
8
+ if ([RESULT_LOST, RESULT_DRAW, RESULT_WIN].indexOf(myGameResult) === -1) {
9
+ return null;
10
+ }
11
+
12
+ let result = 0.5;
13
+ if (myGameResult === RESULT_WIN) {
14
+ result = 1;
15
+ } else if (myGameResult === RESULT_LOST) {
16
+ result = 0;
17
+ }
18
+
19
+ const myChanceToWin =
20
+ 1 / (1 + Math.pow(10, (opponentRating - myRating) / 400));
21
+
22
+ return Math.round(FACTOR * (result - myChanceToWin));
23
+ }
24
+
25
+ function getNewRating(myRating, opponentRating, myGameResult) {
26
+ return myRating + getRatingDelta(myRating, opponentRating, myGameResult);
27
+ }
28
+
29
+ module.exports = {
30
+ ELO_START,
31
+ getNewRating,
32
+ RESULT_WIN,
33
+ RESULT_LOST,
34
+ RESULT_DRAW,
35
+ };
package/index.js CHANGED
@@ -144,19 +144,21 @@ const GAME_HISTORY_INFO = {
144
144
  KO: "ko",
145
145
  LANDING: "la",
146
146
  LEAP: "l",
147
+ METEO: "met",
147
148
  MOVE: "m",
148
149
  PASS: "p",
149
150
  REJECTION: "r",
151
+ REROLL_COACH: "rc",
150
152
  REROLL: "re",
151
153
  SCATTER: "sc",
152
154
  SKILL: "sk",
155
+ SPY: "spy",
153
156
  START_FAN: "fan",
154
157
  STATUS: "s",
155
158
  TAKE_BALL: "t",
156
159
  TD: "td",
157
160
  THROW_TEAM_MATE: "ttm",
158
161
  TURNOVER: "to",
159
- SPY: "spy",
160
162
  };
161
163
 
162
164
  const PLAYER_HISTORY_TYPE = {
@@ -228,10 +230,6 @@ const p = (x, y) => {
228
230
  return { x: +x, y: +y };
229
231
  };
230
232
 
231
- const getRandomNumber = (min, max, r = Math.random) => {
232
- return Math.floor(r() * (max - min + 1)) + min;
233
- };
234
-
235
233
  function shuffleArray(array) {
236
234
  return [...array].sort(() => 0.5 - Math.random());
237
235
  }
@@ -281,6 +279,7 @@ const isSquareValidToPushBack = (
281
279
  const noEmptySquares = availableSquares.every((point) => {
282
280
  return (
283
281
  getPlayerOnCell(point.x, point.y, players) ||
282
+ busy.some((b) => b.x === point.x && b.y === point.y) ||
284
283
  !isOnField(point.x, point.y, w, h)
285
284
  );
286
285
  });
@@ -870,8 +869,7 @@ module.exports = {
870
869
  getEnemyTackleZones,
871
870
  getMaxGfi,
872
871
  getMoralModifier,
873
- getPlayerOnCell,
874
- getRandomNumber,
872
+ getPlayerOnCell,
875
873
  getTeamColor,
876
874
  getThrowingBonus,
877
875
  haveSameTeam,
package/meteo.js ADDED
@@ -0,0 +1,98 @@
1
+ const METEO = {
2
+ AUTUMN_LEAF_STREWN_PITCH: 1,
3
+ AUTUMNAL_CHILL: 2,
4
+ POURING_RAIN: 3,
5
+ STRONG_WINDS: 4,
6
+ PERFECT_CONDITION: 7,
7
+ };
8
+
9
+ const SEASON = {
10
+ AUTUMN: 4,
11
+ SPRING: 2,
12
+ SUMMER: 3,
13
+ WINTER: 1,
14
+ };
15
+
16
+ const getSeason = () => {
17
+ return SEASON.AUTUMN;
18
+ };
19
+
20
+ const getMeteo = (value) => {
21
+ const season = getSeason();
22
+ if (season === SEASON.AUTUMN) {
23
+ switch (value) {
24
+ case 2:
25
+ return METEO.AUTUMN_LEAF_STREWN_PITCH;
26
+ case 3:
27
+ return METEO.AUTUMNAL_CHILL;
28
+ case 11:
29
+ return METEO.POURING_RAIN;
30
+ case 12:
31
+ return METEO.STRONG_WINDS;
32
+ default:
33
+ return METEO.PERFECT_CONDITION;
34
+ }
35
+ }
36
+ return METEO.PERFECT_CONDITION;
37
+ };
38
+
39
+ const meteoPlayerFall = (meteoValue) => {
40
+ let modif = 0;
41
+ if (meteoValue) {
42
+ if (meteoValue === METEO.AUTUMN_LEAF_STREWN_PITCH) {
43
+ modif = -1;
44
+ }
45
+ }
46
+ return modif;
47
+ };
48
+
49
+ const meteoKO = (meteoValue) => {
50
+ let modif = 0;
51
+ if (meteoValue) {
52
+ if (meteoValue === METEO.AUTUMNAL_CHILL) {
53
+ modif = -1;
54
+ }
55
+ }
56
+ return modif;
57
+ };
58
+
59
+ const meteoTakeBall = (meteoValue) => {
60
+ let modif = 0;
61
+ if (meteoValue) {
62
+ if (meteoValue === METEO.POURING_RAIN) {
63
+ modif = -1;
64
+ }
65
+ }
66
+ return modif;
67
+ };
68
+
69
+ const meteoPassRebound = (meteoValue) => {
70
+ let modif = 0;
71
+ if (meteoValue) {
72
+ if (meteoValue === METEO.STRONG_WINDS) {
73
+ modif = 3;
74
+ }
75
+ }
76
+ return modif;
77
+ };
78
+
79
+ const meteoPassBonus = (meteoValue) => {
80
+ let modif = 0;
81
+ if (meteoValue) {
82
+ if (meteoValue === METEO.STRONG_WINDS) {
83
+ modif = -1;
84
+ }
85
+ }
86
+ return modif;
87
+ };
88
+
89
+ const tools = {
90
+ meteoPassBonus,
91
+ meteoPassRebound,
92
+ getMeteo,
93
+ METEO,
94
+ meteoKO,
95
+ meteoPlayerFall,
96
+ meteoTakeBall,
97
+ };
98
+ module.exports = tools;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "enefel",
3
- "version": "1.0.78",
3
+ "version": "1.0.82",
4
4
  "main": "index.js",
5
5
  "author": "Manest",
6
6
  "license": "MIT",
package/random.js CHANGED
@@ -7,8 +7,12 @@ const rollDice = (quantity, max) => {
7
7
  };
8
8
 
9
9
  const tools = {
10
- getRandomNumber: (min, max) => {
11
- return Math.floor(Math.random() * (max - min + 1)) + min;
10
+ getRandomNumber: (min, max, r = Math.random) => {
11
+ return Math.floor(r() * (max - min + 1)) + min;
12
+ },
13
+
14
+ d8: (quantity = 1, max = 8) => {
15
+ return rollDice(quantity, max);
12
16
  },
13
17
 
14
18
  d6: (quantity = 1, max = 6) => {
package/skillCoach.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const SKILL_COACH_NAMES = {
2
2
  SPONSOR: "sponsor",
3
3
  SPY: "spy",
4
+ THREATENING: "threatening",
4
5
  };
5
6
 
6
7
  const SKILL_COACH_TYPE = {
@@ -15,6 +16,11 @@ const COACH_SKILLS = {
15
16
  [SKILL_COACH_NAMES.SPY]: SKILL_COACH_TYPE.GENERAL,
16
17
  };
17
18
 
19
+ function shouldDisplayInfoInName(skillId) {
20
+ const skills = [];
21
+ return skills.includes(skillId);
22
+ }
23
+
18
24
  function getCoachSkill(player, skillId) {
19
25
  if (!COACH_SKILLS.hasOwnProperty(skillId)) {
20
26
  throw `Skill '${skillId}' does not exist`;
@@ -40,4 +46,5 @@ module.exports = {
40
46
  SKILL_COACH_NAMES,
41
47
  hasAvailableCoachSkill,
42
48
  getCoachSkill,
49
+ shouldDisplayInfoInName,
43
50
  };
package/stadium.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const { INITIAL_REROLL, p } = require(".");
2
+ const { d6 } = require("./random");
2
3
 
3
4
  const TILES_STADIUM = {
4
5
  a: {
@@ -79,6 +80,11 @@ const maxWidth = 26;
79
80
  const minHeight = 11;
80
81
  const maxHeight = 15;
81
82
  const priceSize = 20;
83
+ const COACH_REROLL_COST = 50;
84
+
85
+ const getRerollCoachCost = (team) => {
86
+ return COACH_REROLL_COST * (team.rerollCoach + 1);
87
+ };
82
88
 
83
89
  const getStadiumCapacityByGame = (game) => {
84
90
  return getStadiumCapacity(game.stadium_width, game.stadium_height);
@@ -121,6 +127,7 @@ const getStadiumFan = (w, h) => {
121
127
  }
122
128
  return nb;
123
129
  };
130
+
124
131
  const getStadiumReroll = (w, h) => {
125
132
  // Width : 20 22 24 26
126
133
  // Height: 11 13 15
@@ -140,6 +147,20 @@ const getStadiumReroll = (w, h) => {
140
147
  return nb;
141
148
  };
142
149
 
150
+ const STADIUM_REROLL_COACH_SUCCESS = 5;
151
+ const getStadiumRerollCoach = (team) => {
152
+ let nb = 0;
153
+ let results = [];
154
+ for (let i = 0; i < team.rerollCoach; i++) {
155
+ const result = d6();
156
+ if (result >= STADIUM_REROLL_COACH_SUCCESS) {
157
+ nb++;
158
+ }
159
+ results.push(result);
160
+ }
161
+ return { nb, results };
162
+ };
163
+
143
164
  const insert = (str, index, value) => {
144
165
  return str.substr(0, index) + value + str.substr(index);
145
166
  };
@@ -246,4 +267,7 @@ module.exports = {
246
267
  removeLine,
247
268
  removeTile,
248
269
  TILES_STADIUM,
270
+ getStadiumRerollCoach,
271
+ STADIUM_REROLL_COACH_SUCCESS,
272
+ getRerollCoachCost,
249
273
  };