// Assets/ChessEngines/fairy-chess-server/engine-path.js import path from 'path'; import os from 'os'; import { fileURLToPath } from 'url'; import { dirname } from 'path'; // Get current file's directory in ES modules const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); function getEnginePath() { // First check if path is provided through environment variable if (process.env.FAIRY_STOCKFISH_PATH) { return process.env.FAIRY_STOCKFISH_PATH; } // Get the current directory (fairy-chess-server) const currentDir = __dirname; // Navigate up to Assets/ChessEngines const engineBaseDir = path.join(currentDir, '..', '..'); // console.log(engineBaseDir + '/Fairy-Stockfish' + '/src' + '/stockfish') // Determine OS and set appropriate path if (os.platform() === 'win32') { // Windows path return engineBaseDir + '/ChessEngines' + '/stockfish' + '/stockfish.exe' } else { //res://Assets/ChessEngines/Fairy-Stockfish/src/stockfish // Unix-like systems (Linux, macOS) return engineBaseDir + '/ChessEngines'+ '/Fairy-Stockfish' + '/src' + '/stockfish'; } } // Verify engine path exists async function verifyEnginePath(enginePath) { const fs = await import('fs'); if (!fs.existsSync(enginePath)) { throw new Error(`Chess engine not found at path: ${enginePath}`); } return enginePath; } export { getEnginePath, verifyEnginePath };