summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/board.js63
-rw-r--r--utils/checks.js15
2 files changed, 78 insertions, 0 deletions
diff --git a/utils/board.js b/utils/board.js
new file mode 100644
index 0000000..ba43c45
--- /dev/null
+++ b/utils/board.js
@@ -0,0 +1,63 @@
+export const emptyBoard = [
+ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ],
+ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ],
+ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ],
+ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ],
+ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ],
+ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ],
+ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ],
+ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ],
+ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ],
+ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ],
+ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ],
+ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ],
+ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ],
+ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ],
+ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ]
+];
+
+export const letters_total = 102;
+
+export function makeLettersBag () {
+ return {
+ letters : {
+ JOKER:{count:2, points:0 },
+ E:{count:15, points:1}, A:{count:9, points:1}, I:{count:9, points:1}, N:{count:6, points:1}, O:{count:6, points:1}, R:{count:6, points:1}, S:{count:6, points:1}, T:{count:6, points:1}, U:{count:6, points:1}, L:{count:5, points:1},
+ D:{count:3, points:2}, G:{count:2, points:2}, M:{count:3, points:2},
+ B:{count:2, points:3}, C:{count:2, points:3}, P:{count:2, points:3},
+ F:{count:2, points:4}, H:{count:2, points:4}, V:{count:2, points:4},
+ J:{count:1, points:8}, Q:{count:1, points:8},
+ K:{count:1, points:10}, W:{count:1, points:10}, X:{count:1, points:10}, Y:{count:1, points:10}, Z:{count:1, points:10},
+ },
+ remaining: letters_total,
+ };
+}
+
+const allLetters = Object.keys(makeLettersBag().letters);
+
+export function pickLetters(bag, count) {
+ if (count > bag.remaining) {
+ count = bag.remaining;
+ }
+ let ret = [];
+ for (let i=0; i<count; i++) {
+ let n = Math.floor(Math.random() * bag.remaining) -1;
+ console.log(n);
+ let j = 0;
+ for (;;) {
+ if (bag.letters[allLetters[j]].count === 0) {
+ j++;
+ } else if (bag.letters[allLetters[j]].count < n) {
+ n -= bag.letters[allLetters[j]].count;
+ j++;
+ } else {
+ n = 0;
+ break;
+ }
+ }
+ console.log("j:", j);
+ bag.letters[allLetters[j]].count--;
+ ret.push(allLetters[j]);
+ }
+ return ret;
+}
diff --git a/utils/checks.js b/utils/checks.js
new file mode 100644
index 0000000..85c51df
--- /dev/null
+++ b/utils/checks.js
@@ -0,0 +1,15 @@
+import { check } from "express-validator";
+
+export const checkName = check("name")
+ .trim()
+ .matches(/^[a-z][-a-z0-9_]+$/i)
+ .withMessage("Un identifiant d'au moins deux charactères est requis.");
+
+export const checkPassword = check("password")
+ .isStrongPassword()
+ .withMessage("Veuillez utiliser un mot de passe d'au moins 8 caractères contenant au moins une minuscule, majuscule, chiffre et charactère spécial.");
+
+export const checkUsername = check("username")
+ .trim()
+ .matches(/^[a-z][-a-z0-9_]+$/i)
+ .withMessage("Un identifiant d'au moins deux charactères est requis.");