UNPKG

cm-engine-runner

Version:

Abstraction layer to run chess engines, supports opening books

47 lines (42 loc) 2.19 kB
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>cm-engine-runner</title> </head> <body> <h1>cm-engine-runner</h1> <p>Logs are in the developer console</p> <script src="https://cdn.jsdelivr.net/npm/es-module-shims@1.7.2/dist/es-module-shims.min.js"></script> <!-- @formatter:off --> <script type="importmap"> { "imports": { "cm-polyglot/": "./node_modules/cm-polyglot/" } } </script> <!-- @formatter:on --> <script type="module" crossorigin="anonymous"> import {PolyglotRunner} from "./src/PolyglotRunner.js" import {StockfishRunner} from "./src/StockfishRunner.js" const polyglotRunner = new PolyglotRunner({bookUrl: "./assets/books/openings.bin", responseDelay: 0, debug: true}) const startingPosition = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" const startingFewMoves = "rnbqkbnr/pppppp2/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 1" console.log("polyglot", startingPosition, await polyglotRunner.calculateMove(startingPosition)) console.log("polyglot", startingFewMoves, await polyglotRunner.calculateMove(startingFewMoves)) const positionEndGame = "8/8/8/2k5/4K3/8/8/8" console.log("polyglot", positionEndGame, await polyglotRunner.calculateMove(positionEndGame)) const stockfishRunner = new StockfishRunner({workerUrl: "./engines/stockfish-v10-niklasf.js", responseDelay: 0, debug: true}) console.log("stockfish", await stockfishRunner.calculateMove(startingFewMoves)) const postitionBlackWillWin = "4k3/3r4/8/8/8/8/6K1/8 w - - 0 1" console.log("stockfish", await stockfishRunner.calculateMove(postitionBlackWillWin, {level: 1})) console.log("stockfish", await stockfishRunner.calculateMove(postitionBlackWillWin, {level: 10})) const positionManyPawns = "ppppkppp/pppppppp/pppppppp/pppppppp/8/5N2/8/RNBQKB1R b KQ - 0 1" console.log("stockfish", await stockfishRunner.calculateMove(positionManyPawns, {level: 3})) </script> </body> </html>