Chess.com Bot Pro

Bot avançado para Chess.com com múltiplas funcionalidades

  1. // ==UserScript==
  2. // @name Chess.com Bot Pro
  3. // @namespace ChessBotPro
  4. // @version 3.0.0
  5. // @description Bot avançado para Chess.com com múltiplas funcionalidades
  6. // @author Perplexity AI
  7. // @match https://www.chess.com/play/*
  8. // @match https://www.chess.com/game/*
  9. // @match https://www.chess.com/puzzles/*
  10. // @require https://cdnjs.cloudflare.com/ajax/libs/stockfish.js/9.0.0/stockfish.js
  11. // @require https://code.jquery.com/jquery-3.6.0.min.js
  12. // @grant GM_addStyle
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. class ChessBot {
  19. constructor() {
  20. this.engine = null;
  21. this.isThinking = false;
  22. this.autoRun = false;
  23. this.trainingMode = false;
  24. this.delay = 1.0;
  25. this.depth = 15;
  26. this.moveHistory = [];
  27. this.currentBestMoves = [];
  28. this.currentEval = '--';
  29. this.init();
  30. }
  31.  
  32. init() {
  33. this.initEngine();
  34. this.setupUI();
  35. this.setupEventListeners();
  36. this.mainLoop();
  37. }
  38.  
  39. initEngine() {
  40. if (this.engine) this.engine.terminate();
  41. this.engine = new Worker(URL.createObjectURL(new Blob([GM_getResourceText('stockfish.js')], {type: 'application/javascript'})));
  42. this.engine.onmessage = (e) => {
  43. this.handleEngineMessage(e.data);
  44. };
  45.  
  46. this.engine.postMessage('uci');
  47. this.engine.postMessage('setoption name Skill Level value 20');
  48. this.engine.postMessage('ucinewgame');
  49. }
  50.  
  51. handleEngineMessage(data) {
  52. if (data.startsWith('info')) {
  53. this.parseEvaluation(data);
  54. this.parseBestMoves(data);
  55. }
  56.  
  57. if (data.startsWith('bestmove')) {
  58. const move = data.split(' ')[1];
  59. this.processBestMove(move);
  60. }
  61. }
  62.  
  63. parseEvaluation(data) {
  64. const evalMatch = data.match(/score (cp|mate) ([-\d]+)/);
  65. if (evalMatch) {
  66. const [_, type, value] = evalMatch;
  67. this.currentEval = type === 'cp'
  68. ? `${(value / 100).toFixed(1)} pawns`
  69. : `Mate in ${Math.abs(value)}`;
  70. this.updateUI();
  71. }
  72. }
  73.  
  74. parseBestMoves(data) {
  75. const pvMatch = data.match(/pv (\S+)/);
  76. if (pvMatch) {
  77. this.currentBestMoves = pvMatch[1].split(' ').slice(0, 3);
  78. this.updateUI();
  79. }
  80. }
  81.  
  82. processBestMove(move) {
  83. this.isThinking = false;
  84. this.addToHistory(move);
  85. this.highlightMove(move);
  86. if (this.autoRun && !this.trainingMode) {
  87. this.makeMove(move);
  88. }
  89. }
  90.  
  91. async makeMove(move) {
  92. const [from, to] = this.splitMove(move);
  93. await this.simulateHumanClick(from);
  94. await new Promise(resolve => setTimeout(resolve, 500));
  95. await this.simulateHumanClick(to);
  96. }
  97.  
  98. splitMove(move) {
  99. return [move.substring(0,2), move.substring(2,4)];
  100. }
  101.  
  102. async simulateHumanClick(square) {
  103. const element = $(`div[data-square="${square}"]`);
  104. if (element.length) {
  105. element[0].dispatchEvent(new MouseEvent('mousedown', {
  106. bubbles: true,
  107. cancelable: true
  108. }));
  109. }
  110. }
  111.  
  112. addToHistory(move) {
  113. this.moveHistory.push(move);
  114. if (this.moveHistory.length > 10) this.moveHistory.shift();
  115. this.updateUI();
  116. }
  117.  
  118. highlightMove(move) {
  119. $('.chessbot-highlight').removeClass('chessbot-highlight');
  120. $(`div[data-square="${move.substring(0,2)}"], div[data-square="${move.substring(2,4)}"]`)
  121. .addClass('chessbot-highlight');
  122. }
  123.  
  124. updateUI() {
  125. $('#chessbot-eval').text(`Avaliação: ${this.currentEval}`);
  126. $('#chessbot-topmoves').text(`Melhores lances: ${this.currentBestMoves.join(', ')}`);
  127. $('#chessbot-history').html(this.moveHistory.map(m => `<li>${m}</li>`).join(''));
  128. }
  129.  
  130. setupUI() {
  131. GM_addStyle(`
  132. #chessbot-panel {
  133. position: fixed;
  134. top: 20px;
  135. right: 20px;
  136. background: #1a1a1a;
  137. color: #fff;
  138. padding: 15px;
  139. border-radius: 10px;
  140. z-index: 99999;
  141. box-shadow: 0 4px 6px rgba(0,0,0,0.3);
  142. min-width: 250px;
  143. }
  144. .chessbot-highlight {
  145. background: rgba(255,255,0,0.3) !important;
  146. }
  147. #chessbot-history {
  148. max-height: 150px;
  149. overflow-y: auto;
  150. margin: 10px 0;
  151. padding: 0;
  152. list-style: none;
  153. }
  154. .chessbot-btn {
  155. background: #404040;
  156. border: none;
  157. color: #fff;
  158. padding: 8px 15px;
  159. margin: 5px;
  160. border-radius: 5px;
  161. cursor: pointer;
  162. transition: 0.3s;
  163. }
  164. .chessbot-btn.active {
  165. background: #4CAF50;
  166. }
  167. `);
  168.  
  169. $('body').append(`
  170. <div id="chessbot-panel">
  171. <h3 style="margin:0 0 10px 0">ChessBot Pro</h3>
  172. <div id="chessbot-eval">Avaliação: --</div>
  173. <div id="chessbot-topmoves">Melhores lances: --</div>
  174. <ul id="chessbot-history"></ul>
  175. <div>
  176. <button class="chessbot-btn" id="chessbot-autorun">Autorun: OFF</button>
  177. <button class="chessbot-btn" id="chessbot-train">Modo Treino: OFF</button>
  178. </div>
  179. <div>
  180. <input type="number" id="chessbot-depth" value="15" min="1" max="25" style="width:60px;">
  181. <button class="chessbot-btn" id="chessbot-setdepth">Set Depth</button>
  182. </div>
  183. </div>
  184. `);
  185. }
  186.  
  187. setupEventListeners() {
  188. $('#chessbot-autorun').click(() => this.toggleAutoRun());
  189. $('#chessbot-train').click(() => this.toggleTrainingMode());
  190. $('#chessbot-setdepth').click(() => this.setDepth());
  191. document.addEventListener('keydown', (e) => {
  192. if (e.key === 'a') this.toggleAutoRun();
  193. if (e.key === 't') this.toggleTrainingMode();
  194. });
  195. }
  196.  
  197. toggleAutoRun() {
  198. this.autoRun = !this.autoRun;
  199. $('#chessbot-autorun')
  200. .text(`Autorun: ${this.autoRun ? 'ON' : 'OFF'}`)
  201. .toggleClass('active', this.autoRun);
  202. }
  203.  
  204. toggleTrainingMode() {
  205. this.trainingMode = !this.trainingMode;
  206. $('#chessbot-train')
  207. .text(`Modo Treino: ${this.trainingMode ? 'ON' : 'OFF'}`)
  208. .toggleClass('active', this.trainingMode);
  209. }
  210.  
  211. setDepth() {
  212. this.depth = Math.min(25, Math.max(1, parseInt($('#chessbot-depth').val())));
  213. $('#chessbot-depth').val(this.depth);
  214. }
  215.  
  216. getFEN() {
  217. return $('chess-board')[0]?.game?.getFEN() || '';
  218. }
  219.  
  220. mainLoop() {
  221. setInterval(() => {
  222. if (this.shouldAnalyze()) {
  223. this.analyzePosition();
  224. }
  225. }, this.delay * 1000);
  226. }
  227.  
  228. shouldAnalyze() {
  229. return !this.isThinking &&
  230. this.autoRun &&
  231. !this.isGameEnded() &&
  232. this.isPlayerTurn();
  233. }
  234.  
  235. isPlayerTurn() {
  236. const fen = this.getFEN();
  237. return fen.split(' ')[1] === (this.trainingMode ? 'w' : 'b');
  238. }
  239.  
  240. isGameEnded() {
  241. return $('.game-over').length > 0;
  242. }
  243.  
  244. analyzePosition() {
  245. this.isThinking = true;
  246. this.engine.postMessage(`position fen ${this.getFEN()}`);
  247. this.engine.postMessage(`go depth ${this.depth}`);
  248. }
  249. }
  250.  
  251. // Inicialização
  252. window.addEventListener('load', () => new ChessBot());
  253. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址