added word shuffle functionality
This commit is contained in:
15
README.md
15
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
|
#### 6. Prepare Word List
|
||||||
|
|
||||||
Shuffle the word list for randomization:
|
You can shuffle the word list directly in the web interface (see Web Interface Usage section below).
|
||||||
```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
|
|
||||||
```
|
|
||||||
|
|
||||||
### Web Interface Usage
|
### 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
|
- These should match the IPs you used in the `control.py` commands
|
||||||
|
|
||||||
2. **Prepare Word List**
|
2. **Prepare Word List**
|
||||||
- Copy your shuffled word list from `word-list-shuffled.txt`
|
- Copy your word list from `word-list.txt` and paste it into the large text area on the right side
|
||||||
- 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
|
- Click the **"Modify"** button to generate interactive word items
|
||||||
|
|
||||||
3. **Set Game Parameters**
|
3. **Set Game Parameters**
|
||||||
|
|||||||
@ -79,6 +79,9 @@ class Word(BaseModel):
|
|||||||
timeSeconds: float
|
timeSeconds: float
|
||||||
word: str
|
word: str
|
||||||
|
|
||||||
|
class WordList(BaseModel):
|
||||||
|
words: list[str]
|
||||||
|
|
||||||
@app.post("/word")
|
@app.post("/word")
|
||||||
def read_word(word: Word):
|
def read_word(word: Word):
|
||||||
msg = f"CHARADE:{word.lastWordStatus};{word.timeSeconds};{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))
|
sock.sendto(msg.encode('utf-8'), (word.target, 5000))
|
||||||
return { "status": "ok" }
|
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
|
# SSE endpoint
|
||||||
@app.get("/news")
|
@app.get("/news")
|
||||||
|
|||||||
@ -299,6 +299,7 @@
|
|||||||
<br>
|
<br>
|
||||||
|
|
||||||
<div class="button-container">
|
<div class="button-container">
|
||||||
|
<button type="button" id="button-shuffle-words">Shuffle</button>
|
||||||
<button type="button" id="button-create-word-items">Modify</button>
|
<button type="button" id="button-create-word-items">Modify</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -441,6 +442,40 @@
|
|||||||
window.open('data:text/csv;charset=utf-8,' + escape(data), '_blank');
|
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", () => {
|
document.getElementById("button-create-word-items").addEventListener("click", () => {
|
||||||
createWordItems();
|
createWordItems();
|
||||||
if (frameId) {
|
if (frameId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user