diff --git a/README.md b/README.md index 9e3033d..96e18d8 100644 --- a/README.md +++ b/README.md @@ -137,16 +137,7 @@ $env:TARGET_IP="YOUR_PLAYER1_IP,YOUR_PLAYER2_IP" ; python control.py "MODE:1;0;0 #### 6. Prepare Word List -Shuffle the word list for randomization: -```bash -# Windows PowerShell -cd experiment-scripts -Get-Content word-list.txt | Sort-Object {Get-Random} | Out-File word-list-shuffled.txt - -# Linux/Mac -cd experiment-scripts -shuf word-list.txt > word-list-shuffled.txt -``` +You can shuffle the word list directly in the web interface (see Web Interface Usage section below). ### Web Interface Usage @@ -159,8 +150,8 @@ Once you have the web interface running at `http://localhost:8000`: - These should match the IPs you used in the `control.py` commands 2. **Prepare Word List** - - Copy your shuffled word list from `word-list-shuffled.txt` - - Paste it into the large text area on the right side + - Copy your word list from `word-list.txt` and paste it into the large text area on the right side + - Click the **"Shuffle"** button to randomize the word order - Click the **"Modify"** button to generate interactive word items 3. **Set Game Parameters** diff --git a/experiment-scripts/app.py b/experiment-scripts/app.py index 153a341..345b5cd 100644 --- a/experiment-scripts/app.py +++ b/experiment-scripts/app.py @@ -79,6 +79,9 @@ class Word(BaseModel): timeSeconds: float word: str +class WordList(BaseModel): + words: list[str] + @app.post("/word") def read_word(word: Word): msg = f"CHARADE:{word.lastWordStatus};{word.timeSeconds};{word.word}" @@ -86,6 +89,13 @@ def read_word(word: Word): sock.sendto(msg.encode('utf-8'), (word.target, 5000)) return { "status": "ok" } +@app.post("/shuffle") +def shuffle_words(word_list: WordList): + import random + shuffled = word_list.words.copy() + random.shuffle(shuffled) + return { "status": "ok", "shuffled_words": shuffled } + # SSE endpoint @app.get("/news") diff --git a/experiment-scripts/index.html b/experiment-scripts/index.html index 4cf01d0..2f55d72 100644 --- a/experiment-scripts/index.html +++ b/experiment-scripts/index.html @@ -299,6 +299,7 @@
+
@@ -441,6 +442,40 @@ window.open('data:text/csv;charset=utf-8,' + escape(data), '_blank'); }); + document.getElementById("button-shuffle-words").addEventListener("click", async () => { + const wordList = document.getElementById("word-list"); + const text = wordList.value.trim(); + + if (!text) { + alert("Please enter words to shuffle first."); + return; + } + + // Don't allow shuffle if word list is already running + if (frameId !== undefined) { + alert("Cannot shuffle while word list is running. Please stop first."); + return; + } + + const words = text.split('\n').map(word => word.trim()).filter(word => word); + + try { + const response = await fetch("/shuffle", { + method: "POST", + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify({ words: words }), + }); + + const result = await response.json(); + if (result.status === "ok") { + wordList.value = result.shuffled_words.join('\n'); + } + } catch (error) { + console.error("Error shuffling words:", error); + alert("Failed to shuffle words. Please try again."); + } + }); + document.getElementById("button-create-word-items").addEventListener("click", () => { createWordItems(); if (frameId) {