initial spell checker
authorLaurent Mazet <mazet@softndesign.org>
Sun, 7 Jun 2020 20:31:17 +0000 (22:31 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Sun, 7 Jun 2020 20:31:17 +0000 (22:31 +0200)
dict-dists-extractor/Makefile [new file with mode: 0644]
public/index.html
public/trivabble.js

diff --git a/dict-dists-extractor/Makefile b/dict-dists-extractor/Makefile
new file mode 100644 (file)
index 0000000..c51ca26
--- /dev/null
@@ -0,0 +1,28 @@
+# -*- Makefile -*-
+
+ROOT_DICT = ../public/dict
+
+all:
+
+$(ROOT_DICT):
+       mkdir $(ROOT_DICT)
+
+$(ROOT_DICT)/fr.json: /usr/share/dict/french
+       cat $< | \
+        grep -v '^.$$' | \
+        grep -v "[.'-]" | \
+        sed -e 's/[àâ]/a/g' \
+            -e 's/[ç]/c/g' \
+            -e 's/[éèêë]/e/g' \
+            -e 's/[ïî]/i/g' \
+            -e 's/[ô]/o/g' \
+            -e 's/[ùûü]/u/g' | \
+        tr '[a-z]' '[A-Z]' | \
+        sort | \
+        uniq | \
+        awk 'BEGIN { print "[" } \
+            { print "    \"" $$0 "\"," } \
+            END { print "    \"\"\n]" }' > $@
+
+check-%:$(ROOT_DICT)/%.json
+       grep -v '^    "[A-Z,]*",$$' $< | grep -v '\[' | grep -v '\]' | grep -v '""' || echo "$< is correct"
index d598935fc86bf6bea02ea16514fb1973fe487a36..92117833fcd8274c3d3ca357a291f1d07e4619d1 100644 (file)
@@ -69,6 +69,7 @@
             <p id="help-turn" data-l10n="text-content">Who's turn? Click on the Turn button!</p>
             <button id="clear-rack" class="minibutton" data-l10n="text-content">Put back all the tiles of&#10;your rack in the bag</button>
             <button id="show-rack" class="minibutton" data-l10n="text-content">Show my rack to other players</button>
+            <button id="compute-word" class="minibutton" data-l10n="text-content">Compute words on board</button>
         </div>
     </body>
 </html>
index 42884f6060999b659df28e369429525794f8137b..4f93c89f3126d93fa80b16081d94c06f7dacd02a 100644 (file)
@@ -79,6 +79,7 @@
     let remainingLetters = 0;
     let needsRestart = false;
     const gameInProgress = false;
+    let currentPlay = {};
 
     let eventSource = null;
     let webSocket = null;
         movingTile.style.width  = "";
         movingTile.style.height = "";
 
+        /* Keep track of letter */
+        if (moveCMD.from === "rack") {
+            if (moveCMD.to === "board") {
+               currentPlay[moveCMD.indexTo] = "-";
+            }
+        } else { /* moveCMD.from === "board" */
+            if (moveCMD.to === "board") {
+               currentPlay[moveCMD.indexTo] = currentPlay[moveCMD.indexFrom];
+            }
+            delete currentPlay[moveCMD.indexFrom];
+        }
+
         mouseUp(document,   dragTileEnd,  true);
         mouseMove(document, dragTileMove, true);
 
                             ? format(_("You changed the language of the board to {0}"), newLang)
                             : format(_("{0} changed the language of the board to {1}"), msg.sender, newLang)
                     );
+                    dictionnary = JSON.parse();
 
                     return;
                 }
             tablePlayers[currentPlayer].classList.remove("current-player");
         }
 
+        currentPlay = {};
         currentPlayer = player;
         refreshCurrentPlayer();
     }
                 break;
             case "setCell":
                 setCell(data.indexTo, data.letter, Object.prototype.hasOwnProperty.call(data, "player") && data.player !== localStorage.trivabblePlayerName);
+                if ((data.letter !== "") && (currentPlay[data.indexTo] === "-")) {
+                    currentPlay[data.indexTo] = data.letter;
+                }
                 break;
             case "setRackCell":
                 setRackCell(data.indexTo, data.letter);
 
     }
 
+    function getLetterFromBoard(row, col) {
+        if ((row < 0) || (row >= 15) || (col < 0) || (col >= 15)) return "";
+        let letter = "";
+        try {
+            let index = row * 15 + col;
+            let tilePlaceholder = boardCells[index].getElementsByClassName("tile-placeholder")[0];
+            let tile = tilePlaceholder.getElementsByClassName("tile")[0];
+            letter = tile.firstChild.textContent;
+        } catch (e) {}
+        return letter;
+    }
+
+    function searchWordInLine(row, col, incRow, incCol) {
+        
+        while (getLetterFromBoard(row - incRow, col - incCol) !== "") {
+            row -= incRow;
+            col -= incCol
+        }
+
+        let word = "";
+        let letter;
+        while ((letter = getLetterFromBoard(row, col)) !== "") {
+            word += letter;
+            row += incRow;
+            col += incCol;
+        }
+        return (word.length > 1) ? word : "";
+    }
+    
+    function computeWord() {
+        let str = "letter:";
+        for (let i in currentPlay) {
+            str += " " + currentPlay[i] + ": " + i;
+        }
+
+        let words = [];
+        for (let i in currentPlay) {
+            let row = Math.floor(i / 15);
+            let col = i % 15;
+            let newWord;
+            newWord = searchWordInLine(row, col, 1, 0);
+            if ((newWord !== "") &&  (!words.includes(newWord))) {
+                words.push(newWord);
+            }
+            newWord = searchWordInLine(row, col, 0, 1);
+            if ((newWord !== "") &&  (!words.includes(newWord))) {
+                words.push(newWord);
+            }
+        }
+
+        myConfirm(
+            _("Words found\n" + str + "\n" + words),
+            function () {}
+        );
+    }
+
     function initChat() {
         chatMessages.style.width = chatMessages.offsetWidth + "px";
 
         document.getElementById("join-game").onclick   = joinGame;
         document.getElementById("clear-rack").onclick  = clearRack;
         document.getElementById("show-rack").onclick   = showRack;
+        document.getElementById("compute-word").onclick = computeWord;
         helpClear.onclick  = clearGame;
     }