Actuall server mapping

This commit is contained in:
2026-02-11 16:29:03 +01:00
parent de2684d4c1
commit 44694abad2

View File

@@ -55,18 +55,22 @@ const botServer = net.createServer((socket) => {
if (game.turn !== bot.role || game.winner) return; if (game.turn !== bot.role || game.winner) return;
// Handle Bot Move (e.g., "nw" or "3o")
let from, to; let from, to;
if (bot.role === "wolf") { if (bot.role === "wolf") {
from = game.wolf; from = game.wolf;
const targetDir = msg.toLowerCase(); const targetDir = msg.toLowerCase();
to = board_wolf[from].find(t => getDir(from, t) === targetDir); to = board_wolf[from].find(t => getDir(from, t) === targetDir);
} else { } else {
const sheepId = parseInt(msg[0]); // FIX: Parse the first character as the sheep index (1-3)
const sheepIndex = parseInt(msg[0]) - 1; // Convert 1-3 to 0-2 array index
const targetDir = msg.substring(1).toLowerCase(); const targetDir = msg.substring(1).toLowerCase();
from = sheepId;
// Ensure the index is valid (0, 1, or 2)
if (game.sheep[sheepIndex] !== undefined) {
from = game.sheep[sheepIndex]; // Get board position (e.g., 6)
to = board_sheep[from].find(t => getDir(from, t) === targetDir); to = board_sheep[from].find(t => getDir(from, t) === targetDir);
} }
}
if (to !== undefined) { if (to !== undefined) {
handleMove(roomId, bot.role, { from, to }); handleMove(roomId, bot.role, { from, to });