summaryrefslogtreecommitdiff
path: root/utils/board.js
diff options
context:
space:
mode:
authorJulien Dessaux2022-11-22 22:55:36 +0100
committerJulien Dessaux2022-11-22 22:55:36 +0100
commit038c877aed55cffdb4401a4c7e7b15b113798145 (patch)
treee2902779e76ba8bd60b63be0e512a3c112530d68 /utils/board.js
parentAdded basic games handling (diff)
downloadjeux-de-mots-038c877aed55cffdb4401a4c7e7b15b113798145.tar.gz
jeux-de-mots-038c877aed55cffdb4401a4c7e7b15b113798145.tar.bz2
jeux-de-mots-038c877aed55cffdb4401a4c7e7b15b113798145.zip
Implemented game creation
Diffstat (limited to 'utils/board.js')
-rw-r--r--utils/board.js63
1 files changed, 63 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;
+}