Actuall server mapping
This commit is contained in:
12
server.js
12
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) {
|
||||
|
||||
Reference in New Issue
Block a user