Swap on reset

This commit is contained in:
2026-02-09 22:34:11 +01:00
parent 1cfa9f5cd2
commit dec8fa1710
2 changed files with 187 additions and 218 deletions

View File

@@ -4,62 +4,70 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Wolf & Schafe | Rough Edition</title> <title>Wolf & Schafe | Pro</title>
<style> <style>
:root { :root {
--bg: #e5e7eb; --bg: #f0f2f5;
--wolf: #ff3e3e; --wolf: #e63946;
--sheep: #3b82f6; --wolf-light: #ff6b78;
--black: #1a1a1a; --sheep: #457b9d;
--surface: #ffffff; --sheep-light: #7db0cf;
--black: #1d3557;
--white: #ffffff;
} }
body { body {
font-family: 'Courier New', Courier, monospace; font-family: 'Courier New', Courier, monospace;
/* Rough, typewriter feel */ background: var(--bg);
background-color: var(--bg);
color: var(--black); color: var(--black);
margin: 0;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
min-height: 100vh; min-height: 100vh;
} margin: 0;
padding: 10px;
/* Large Screen Scaling */
.game-wrapper {
width: 100%;
max-width: 900px;
/* Increased for big monitors */
padding: 20px;
box-sizing: border-box; box-sizing: border-box;
} }
.main-card { .game-wrapper {
background: var(--surface); width: 100%;
border: 4px solid var(--black); max-width: 800px;
box-shadow: 12px 12px 0px var(--black);
/* Brutalist shadow */
padding: 2rem;
display: flex;
flex-direction: column;
gap: 20px;
} }
/* Clear Identity Section */ .main-card {
.identity-banner { background: var(--white);
border: 4px solid var(--black);
box-shadow: 8px 8px 0px var(--black);
padding: 1.5rem;
display: flex; display: flex;
flex-direction: column;
gap: 15px;
}
.info-bar {
display: flex;
flex-wrap: wrap;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
border: 3px solid var(--black); border: 3px solid var(--black);
padding: 15px; padding: 10px;
background: #f3f4f6; background: #f8fafc;
gap: 10px;
}
.room-tag {
font-size: 0.8rem;
font-weight: bold;
background: var(--black);
color: white;
padding: 4px 8px;
text-transform: uppercase;
} }
.id-box { .id-box {
font-size: 1.5rem; font-size: 1.2rem;
font-weight: 900; font-weight: 900;
padding: 10px 20px; padding: 8px 16px;
border: 3px solid var(--black); border: 3px solid var(--black);
text-transform: uppercase; text-transform: uppercase;
} }
@@ -74,42 +82,37 @@
color: white; color: white;
} }
#status {
font-size: 1.2rem;
font-weight: bold;
text-align: right;
}
/* Board Scaling */
.board-container { .board-container {
width: 100%; width: 100%;
aspect-ratio: 600 / 420; aspect-ratio: 600 / 420;
background: #fff;
border: 3px solid var(--black); border: 3px solid var(--black);
cursor: crosshair; background: #fff;
position: relative;
touch-action: manipulation;
} }
svg { svg {
width: 100%; width: 100%;
height: 100%; height: 100%;
display: block;
} }
/* Rough Elements */
.edge { .edge {
stroke: var(--black); stroke: var(--black);
stroke-width: 4; stroke-width: 3;
} }
.node-circle { .node-circle {
stroke: var(--black); stroke: var(--black);
stroke-width: 3; stroke-width: 2.5;
transition: transform 0.1s; transition: all 0.15s ease;
} }
.empty { .empty {
fill: #fff; fill: #fff;
} }
/* Piece Colors */
.sheep { .sheep {
fill: var(--sheep); fill: var(--sheep);
} }
@@ -118,86 +121,95 @@
fill: var(--wolf); fill: var(--wolf);
} }
.selected { /* Subtle Select: Lightens the fill and adds a clean 4px border */
stroke-width: 6; .wolf.selected {
stroke: #000; fill: var(--wolf-light);
fill: #fde047; stroke-width: 4;
/* Yellow highlight for selection */ }
.sheep.selected {
fill: var(--sheep-light);
stroke-width: 4;
} }
.possible { .possible {
fill: #fff; fill: #fff;
stroke: #22c55e; stroke: #10b981;
stroke-width: 4; stroke-width: 3;
stroke-dasharray: 6; stroke-dasharray: 4;
} }
.node-label { .node-label {
font-family: Arial, sans-serif; font-family: sans-serif;
font-size: 14px;
font-weight: 900; font-weight: 900;
pointer-events: none; pointer-events: none;
user-select: none;
} }
/* Buttons */
.controls { .controls {
display: grid; display: grid;
grid-template-columns: repeat(3, 1fr); grid-template-columns: repeat(3, 1fr);
gap: 15px; gap: 10px;
} }
button { button {
border: 3px solid var(--black); border: 3px solid var(--black);
background: white; background: white;
padding: 15px; padding: 12px 5px;
font-weight: 900; font-weight: 900;
cursor: pointer; cursor: pointer;
box-shadow: 4px 4px 0px var(--black); box-shadow: 4px 4px 0px var(--black);
text-transform: uppercase; text-transform: uppercase;
font-size: 0.8rem;
} }
button:active { button:active {
box-shadow: 0px 0px 0px var(--black); box-shadow: 0px 0px 0px var(--black);
transform: translate(4px, 4px); transform: translate(2px, 2px);
} }
button#exitBtn { #exitBtn {
background: #fda4af; background: #fee2e2;
} color: #991b1b;
button#copyRoomBtn {
background: #bae6fd;
} }
@media (max-width: 600px) { @media (max-width: 600px) {
.main-card { .main-card {
padding: 10px; padding: 10px;
border-width: 3px; box-shadow: 4px 4px 0px var(--black);
box-shadow: 6px 6px 0px var(--black); gap: 10px;
} }
.identity-banner { .info-bar {
flex-direction: column; flex-direction: column;
gap: 10px; align-items: stretch;
text-align: center;
}
#status {
text-align: center !important;
} }
.controls { .controls {
grid-template-columns: 1fr; grid-template-columns: 1fr;
} }
.id-box {
font-size: 1rem;
}
} }
</style> </style>
</head> </head>
<body> <body>
<div class="game-wrapper"> <div class="game-wrapper">
<div class="main-card"> <div class="main-card">
<div class="identity-banner"> <div class="info-bar">
<div> <div>
<span style="font-size: 0.8rem; display: block;">DEINE ROLLE:</span> <div class="room-tag">RAUM: <span id="codeDisplay">...</span></div>
<div id="idBadge" class="id-box">...</div> <div id="idBadge" class="id-box">...</div>
</div> </div>
<div id="status">Laden...</div> <div id="status" style="text-align: right; font-weight: 900; line-height: 1.2;">Laden...</div>
</div> </div>
<div class="board-container"> <div class="board-container">
@@ -205,123 +217,97 @@
</div> </div>
<div class="controls"> <div class="controls">
<button id="copyRoomBtn">Link Kopieren</button> <button id="copyRoomBtn">Link</button>
<button id="restartBtn">Neustart</button> <button id="restartBtn">Swap & Reset</button>
<button id="exitBtn">Verlassen</button> <button id="exitBtn">Beenden</button>
</div> </div>
</div> </div>
</div> </div>
<script> <script>
let sessionId = localStorage.getItem("game_session_id") || (Math.random().toString(36).substring(2) + Date.now().toString(36)); let sessionId = localStorage.getItem("game_session_id") || (Math.random().toString(36).substring(2));
localStorage.setItem("game_session_id", sessionId); localStorage.setItem("game_session_id", sessionId);
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
let roomId = params.get("room"); let roomId = params.get("room") || prompt("Raumcode (leer für neu):");
if (!roomId) roomId = prompt("Code (leer für Neu):") || "";
const protocol = location.protocol === "https:" ? "wss" : "ws"; const ws = new WebSocket(`${location.protocol === "https:" ? "wss" : "ws"}://${location.host}?room=${roomId}&sessionId=${sessionId}`);
const ws = new WebSocket(`${protocol}://${location.host}?room=${roomId}&sessionId=${sessionId}`);
const svg = document.querySelector("svg"); const svg = document.querySelector("svg");
let myRole = null, state = null, selected = null;
let myRole = null, state = null, selected = null, currentRoomId = null;
const board_wolf = { 0: [1, 2, 3], 1: [0, 2, 4, 5], 2: [0, 1, 3, 5], 3: [0, 2, 5, 6], 4: [1, 5, 7], 5: [1, 2, 3, 4, 6, 7, 8, 9], 6: [3, 5, 9], 7: [4, 5, 8, 10], 8: [5, 7, 9, 10], 9: [5, 6, 8, 10], 10: [7, 8, 9] };
const board_sheep = { 0: [1, 2, 3], 1: [2, 4, 5], 2: [1, 3, 5], 3: [2, 5, 6], 4: [5, 7], 5: [4, 6, 7, 8, 9], 6: [5, 9], 7: [8, 10], 8: [7, 9, 10], 9: [8, 10], 10: [] };
const pos = { 0: [80, 210], 1: [180, 110], 2: [180, 210], 3: [180, 310], 4: [280, 110], 5: [280, 210], 6: [280, 310], 7: [380, 110], 8: [380, 210], 9: [380, 310], 10: [480, 210] }; const pos = { 0: [80, 210], 1: [180, 110], 2: [180, 210], 3: [180, 310], 4: [280, 110], 5: [280, 210], 6: [280, 310], 7: [380, 110], 8: [380, 210], 9: [380, 310], 10: [480, 210] };
const edges = [[0, 1], [0, 2], [0, 3], [1, 2], [2, 3], [1, 4], [2, 5], [3, 6], [4, 5], [5, 6], [4, 7], [5, 8], [6, 9], [7, 8], [8, 9], [5, 1], [5, 3], [5, 7], [5, 9], [7, 10], [8, 10], [9, 10]]; const edges = [[0, 1], [0, 2], [0, 3], [1, 2], [2, 3], [1, 4], [2, 5], [3, 6], [4, 5], [5, 6], [4, 7], [5, 8], [6, 9], [7, 8], [8, 9], [5, 1], [5, 3], [5, 7], [5, 9], [7, 10], [8, 10], [9, 10]];
const bWolf = { 0: [1, 2, 3], 1: [0, 2, 4, 5], 2: [0, 1, 3, 5], 3: [0, 2, 5, 6], 4: [1, 5, 7], 5: [1, 2, 3, 4, 6, 7, 8, 9], 6: [3, 5, 9], 7: [4, 5, 8, 10], 8: [5, 7, 9, 10], 9: [5, 6, 8, 10], 10: [7, 8, 9] };
const bSheep = { 0: [1, 2, 3], 1: [2, 4, 5], 2: [1, 3, 5], 3: [2, 5, 6], 4: [5, 7], 5: [4, 6, 7, 8, 9], 6: [5, 9], 7: [8, 10], 8: [7, 9, 10], 9: [8, 10], 10: [] };
ws.onmessage = e => { ws.onmessage = e => {
const msg = JSON.parse(e.data); const msg = JSON.parse(e.data);
if (msg.type === "role") { if (msg.type === "init") {
myRole = msg.role; document.getElementById("codeDisplay").innerText = msg.roomId;
currentRoomId = msg.roomId; if (!params.has("room")) window.history.replaceState({}, '', `?room=${msg.roomId}`);
const badge = document.getElementById("idBadge"); }
badge.innerText = myRole === "wolf" ? "DER WOLF" : "DIE SCHAFE"; if (msg.type === "state") {
badge.className = `id-box is-${myRole}`; state = msg.game;
if (!params.has("room")) window.history.replaceState({}, '', `?room=${currentRoomId}`); myRole = msg.yourRole;
updateUI();
render();
} }
if (msg.type === "state") { state = msg.game; render(); }
}; };
function render() { function updateUI() {
if (!state) return; const badge = document.getElementById("idBadge");
svg.innerHTML = ""; badge.innerText = myRole === "wolf" ? "WOLF" : "SCHAFE";
badge.className = `id-box is-${myRole}`;
const statusEl = document.getElementById("status"); const statusEl = document.getElementById("status");
if (state.winner) { if (state.winner) {
statusEl.innerHTML = `ENDE: ${state.winner.toUpperCase()} GEWINNT!`; statusEl.innerHTML = `SIEG: ${state.winner === 'wolf' ? 'WOLF' : 'SCHAFE'}`;
} else { } else {
statusEl.innerHTML = (state.turn === myRole ? "DU BIST DRAN" : "WARTE...") + `<br><small>ZUG ${state.moveCount}/40</small>`; statusEl.innerHTML = `${state.turn === myRole ? 'DEIN ZUG' : 'Gegner...'}<br><small>ZUG ${state.moveCount}/40</small>`;
} }
}
function render() {
svg.innerHTML = "";
edges.forEach(([a, b]) => { edges.forEach(([a, b]) => {
const line = document.createElementNS("http://www.w3.org/2000/svg", "line"); const l = document.createElementNS("http://www.w3.org/2000/svg", "line");
line.setAttribute("x1", pos[a][0]); line.setAttribute("y1", pos[a][1]); l.setAttribute("x1", pos[a][0]); l.setAttribute("y1", pos[a][1]);
line.setAttribute("x2", pos[b][0]); line.setAttribute("y2", pos[b][1]); l.setAttribute("x2", pos[b][0]); l.setAttribute("y2", pos[b][1]);
line.setAttribute("class", "edge"); l.setAttribute("class", "edge"); svg.appendChild(l);
svg.appendChild(line);
}); });
for (let i = 0; i <= 10; i++) { for (let i = 0; i <= 10; i++) {
const [x, y] = pos[i]; const [x, y] = pos[i];
let type = "empty"; let type = state.wolf === i ? "wolf" : (state.sheep.includes(i) ? "sheep" : "empty");
if (state.wolf === i) type = "wolf"; const isPossible = selected !== null && (myRole === "wolf" ? bWolf[selected] : bSheep[selected]).includes(i) && state.wolf !== i && !state.sheep.includes(i);
if (state.sheep.includes(i)) type = "sheep";
const isPossible = selected !== null && const g = document.createElementNS("http://www.w3.org/2000/svg", "g");
(myRole === "wolf" ? board_wolf[selected] : board_sheep[selected]).includes(i) && g.onclick = () => {
state.wolf !== i && !state.sheep.includes(i); if (state.turn !== myRole || state.winner) return;
const isMine = (myRole === "wolf" && state.wolf === i) || (myRole === "sheep" && state.sheep.includes(i));
if (selected === null) { if (isMine) selected = i; }
else { if (isMine) selected = (selected === i ? null : i); else { ws.send(JSON.stringify({ from: selected, to: i })); selected = null; } }
render();
};
const group = document.createElementNS("http://www.w3.org/2000/svg", "g"); const c = document.createElementNS("http://www.w3.org/2000/svg", "circle");
group.style.cursor = "pointer"; c.setAttribute("cx", x); c.setAttribute("cy", y); c.setAttribute("r", 25);
group.onclick = () => handleClick(i); c.setAttribute("class", `node-circle ${type} ${selected === i ? 'selected' : ''} ${isPossible ? 'possible' : ''}`);
g.appendChild(c);
const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle"); const t = document.createElementNS("http://www.w3.org/2000/svg", "text");
circle.setAttribute("cx", x); circle.setAttribute("cy", y); circle.setAttribute("r", 26); t.setAttribute("x", x); t.setAttribute("y", y + 5);
circle.setAttribute("class", `node-circle ${type} ${selected === i ? 'selected' : ''} ${isPossible ? 'possible' : ''}`); t.setAttribute("text-anchor", "middle");
t.setAttribute("class", "node-label");
group.appendChild(circle); t.setAttribute("fill", (type === "empty" ? "black" : "white"));
t.textContent = i; g.appendChild(t);
// Added Numbers back to nodes svg.appendChild(g);
const txt = document.createElementNS("http://www.w3.org/2000/svg", "text");
txt.setAttribute("x", x); txt.setAttribute("y", y + 6);
txt.setAttribute("text-anchor", "middle");
txt.setAttribute("class", "node-label");
txt.setAttribute("fill", (type === "empty" || selected === i) ? "black" : "white");
txt.textContent = i;
group.appendChild(txt);
svg.appendChild(group);
} }
} }
function handleClick(i) { document.getElementById("restartBtn").onclick = () => { selected = null; ws.send(JSON.stringify({ type: "restart" })); };
if (!state || state.turn !== myRole || state.winner) return; document.getElementById("copyRoomBtn").onclick = () => { navigator.clipboard.writeText(window.location.href); alert("Kopiert!"); };
const isMyPiece = (myRole === "wolf" && state.wolf === i) || (myRole === "sheep" && state.sheep.includes(i)); document.getElementById("exitBtn").onclick = () => { if (confirm("Beenden?")) { ws.send(JSON.stringify({ type: "leave" })); window.location.href = window.location.pathname; } };
if (selected === null) {
if (isMyPiece) { selected = i; render(); }
} else {
if (isMyPiece) {
selected = (selected === i) ? null : i;
} else {
ws.send(JSON.stringify({ from: selected, to: i }));
selected = null;
}
render();
}
}
document.getElementById("restartBtn").onclick = () => ws.send(JSON.stringify({ type: "restart" }));
document.getElementById("copyRoomBtn").onclick = () => {
navigator.clipboard.writeText(window.location.href).then(() => alert("Link kopiert!"));
};
document.getElementById("exitBtn").onclick = () => {
if (confirm("Raum verlassen?")) {
ws.send(JSON.stringify({ type: "leave" }));
window.location.href = window.location.pathname;
}
};
</script> </script>
</body> </body>

109
server.js
View File

@@ -9,67 +9,26 @@ app.use(express.static("public"));
const server = http.createServer(app); const server = http.createServer(app);
const wss = new WebSocket.Server({ server }); const wss = new WebSocket.Server({ server });
const board_wolf = { const board_wolf = { 0: [1, 2, 3], 1: [0, 2, 4, 5], 2: [0, 1, 3, 5], 3: [0, 2, 5, 6], 4: [1, 5, 7], 5: [1, 2, 3, 4, 6, 7, 8, 9], 6: [3, 5, 9], 7: [4, 5, 8, 10], 8: [5, 7, 9, 10], 9: [5, 6, 8, 10], 10: [7, 8, 9] };
0: [1, 2, 3], 1: [0, 2, 4, 5], 2: [0, 1, 3, 5], 3: [0, 2, 5, 6], 4: [1, 5, 7], const board_sheep = { 0: [1, 2, 3], 1: [2, 4, 5], 2: [1, 3, 5], 3: [2, 5, 6], 4: [5, 7], 5: [4, 6, 7, 8, 9], 6: [5, 9], 7: [8, 10], 8: [7, 9, 10], 9: [8, 10], 10: [] };
5: [1, 2, 3, 4, 6, 7, 8, 9], 6: [3, 5, 9], 7: [4, 5, 8, 10], 8: [5, 7, 9, 10],
9: [5, 6, 8, 10], 10: [7, 8, 9]
};
const board_sheep = {
0: [1, 2, 3], 1: [2, 4, 5], 2: [1, 3, 5], 3: [2, 5, 6], 4: [5, 7],
5: [4, 6, 7, 8, 9], 6: [5, 9], 7: [8, 10], 8: [7, 9, 10], 9: [8, 10], 10: []
};
const rooms = {}; const rooms = {};
function broadcast(roomId) { function broadcast(roomId) {
const room = rooms[roomId]; const room = rooms[roomId];
if (!room) return; if (!room) return;
const msg = JSON.stringify({ type: "state", game: room.game });
room.players.forEach(p => { room.players.forEach(p => {
if (p.ws && p.ws.readyState === WebSocket.OPEN) p.ws.send(msg); if (p.ws && p.ws.readyState === WebSocket.OPEN) {
p.ws.send(JSON.stringify({
type: "state",
game: room.game,
yourRole: p.role
}));
}
}); });
} }
function checkWinConditions(game) {
if (game.wolf === 0) return "wolf";
if (game.moveCount >= 40) return "wolf";
const canWolfMove = board_wolf[game.wolf].some(to => !game.sheep.includes(to));
const canSheepMove = game.sheep.some(from =>
board_sheep[from].some(to => to !== game.wolf && !game.sheep.includes(to))
);
if (!canWolfMove) return "sheep";
if (!canSheepMove && game.turn === "sheep") return "wolf";
return null;
}
function handleMove(roomId, role, { from, to }) {
const room = rooms[roomId];
if (!room || room.game.winner) return;
const game = room.game;
if (game.turn !== role) return;
const allowed = (role === "wolf") ? board_wolf[from] : board_sheep[from];
if (!allowed?.includes(to)) return;
if (game.sheep.includes(to) || game.wolf === to) return;
if (role === "wolf") {
if (from !== game.wolf) return;
game.wolf = to;
game.turn = "sheep";
} else {
const i = game.sheep.indexOf(from);
if (i === -1) return;
game.sheep[i] = to;
game.turn = "wolf";
}
game.moveCount++;
game.winner = checkWinConditions(game);
broadcast(roomId);
}
wss.on("connection", (ws, req) => { wss.on("connection", (ws, req) => {
const urlParams = new URLSearchParams(req.url.split('?')[1]); const urlParams = new URLSearchParams(req.url.split('?')[1]);
let roomId = urlParams.get("room"); let roomId = urlParams.get("room");
@@ -79,7 +38,8 @@ wss.on("connection", (ws, req) => {
if (!roomId) roomId = randomBytes(3).toString("hex"); if (!roomId) roomId = randomBytes(3).toString("hex");
rooms[roomId] = { rooms[roomId] = {
game: { wolf: 5, sheep: [0, 1, 3], turn: "sheep", moveCount: 0, winner: null }, game: { wolf: 5, sheep: [0, 1, 3], turn: "sheep", moveCount: 0, winner: null },
players: [] players: [],
nextFirstRole: "sheep" // Tracks who should be sheep next game
}; };
} }
@@ -93,35 +53,58 @@ wss.on("connection", (ws, req) => {
} }
if (player) { if (player) {
player.ws = ws; // Re-attach new socket to existing session player.ws = ws;
} else { } else {
const role = room.players.length === 0 ? "sheep" : "wolf"; // Assign role based on who is already there
const role = room.players.length === 0 ? room.nextFirstRole : (room.nextFirstRole === "sheep" ? "wolf" : "sheep");
player = { ws, role, sessionId }; player = { ws, role, sessionId };
room.players.push(player); room.players.push(player);
} }
ws.send(JSON.stringify({ type: "role", role: player.role, roomId })); ws.send(JSON.stringify({ type: "init", role: player.role, roomId }));
broadcast(roomId); broadcast(roomId);
ws.on("message", msg => { ws.on("message", msg => {
let data; let data = JSON.parse(msg);
try { data = JSON.parse(msg); } catch { return; }
if (data.type === "restart") { if (data.type === "restart") {
// Swap roles for the next round
room.players.forEach(p => p.role = (p.role === "wolf" ? "sheep" : "wolf"));
room.game = { wolf: 5, sheep: [0, 1, 3], turn: "sheep", moveCount: 0, winner: null }; room.game = { wolf: 5, sheep: [0, 1, 3], turn: "sheep", moveCount: 0, winner: null };
broadcast(roomId); broadcast(roomId);
} else if (data.type === "leave") { } else if (data.type === "leave") {
room.players = room.players.filter(p => p.sessionId !== sessionId); room.players = room.players.filter(p => p.sessionId !== sessionId);
if (room.players.length === 0) delete rooms[roomId]; if (room.players.length === 0) delete rooms[roomId];
ws.close();
} else { } else {
handleMove(roomId, player.role, data); handleMove(roomId, player.role, data);
} }
}); });
ws.on("close", () => {
// We don't remove the player here so they can reconnect on refresh
});
}); });
server.listen(3030, () => console.log("Server läuft auf Port 3030")); // Reuse the handleMove and checkWinConditions from previous scripts...
function checkWinConditions(game) {
if (game.wolf === 0) return "wolf";
if (game.moveCount >= 40) return "wolf";
const canWolfMove = board_wolf[game.wolf].some(to => !game.sheep.includes(to));
const canSheepMove = game.sheep.some(from => board_sheep[from].some(to => to !== game.wolf && !game.sheep.includes(to)));
if (!canWolfMove) return "sheep";
if (!canSheepMove && game.turn === "sheep") return "wolf";
return null;
}
function handleMove(roomId, role, { from, to }) {
const room = rooms[roomId];
if (!room || room.game.winner || room.game.turn !== role) return;
const game = room.game;
const allowed = (role === "wolf") ? board_wolf[from] : board_sheep[from];
if (!allowed?.includes(to) || game.sheep.includes(to) || game.wolf === to) return;
if (role === "wolf") { game.wolf = to; game.turn = "sheep"; }
else { game.sheep[game.sheep.indexOf(from)] = to; game.turn = "wolf"; }
game.moveCount++;
game.winner = checkWinConditions(game);
broadcast(roomId);
}
server.listen(3030);