Files
ChessHub/backend/chessbot.js
T
Moon Patel e87629f736 stockfish chess engine added
the engine is compatible wiht linux systems. If you are running on
windows add windows engine.
2023-10-13 03:04:58 +05:30

25 lines
656 B
JavaScript

const { Engine } = require("node-uci");
require("dotenv").config();
const engine = new Engine(process.env.CHESS_ENGINE_PATH || "./engine/stockfish16.exe");
engine
.init()
.then((eng) => {
return eng.setoption("UCI_LimitStrength", true);
})
.then((eng) => {
eng.setoption("UCI_Elo");
});
const nextMove = async ({ position }) => {
await engine.isready();
console.log("Chess engine ready");
engine.position(position);
const result = await engine.go({ depth: 10 });
console.log("Best move or position", position, "is", result.bestmove);
return result.bestmove;
};
module.exports = { nextMove };