Advertisement
CodeCrusader

chess.com Stockfish 15 Aid

Jun 7th, 2023 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.36 KB | Source Code | 0 0
  1. // USE THIS AT YOUR OWN RISK - I AM NOT AT FAULT OR RESPONSIBLE FOR ANYTHING
  2. // How to use: 1. Go to chess.com   2. Go into a game   3. Open inspect element/developer tools, the console and then paste the code and press enter  4. Voila! The best move is being highlighted as  a blue square.
  3.  
  4. // Load Stockfish 15 engine
  5. const stockfish = new Worker('https://cdn.jsdelivr.net/npm/stockfish-15-js/stockfish-15-js.js');
  6.  
  7. // Set the position of the chess board
  8. const position = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1';
  9.  
  10. // Set the difficulty level of the engine
  11. const level = 20;
  12.  
  13. // Send commands to Stockfish engine
  14. stockfish.postMessage('uci');
  15. stockfish.postMessage(`position fen ${position}`);
  16. stockfish.postMessage(`go depth ${level}`);
  17.  
  18. // Listen for the best move from Stockfish engine
  19. stockfish.onmessage = (event) => {
  20.   const message = event.data;
  21.  
  22.   if (message.startsWith('bestmove')) {
  23.     const bestMove = message.split(' ')[1];
  24.  
  25.     // Highlight the best move on the chess board
  26.     const squares = document.querySelectorAll('.cg-board .cg-square');
  27.     squares.forEach((square) => {
  28.       if (square.dataset.square === bestMove.slice(0, 2)) {
  29.         square.style.backgroundColor = 'green';
  30.       } else if (square.dataset.square === bestMove.slice(2, 4)) {
  31.         square.style.backgroundColor = 'yellow';
  32.       }
  33.     });
  34.   }
  35. };
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement