From 44694abad2595ead5861eab40cecb81d62ddd04b Mon Sep 17 00:00:00 2001 From: Simon Oberzier Date: Wed, 11 Feb 2026 16:29:03 +0100 Subject: [PATCH] Actuall server mapping --- server.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index a55bef4..e33aa70 100644 --- a/server.js +++ b/server.js @@ -55,17 +55,21 @@ const botServer = net.createServer((socket) => { if (game.turn !== bot.role || game.winner) return; - // Handle Bot Move (e.g., "nw" or "3o") let from, to; if (bot.role === "wolf") { from = game.wolf; const targetDir = msg.toLowerCase(); to = board_wolf[from].find(t => getDir(from, t) === targetDir); } 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(); - from = sheepId; - to = board_sheep[from].find(t => getDir(from, t) === targetDir); + + // 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); + } } if (to !== undefined) {