Chess.com Panel Pro by Akashdeep

Enhances your Chess.com experience with move suggestions, UI enhancements, and customizable features. Credits to GoodtimeswithEno for the initial move highlighting and basic chess engine implementation.

目前為 2025-03-28 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // additional copyright/license info:
  3. //© All Rights Reserved
  4. //
  5. //Chess.com Enhanced Experience © 2024 by Akashdeep
  6. //
  7. // ==UserScript
  8. // @name Chess.com Panel Pro by Akashdeep
  9. // @namespace Akashdeep
  10. // @version 1.0.0.2
  11. // @description Enhances your Chess.com experience with move suggestions, UI enhancements, and customizable features. Credits to GoodtimeswithEno for the initial move highlighting and basic chess engine implementation.
  12. // @author Akashdeep
  13. // @license Chess.com Enhanced Experience © 2024 by Akashdeep, © All Rights Reserved
  14. // @match https://www.chess.com/play/*
  15. // @match https://www.chess.com/game/*
  16. // @match https://www.chess.com/puzzles/*
  17. // @match https://www.chess.com/*
  18. // @icon data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  19. // @grant GM_getValue
  20. // @grant GM_setValue
  21. // @grant GM_xmlhttpRequest
  22. // @grant GM_getResourceText
  23. // @grant GM_registerMenuCommand
  24. // @resource stockfish.js https://cdnjs.cloudflare.com/ajax/libs/stockfish.js/10.0.2/stockfish.js
  25. // @require https://code.jquery.com/jquery-3.6.0.min.js
  26. // @run-at document-start
  27. // @liscense MIT
  28.  
  29. // @downloadURL
  30. // @updateURL
  31. // ==/UserScript==
  32.  
  33. //Don't touch anything below unless you know what your doing!
  34.  
  35. const currentVersion = '1.0.0.2'; // Sets the current version
  36.  
  37. function main() {
  38.  
  39. var stockfishObjectURL;
  40. var engine = document.engine = {};
  41. var myVars = document.myVars = {};
  42. myVars.autoMovePiece = false;
  43. myVars.autoRun = false;
  44. myVars.delay = 0.1;
  45. var myFunctions = document.myFunctions = {};
  46.  
  47. myVars.playStyle = {
  48. aggressive: Math.random() * 0.5 + 0.3, // 0.3-0.8 tendency for aggressive moves
  49. defensive: Math.random() * 0.5 + 0.3, // 0.3-0.8 tendency for defensive moves
  50. tactical: Math.random() * 0.6 + 0.2, // 0.2-0.8 tendency for tactical moves
  51. positional: Math.random() * 0.6 + 0.2 // 0.2-0.8 tendency for positional moves
  52. };
  53.  
  54. myVars.preferredOpenings = [
  55. "e4", "d4", "c4", "Nf3" // Just examples, could be expanded
  56. ].sort(() => Math.random() - 0.5); // Randomize the order
  57.  
  58. myVars.playerFingerprint = GM_getValue('playerFingerprint', {
  59. favoredPieces: Math.random() < 0.5 ? 'knights' : 'bishops',
  60. openingTempo: Math.random() * 0.5 + 0.5, // 0.5-1.0 opening move speed
  61. tacticalAwareness: Math.random() * 0.4 + 0.6, // 0.6-1.0 tactical vision
  62. exchangeThreshold: Math.random() * 0.3 + 0.1, // When to accept exchanges
  63. attackingStyle: ['kingside', 'queenside', 'central'][Math.floor(Math.random() * 3)]
  64. });
  65. // Save on first run
  66. if (!GM_getValue('playerFingerprint')) {
  67. GM_setValue('playerFingerprint', myVars.playerFingerprint);
  68. }
  69.  
  70. // Add to myVars initialization
  71. myVars.tacticalProfile = GM_getValue('tacticalProfile', {
  72. strengths: [
  73. getRandomTacticalStrength(),
  74. getRandomTacticalStrength()
  75. ],
  76. weaknesses: [
  77. getRandomTacticalWeakness(),
  78. getRandomTacticalWeakness()
  79. ]
  80. });
  81.  
  82. // Save on first run
  83. if (!GM_getValue('tacticalProfile')) {
  84. GM_setValue('tacticalProfile', myVars.tacticalProfile);
  85. }
  86.  
  87. function getRandomTacticalStrength() {
  88. const strengths = [
  89. 'fork', 'pin', 'skewer', 'discovery', 'zwischenzug',
  90. 'removing-defender', 'attraction'
  91. ];
  92. return strengths[Math.floor(Math.random() * strengths.length)];
  93. }
  94.  
  95. function getRandomTacticalWeakness() {
  96. const weaknesses = [
  97. 'long-calculation', 'quiet-moves', 'backward-moves',
  98. 'zugzwang', 'prophylaxis', 'piece-coordination'
  99. ];
  100. return weaknesses[Math.floor(Math.random() * weaknesses.length)];
  101. }
  102.  
  103. stop_b = stop_w = 0;
  104. s_br = s_br2 = s_wr = s_wr2 = 0;
  105. obs = "";
  106. myFunctions.rescan = function(lev) {
  107. var ari = $("chess-board")
  108. .find(".piece")
  109. .map(function() {
  110. return this.className;
  111. })
  112. .get();
  113. jack = ari.map(f => f.substring(f.indexOf(' ') + 1));
  114. function removeWord(arr, word) {
  115. for (var i = 0; i < arr.length; i++) {
  116. arr[i] = arr[i].replace(word, '');
  117. }
  118. }
  119. removeWord(ari, 'square-');
  120. jack = ari.map(f => f.substring(f.indexOf(' ') + 1));
  121. for (var i = 0; i < jack.length; i++) {
  122. jack[i] = jack[i].replace('br', 'r')
  123. .replace('bn', 'n')
  124. .replace('bb', 'b')
  125. .replace('bq', 'q')
  126. .replace('bk', 'k')
  127. .replace('bb', 'b')
  128. .replace('bn', 'n')
  129. .replace('br', 'r')
  130. .replace('bp', 'p')
  131. .replace('wp', 'P')
  132. .replace('wr', 'R')
  133. .replace('wn', 'N')
  134. .replace('wb', 'B')
  135. .replace('br', 'R')
  136. .replace('wn', 'N')
  137. .replace('wb', 'B')
  138. .replace('wq', 'Q')
  139. .replace('wk', 'K')
  140. .replace('wb', 'B')
  141. }
  142. str2 = "";
  143. var count = 0,
  144. str = "";
  145. for (var j = 8; j > 0; j--) {
  146. for (var i = 1; i < 9; i++) {
  147. (str = (jack.find(el => el.includes([i] + [j])))) ? str = str.replace(/[^a-zA-Z]+/g, ''): str = "";
  148. if (str == "") {
  149. count++;
  150. str = count.toString();
  151. if (!isNaN(str2.charAt(str2.length - 1))) str2 = str2.slice(0, -1);
  152. else {
  153. count = 1;
  154. str = count.toString()
  155. }
  156. }
  157. str2 += str;
  158. if (i == 8) {
  159. count = 0;
  160. str2 += "/";
  161. }
  162. }
  163. }
  164. str2 = str2.slice(0, -1);
  165. //str2=str2+" KQkq - 0"
  166. color = "";
  167. wk = wq = bk = bq = "0";
  168. const move = $('vertical-move-list')
  169. .children();
  170. if (move.length < 2) {
  171. stop_b = stop_w = s_br = s_br2 = s_wr = s_wr2 = 0;
  172. }
  173. if (stop_b != 1) {
  174. if (move.find(".black.node:contains('K')")
  175. .length) {
  176. bk = "";
  177. bq = "";
  178. stop_b = 1;
  179. console.log('debug secb');
  180. }
  181. } else {
  182. bq = "";
  183. bk = "";
  184. }
  185. if (stop_b != 1)(bk = (move.find(".black.node:contains('O-O'):not(:contains('O-O-O'))")
  186. .length) ? "" : "k") ? (bq = (move.find(".black.node:contains('O-O-O')")
  187. .length) ? bk = "" : "q") : bq = "";
  188. if (s_br != 1) {
  189. if (move.find(".black.node:contains('R')")
  190. .text()
  191. .match('[abcd]+')) {
  192. bq = "";
  193. s_br = 1
  194. }
  195. } else bq = "";
  196. if (s_br2 != 1) {
  197. if (move.find(".black.node:contains('R')")
  198. .text()
  199. .match('[hgf]+')) {
  200. bk = "";
  201. s_br2 = 1
  202. }
  203. } else bk = "";
  204. if (stop_b == 0) {
  205. if (s_br == 0)
  206. if (move.find(".white.node:contains('xa8')")
  207. .length > 0) {
  208. bq = "";
  209. s_br = 1;
  210. console.log('debug b castle_r');
  211. }
  212. if (s_br2 == 0)
  213. if (move.find(".white.node:contains('xh8')")
  214. .length > 0) {
  215. bk = "";
  216. s_br2 = 1;
  217. console.log('debug b castle_l');
  218. }
  219. }
  220. if (stop_w != 1) {
  221. if (move.find(".white.node:contains('K')")
  222. .length) {
  223. wk = "";
  224. wq = "";
  225. stop_w = 1;
  226. console.log('debug secw');
  227. }
  228. } else {
  229. wq = "";
  230. wk = "";
  231. }
  232. if (stop_w != 1)(wk = (move.find(".white.node:contains('O-O'):not(:contains('O-O-O'))")
  233. .length) ? "" : "K") ? (wq = (move.find(".white.node:contains('O-O-O')")
  234. .length) ? wk = "" : "Q") : wq = "";
  235. if (s_wr != 1) {
  236. if (move.find(".white.node:contains('R')")
  237. .text()
  238. .match('[abcd]+')) {
  239. wq = "";
  240. s_wr = 1
  241. }
  242. } else wq = "";
  243. if (s_wr2 != 1) {
  244. if (move.find(".white.node:contains('R')")
  245. .text()
  246. .match('[hgf]+')) {
  247. wk = "";
  248. s_wr2 = 1
  249. }
  250. } else wk = "";
  251. if (stop_w == 0) {
  252. if (s_wr == 0)
  253. if (move.find(".black.node:contains('xa1')")
  254. .length > 0) {
  255. wq = "";
  256. s_wr = 1;
  257. console.log('debug w castle_l');
  258. }
  259. if (s_wr2 == 0)
  260. if (move.find(".black.node:contains('xh1')")
  261. .length > 0) {
  262. wk = "";
  263. s_wr2 = 1;
  264. console.log('debug w castle_r');
  265. }
  266. }
  267. if ($('.coordinates')
  268. .children()
  269. .first()
  270. .text() == 1) {
  271. str2 = str2 + " b " + wk + wq + bk + bq;
  272. color = "white";
  273. } else {
  274. str2 = str2 + " w " + wk + wq + bk + bq;
  275. color = "black";
  276. }
  277. //console.log(str2);
  278. return str2;
  279. }
  280. myFunctions.color = function(dat){
  281. response = dat;
  282. var res1 = response.substring(0, 2);
  283. var res2 = response.substring(2, 4);
  284.  
  285. // Check if automove is enabled and make the move
  286. if(myVars.autoMove === true){
  287. console.log(`Auto move enabled, moving from ${res1} to ${res2}`);
  288. myFunctions.movePiece(res1, res2);
  289. } else {
  290. console.log(`Auto move disabled, highlighting ${res1} to ${res2}`);
  291. }
  292. isThinking = false;
  293.  
  294. res1 = res1.replace(/^a/, "1")
  295. .replace(/^b/, "2")
  296. .replace(/^c/, "3")
  297. .replace(/^d/, "4")
  298. .replace(/^e/, "5")
  299. .replace(/^f/, "6")
  300. .replace(/^g/, "7")
  301. .replace(/^h/, "8");
  302. res2 = res2.replace(/^a/, "1")
  303. .replace(/^b/, "2")
  304. .replace(/^c/, "3")
  305. .replace(/^d/, "4")
  306. .replace(/^e/, "5")
  307. .replace(/^f/, "6")
  308. .replace(/^g/, "7")
  309. .replace(/^h/, "8");
  310.  
  311. // Use custom highlight color if available
  312. const highlightColor = myVars.highlightColor || 'rgb(235, 97, 80)';
  313.  
  314. $(board.nodeName)
  315. .prepend(`<div class="highlight square-${res2} bro" style="background-color: ${highlightColor}; opacity: 0.71;" data-test-element="highlight"></div>`)
  316. .children(':first')
  317. .delay(1800)
  318. .queue(function() {
  319. $(this)
  320. .remove();
  321. });
  322. $(board.nodeName)
  323. .prepend(`<div class="highlight square-${res1} bro" style="background-color: ${highlightColor}; opacity: 0.71;" data-test-element="highlight"></div>`)
  324. .children(':first')
  325. .delay(1800)
  326. .queue(function() {
  327. $(this)
  328. .remove();
  329. });
  330. }
  331.  
  332. myFunctions.movePiece = function(from, to) {
  333. // Check if the move is legal before attempting to make it
  334. let isLegalMove = false;
  335. let moveObject = null;
  336. for (let each = 0; each < board.game.getLegalMoves().length; each++) {
  337. if (board.game.getLegalMoves()[each].from === from &&
  338. board.game.getLegalMoves()[each].to === to) {
  339. isLegalMove = true;
  340. moveObject = board.game.getLegalMoves()[each];
  341. break;
  342. }
  343. }
  344. if (!isLegalMove) {
  345. console.log(`Attempted illegal move: ${from} to ${to}`);
  346. return;
  347. }
  348. // Add a small delay before making the move to simulate human reaction time
  349. setTimeout(() => {
  350. try {
  351. // Make the actual move
  352. board.game.move({
  353. ...moveObject,
  354. promotion: moveObject.promotion || 'q', // Default to queen for simplicity
  355. animate: true,
  356. userGenerated: true
  357. });
  358. console.log(`Successfully moved from ${from} to ${to}`);
  359. } catch (error) {
  360. console.error("Error making move:", error);
  361. }
  362. }, 100 + Math.random() * 300); // Small random delay to appear more human-like
  363. }
  364.  
  365. // Replace simple movement simulation with this more advanced version
  366. function simulateNaturalMouseMovement(from, to, callback) {
  367. // Convert chess coordinates to screen positions
  368. const fromPos = getSquarePosition(from);
  369. const toPos = getSquarePosition(to);
  370.  
  371. // Create a bezier curve path with a slight variance
  372. const controlPoint1 = {
  373. x: fromPos.x + (toPos.x - fromPos.x) * 0.3 + (Math.random() * 40 - 20),
  374. y: fromPos.y + (toPos.y - fromPos.y) * 0.1 + (Math.random() * 40 - 20)
  375. };
  376.  
  377. const controlPoint2 = {
  378. x: fromPos.x + (toPos.x - fromPos.x) * 0.7 + (Math.random() * 40 - 20),
  379. y: fromPos.y + (toPos.y - fromPos.y) * 0.9 + (Math.random() * 40 - 20)
  380. };
  381.  
  382. // Calculate movement duration based on distance
  383. const distance = Math.sqrt(Math.pow(toPos.x - fromPos.x, 2) + Math.pow(toPos.y - fromPos.y, 2));
  384. const baseDuration = 300 + Math.random() * 400;
  385. const movementDuration = baseDuration + distance * (0.5 + Math.random() * 0.5);
  386.  
  387. // Create array of points along path
  388. const steps = 15 + Math.floor(distance / 30);
  389. const points = [];
  390.  
  391. for (let i = 0; i <= steps; i++) {
  392. const t = i / steps;
  393. points.push(getBezierPoint(t, fromPos, controlPoint1, controlPoint2, toPos));
  394. }
  395.  
  396. // Execute the movement with variable speed
  397. executeMouseMovement(points, 0, movementDuration / steps, callback);
  398. }
  399.  
  400. // Add these functions for more realistic timing
  401. function calculateMoveComplexity(from, to) {
  402. // Approximate complexity based on piece type, capture, check, etc.
  403. // Returns a value between 0 (simple) and 1 (complex)
  404. return Math.random() * 0.7 + 0.3; // Placeholder implementation
  405. }
  406.  
  407. function calculateHumanLikeDelay(complexity) {
  408. // More complex positions take longer to think about
  409. const baseDelay = 500; // Base delay in ms
  410. const complexityFactor = 2500; // Max additional delay for complex positions
  411. return baseDelay + (complexity * complexityFactor * Math.random());
  412. }
  413.  
  414. function getRandomThinkingDelay() {
  415. // Humans don't immediately start calculating
  416. return 300 + Math.random() * 700;
  417. }
  418.  
  419. function parser(e) {
  420. if(e.data.includes('bestmove')) {
  421. const bestMove = e.data.split(' ')[1];
  422.  
  423. // Sometimes make a "human-like" suboptimal move
  424. const shouldMakeHumanMove = Math.random() < getBlunderProbability();
  425. if (shouldMakeHumanMove && e.data.includes('ponder')) {
  426. // Try to extract alternative moves or generate a plausible suboptimal move
  427. const actualMove = generateHumanLikeMove(bestMove, e.data);
  428. console.log(`Using human-like move ${actualMove} instead of best move ${bestMove}`);
  429. myFunctions.color(actualMove);
  430. } else {
  431. console.log(bestMove);
  432. myFunctions.color(bestMove);
  433. }
  434. isThinking = false;
  435. }
  436. }
  437.  
  438. function getBlunderProbability() {
  439. // Use custom blunder rate from slider if available
  440. const userBlunderRate = myVars.blunderRate !== undefined ? myVars.blunderRate : 0.05;
  441.  
  442. // Make blunder probability vary based on multiple factors
  443. const gamePhase = estimateGamePhase();
  444. const timeRemaining = estimateTimeRemaining();
  445. const complexity = estimatePositionComplexity();
  446.  
  447. // Base probability comes from user settings
  448. let baseProb = userBlunderRate;
  449.  
  450. // More likely to blunder in time pressure
  451. if (timeRemaining < 30) {
  452. baseProb += 0.1 * (1 - (timeRemaining / 30));
  453. }
  454.  
  455. // More likely to blunder in complex positions
  456. if (complexity > 0.6) {
  457. baseProb += 0.05 * (complexity - 0.6) * 2;
  458. }
  459.  
  460. // More likely to blunder in the endgame when tired
  461. if (gamePhase > 30) {
  462. baseProb += 0.03 * ((gamePhase - 30) / 10);
  463. }
  464.  
  465. // Add randomness to make it unpredictable
  466. return Math.min(0.4, baseProb * (0.7 + Math.random() * 0.6));
  467. }
  468.  
  469. function estimateGamePhase() {
  470. // Estimate how far the game has progressed (0-40 approx)
  471. try {
  472. const moveList = $('vertical-move-list').children().length;
  473. return moveList / 2; // Rough estimate of move number
  474. } catch (e) {
  475. return 15; // Default to middle game
  476. }
  477. }
  478.  
  479. function estimateTimeRemaining() {
  480. // Try to get the clock time if available
  481. try {
  482. const clockEl = document.querySelector('.clock-component');
  483. if (clockEl) {
  484. const timeText = clockEl.textContent;
  485. const minutes = parseInt(timeText.split(':')[0]);
  486. const seconds = parseInt(timeText.split(':')[1]);
  487. return minutes * 60 + seconds;
  488. }
  489. } catch (e) {}
  490.  
  491. // Default value if clock can't be read
  492. return 180;
  493. }
  494.  
  495. function estimatePositionComplexity() {
  496. // Calculate a complexity score between 0-1
  497. // This would ideally analyze the position for tactical elements
  498. return Math.random() * 0.8 + 0.2; // Placeholder
  499. }
  500.  
  501. function generateHumanLikeMove(bestMove, engineData) {
  502. // Significantly enhance the human-like behavior
  503. // Sometimes choose 2nd, 3rd, or even 4th best moves
  504. if (engineData.includes('pv') && Math.random() < 0.4) {
  505. try {
  506. // Extract multiple lines from engine analysis
  507. const lines = engineData.split('\n')
  508. .filter(line => line.includes(' pv '))
  509. .map(line => {
  510. const pvIndex = line.indexOf(' pv ');
  511. return line.substring(pvIndex + 4).split(' ')[0];
  512. });
  513.  
  514. if (lines.length > 1) {
  515. // Weight moves by their quality (prefer better moves, but sometimes choose worse ones)
  516. const moveIndex = Math.floor(Math.pow(Math.random(), 2.5) * Math.min(lines.length, 4));
  517. return lines[moveIndex] || bestMove;
  518. }
  519. } catch (e) {
  520. console.log("Error extracting alternative moves", e);
  521. }
  522. }
  523.  
  524. // Occasionally make a typical human error based on common patterns
  525. if (Math.random() < 0.15) {
  526. // Approximate a plausible human move (e.g., moving to adjacent square)
  527. const fromSquare = bestMove.substring(0, 2);
  528. const toSquare = bestMove.substring(2, 4);
  529.  
  530. // Simple adjustment - occasionally play a shorter move (undershoot)
  531. if (Math.random() < 0.7) {
  532. const files = "abcdefgh";
  533. const ranks = "12345678";
  534. const fromFile = fromSquare.charAt(0);
  535. const fromRank = fromSquare.charAt(1);
  536. const toFile = toSquare.charAt(0);
  537. const toRank = toSquare.charAt(1);
  538.  
  539. // Calculate direction
  540. const fileDiff = files.indexOf(toFile) - files.indexOf(fromFile);
  541. const rankDiff = ranks.indexOf(toRank) - ranks.indexOf(fromRank);
  542.  
  543. // Sometimes undershoot by one square
  544. if (Math.abs(fileDiff) > 1 || Math.abs(rankDiff) > 1) {
  545. const newToFile = files[files.indexOf(fromFile) + (fileDiff > 0 ? Math.max(1, fileDiff-1) : Math.min(-1, fileDiff+1))];
  546. const newToRank = ranks[ranks.indexOf(fromRank) + (rankDiff > 0 ? Math.max(1, rankDiff-1) : Math.min(-1, rankDiff+1))];
  547.  
  548. // Check if the new square is valid
  549. if (newToFile && newToRank) {
  550. const alternativeMove = fromSquare + newToFile + newToRank;
  551. // Verify this is a legal move before returning
  552. for (let each=0; each<board.game.getLegalMoves().length; each++) {
  553. if (board.game.getLegalMoves()[each].from === fromSquare &&
  554. board.game.getLegalMoves()[each].to === newToFile + newToRank) {
  555. return alternativeMove;
  556. }
  557. }
  558. }
  559. }
  560. }
  561. }
  562.  
  563. return bestMove;
  564. }
  565.  
  566. myFunctions.reloadChessEngine = function() {
  567. console.log(`Reloading the chess engine!`);
  568.  
  569. engine.engine.terminate();
  570. isThinking = false;
  571. myFunctions.loadChessEngine();
  572. }
  573.  
  574. myFunctions.loadChessEngine = function() {
  575. if(!stockfishObjectURL) {
  576. stockfishObjectURL = URL.createObjectURL(new Blob([GM_getResourceText('stockfish.js')], {type: 'application/javascript'}));
  577. }
  578. console.log(stockfishObjectURL);
  579. if(stockfishObjectURL) {
  580. engine.engine = new Worker(stockfishObjectURL);
  581.  
  582. engine.engine.onmessage = e => {
  583. parser(e);
  584. };
  585. engine.engine.onerror = e => {
  586. console.log("Worker Error: "+e);
  587. };
  588.  
  589. engine.engine.postMessage('ucinewgame');
  590. }
  591. console.log('loaded chess engine');
  592. }
  593.  
  594. var lastValue = 11;
  595. myFunctions.runChessEngine = function(depth) {
  596. // Add variable depth based on position type
  597. var fen = board.game.getFEN();
  598. var positionType = analyzePositionType(fen);
  599. var effectiveDepth = adjustDepthByPosition(depth, positionType);
  600.  
  601. engine.engine.postMessage(`position fen ${fen}`);
  602. console.log('updated: ' + `position fen ${fen}`);
  603. isThinking = true;
  604. engine.engine.postMessage(`go depth ${effectiveDepth}`);
  605. lastValue = depth; // Keep original depth for UI display
  606. }
  607.  
  608. function analyzePositionType(fen) {
  609. // Determine position type: opening, middlegame, endgame, tactical
  610. const piecesCount = fen.split(' ')[0].match(/[pnbrqkPNBRQK]/g).length;
  611.  
  612. if (piecesCount > 25) return 'opening';
  613. if (piecesCount < 12) return 'endgame';
  614. return 'middlegame';
  615. }
  616.  
  617. function adjustDepthByPosition(requestedDepth, positionType) {
  618. // Humans play more accurately in different phases
  619. if (positionType === 'opening' && Math.random() < 0.7) {
  620. // In openings, humans often play memorized moves
  621. return requestedDepth + Math.floor(Math.random() * 3);
  622. } else if (positionType === 'endgame' && Math.random() < 0.5) {
  623. // In endgames, calculation may be more/less precise
  624. return requestedDepth + (Math.random() < 0.5 ? -1 : 1);
  625. }
  626.  
  627. // Occasionally randomize depth slightly
  628. return Math.max(1, requestedDepth + (Math.random() < 0.3 ? Math.floor(Math.random() * 3) - 1 : 0));
  629. }
  630.  
  631. myFunctions.autoRun = function(lstValue){
  632. if(board.game.getTurn() == board.game.getPlayingAs()){
  633. myFunctions.runChessEngine(lstValue);
  634. }
  635. }
  636.  
  637. document.onkeydown = function(e) {
  638. switch (e.keyCode) {
  639. case 81:
  640. myFunctions.runChessEngine(1);
  641. break;
  642. case 87:
  643. myFunctions.runChessEngine(2);
  644. break;
  645. case 69:
  646. myFunctions.runChessEngine(3);
  647. break;
  648. case 82:
  649. myFunctions.runChessEngine(4);
  650. break;
  651. case 84:
  652. myFunctions.runChessEngine(5);
  653. break;
  654. case 89:
  655. myFunctions.runChessEngine(6);
  656. break;
  657. case 85:
  658. myFunctions.runChessEngine(7);
  659. break;
  660. case 73:
  661. myFunctions.runChessEngine(8);
  662. break;
  663. case 79:
  664. myFunctions.runChessEngine(9);
  665. break;
  666. case 80:
  667. myFunctions.runChessEngine(10);
  668. break;
  669. case 65:
  670. myFunctions.runChessEngine(11);
  671. break;
  672. case 83:
  673. myFunctions.runChessEngine(12);
  674. break;
  675. case 68:
  676. myFunctions.runChessEngine(13);
  677. break;
  678. case 70:
  679. myFunctions.runChessEngine(14);
  680. break;
  681. case 71:
  682. myFunctions.runChessEngine(15);
  683. break;
  684. case 72:
  685. myFunctions.runChessEngine(16);
  686. break;
  687. case 74:
  688. myFunctions.runChessEngine(17);
  689. break;
  690. case 75:
  691. myFunctions.runChessEngine(18);
  692. break;
  693. case 76:
  694. myFunctions.runChessEngine(19);
  695. break;
  696. case 90:
  697. myFunctions.runChessEngine(20);
  698. break;
  699. case 88:
  700. myFunctions.runChessEngine(21);
  701. break;
  702. case 67:
  703. myFunctions.runChessEngine(22);
  704. break;
  705. case 86:
  706. myFunctions.runChessEngine(23);
  707. break;
  708. case 66:
  709. myFunctions.runChessEngine(24);
  710. break;
  711. case 78:
  712. myFunctions.runChessEngine(25);
  713. break;
  714. case 77:
  715. myFunctions.runChessEngine(26);
  716. break;
  717. case 187:
  718. myFunctions.runChessEngine(100);
  719. break;
  720. }
  721. };
  722.  
  723. myFunctions.spinner = function() {
  724. if(isThinking == true){
  725. $('#thinking-indicator').addClass('active');
  726. }
  727. if(isThinking == false) {
  728. $('#thinking-indicator').removeClass('active');
  729. }
  730. }
  731.  
  732. let dynamicStyles = null;
  733.  
  734. function addAnimation(body) {
  735. if (!dynamicStyles) {
  736. dynamicStyles = document.createElement('style');
  737. dynamicStyles.type = 'text/css';
  738. document.head.appendChild(dynamicStyles);
  739. }
  740.  
  741. dynamicStyles.sheet.insertRule(body, dynamicStyles.length);
  742. }
  743.  
  744. var loaded = false;
  745. myFunctions.loadEx = function(){
  746. try{
  747. var tmpStyle;
  748. var tmpDiv;
  749. board = $('chess-board')[0] || $('wc-chess-board')[0];
  750. myVars.board = board;
  751.  
  752. var div = document.createElement('div')
  753. var content = `
  754. <div class="chess-bot-container">
  755. <div class="bot-header">
  756. <div class="bot-logo">
  757. <svg viewBox="0 0 24 24" width="24" height="24">
  758. <path fill="currentColor" d="M19,22H5V20H19V22M17,10C15.58,10 14.26,10.77 13.55,12H13V7H16V5H13V2H11V5H8V7H11V12H10.45C9.74,10.77 8.42,10 7,10A5,5 0 0,0 2,15A5,5 0 0,0 7,20H17A5,5 0 0,0 22,15A5,5 0 0,0 17,10M7,18A3,3 0 0,1 4,15A3,3 0 0,1 7,12A3,3 0 0,1 10,15A3,3 0 0,1 7,18M17,18A3,3 0 0,1 14,15A3,3 0 0,1 17,12A3,3 0 0,1 20,15A3,3 0 0,1 17,18Z" />
  759. </svg>
  760. </div>
  761. <h3 class="bot-title">Panel Pro By @akashdeep</h3>
  762. <div id="thinking-indicator" class="thinking-indicator">
  763. <span class="dot dot1"></span>
  764. <span class="dot dot2"></span>
  765. <span class="dot dot3"></span>
  766. </div>
  767. </div>
  768.  
  769. <div class="bot-tabs">
  770. <button class="tab-button active" data-tab="main-settings">Main</button>
  771. <button class="tab-button" data-tab="style-settings">Play Style</button>
  772. <button class="tab-button" data-tab="advanced-settings">Advanced</button>
  773. </div>
  774.  
  775. <div class="bot-tabs-content">
  776. <div class="tab-content active" id="main-settings">
  777. <div class="bot-info">
  778. <div class="depth-card">
  779. <p id="depthText" class="depth-display">Current Depth: <strong>11</strong></p>
  780. <p class="key-hint">Press a key (Q-Z) to change depth</p>
  781.  
  782. <div class="depth-control">
  783. <label for="depthSlider">Depth/ELO:</label>
  784. <div class="slider-controls">
  785. <button class="depth-button" id="decreaseDepth">-</button>
  786. <input type="range" id="depthSlider" min="1" max="26" value="11" class="depth-slider">
  787. <button class="depth-button" id="increaseDepth">+</button>
  788. </div>
  789. <span id="depthValue">11</span>
  790. </div>
  791. </div>
  792. </div>
  793.  
  794. <div class="bot-controls">
  795. <div class="control-group">
  796. <div class="control-item toggle-container">
  797. <input type="checkbox" id="autoRun" name="autoRun" class="toggle-input" value="false">
  798. <label for="autoRun" class="toggle-label">
  799. <span class="toggle-button"></span>
  800. <span class="toggle-text">Auto Run</span>
  801. </label>
  802. </div>
  803.  
  804. <div class="control-item toggle-container">
  805. <input type="checkbox" id="autoMove" name="autoMove" class="toggle-input" value="false">
  806. <label for="autoMove" class="toggle-label">
  807. <span class="toggle-button"></span>
  808. <span class="toggle-text">Auto Move</span>
  809. </label>
  810. </div>
  811. </div>
  812.  
  813. <div class="control-group">
  814. <div class="control-item slider-container">
  815. <label for="timeDelayMin">Min Delay (sec)</label>
  816. <input type="number" id="timeDelayMin" name="timeDelayMin" min="0.1" value="0.1" step="0.1" class="number-input">
  817. </div>
  818.  
  819. <div class="control-item slider-container">
  820. <label for="timeDelayMax">Max Delay (sec)</label>
  821. <input type="number" id="timeDelayMax" name="timeDelayMax" min="0.1" value="1" step="0.1" class="number-input">
  822. </div>
  823. </div>
  824. </div>
  825. </div>
  826.  
  827. <div class="tab-content" id="style-settings">
  828. <div class="playStyle-controls">
  829. <h4 class="settings-section-title">Playing Style Settings</h4>
  830.  
  831. <div class="style-slider-container">
  832. <label for="aggressiveSlider">Aggressive Play:</label>
  833. <input type="range" id="aggressiveSlider" min="1" max="10" value="5" class="style-slider">
  834. <span id="aggressiveValue">5</span>
  835. </div>
  836.  
  837. <div class="style-slider-container">
  838. <label for="defensiveSlider">Defensive Play:</label>
  839. <input type="range" id="defensiveSlider" min="1" max="10" value="5" class="style-slider">
  840. <span id="defensiveValue">5</span>
  841. </div>
  842.  
  843. <div class="style-slider-container">
  844. <label for="tacticalSlider">Tactical Play:</label>
  845. <input type="range" id="tacticalSlider" min="1" max="10" value="5" class="style-slider">
  846. <span id="tacticalValue">5</span>
  847. </div>
  848.  
  849. <div class="style-slider-container">
  850. <label for="positionalSlider">Positional Play:</label>
  851. <input type="range" id="positionalSlider" min="1" max="10" value="5" class="style-slider">
  852. <span id="positionalValue">5</span>
  853. </div>
  854.  
  855. <div class="style-slider-container">
  856. <label for="blunderRateSlider">Blunder Rate:</label>
  857. <input type="range" id="blunderRateSlider" min="0" max="10" value="2" class="style-slider">
  858. <span id="blunderRateValue">2</span>
  859. </div>
  860. </div>
  861. </div>
  862.  
  863. <div class="tab-content" id="advanced-settings">
  864. <div class="advanced-controls">
  865. <h4 class="settings-section-title">Advanced Settings</h4>
  866.  
  867. <div class="control-item toggle-container">
  868. <input type="checkbox" id="adaptToRating" name="adaptToRating" class="toggle-input" value="true" checked>
  869. <label for="adaptToRating" class="toggle-label">
  870. <span class="toggle-button"></span>
  871. <span class="toggle-text">Adapt to opponent rating</span>
  872. </label>
  873. </div>
  874.  
  875. <div class="control-item toggle-container">
  876. <input type="checkbox" id="useOpeningBook" name="useOpeningBook" class="toggle-input" value="true" checked>
  877. <label for="useOpeningBook" class="toggle-label">
  878. <span class="toggle-button"></span>
  879. <span class="toggle-text">Use personalized openings</span>
  880. </label>
  881. </div>
  882.  
  883. <div class="highlight-color-picker">
  884. <label for="highlightColor">Move highlight color:</label>
  885. <input type="color" id="highlightColor" value="#eb6150" class="color-input">
  886. </div>
  887.  
  888. <div class="opening-selection">
  889. <label for="preferredOpeningSelect">Preferred Opening:</label>
  890. <select id="preferredOpeningSelect" class="select-input">
  891. <option value="random">Random</option>
  892. <option value="e4">e4 (King's Pawn)</option>
  893. <option value="d4">d4 (Queen's Pawn)</option>
  894. <option value="c4">c4 (English)</option>
  895. <option value="Nf3">Nf3 (Réti)</option>
  896. </select>
  897. </div>
  898. </div>
  899. </div>
  900. </div>
  901.  
  902. <div class="bot-actions">
  903. <button type="button" id="relEngBut" class="action-button primary-button" onclick="document.myFunctions.reloadChessEngine()">
  904. <svg viewBox="0 0 24 24" width="16" height="16">
  905. <path fill="currentColor" d="M17.65,6.35C16.2,4.9 14.21,4 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20C15.73,20 18.84,17.45 19.73,14H17.65C16.83,16.33 14.61,18 12,18A6,6 0 0,1 6,12A6,6 0 0,1 12,6C13.66,6 15.14,6.69 16.22,7.78L13,11H20V4L17.65,6.35Z" />
  906. </svg>
  907. Reload Engine
  908. </button>
  909.  
  910. <button type="button" id="isBut" class="action-button secondary-button" onclick="window.confirm('Can I take you to the issues page?') ? document.location = 'https://github.com/Auzgame/userscripts/issues' : console.log('canceled')">
  911. <svg viewBox="0 0 24 24" width="16" height="16">
  912. <path fill="currentColor" d="M13,13H11V7H13M13,17H11V15H13M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z" />
  913. </svg>
  914. Report Issue
  915. </button>
  916. </div>
  917. </div>`;
  918. div.innerHTML = content;
  919. div.setAttribute('id','settingsContainer');
  920.  
  921. board.parentElement.parentElement.appendChild(div);
  922.  
  923. //Add CSS styles
  924. var botStyles = document.createElement('style');
  925. botStyles.innerHTML = `
  926. @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap');
  927.  
  928. #settingsContainer {
  929. background-color: #1e1e2e;
  930. color: #cdd6f4;
  931. border-radius: 12px;
  932. padding: 20px;
  933. margin-top: 15px;
  934. box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  935. font-family: 'Roboto', sans-serif;
  936. max-width: 400px;
  937. margin-left: auto;
  938. margin-right: auto;
  939. border: 1px solid #313244;
  940. }
  941.  
  942. .chess-bot-container {
  943. display: flex;
  944. flex-direction: column;
  945. gap: 16px;
  946. }
  947.  
  948. .bot-header {
  949. display: flex;
  950. align-items: center;
  951. justify-content: center;
  952. gap: 10px;
  953. margin-bottom: 5px;
  954. position: relative;
  955. }
  956.  
  957. .bot-logo {
  958. display: flex;
  959. align-items: center;
  960. justify-content: center;
  961. color: #89b4fa;
  962. }
  963.  
  964. .bot-title {
  965. margin: 0;
  966. color: #89b4fa;
  967. font-size: 20px;
  968. font-weight: 500;
  969. letter-spacing: 0.5px;
  970. }
  971.  
  972. .thinking-indicator {
  973. position: absolute;
  974. right: 0;
  975. display: none;
  976. align-items: center;
  977. }
  978.  
  979. .thinking-indicator.active {
  980. display: flex;
  981. }
  982.  
  983. .dot {
  984. width: 8px;
  985. height: 8px;
  986. margin: 0 2px;
  987. background-color: #89b4fa;
  988. border-radius: 50%;
  989. opacity: 0.6;
  990. }
  991.  
  992. .dot1 {
  993. animation: pulse 1.5s infinite;
  994. }
  995.  
  996. .dot2 {
  997. animation: pulse 1.5s infinite 0.3s;
  998. }
  999.  
  1000. .dot3 {
  1001. animation: pulse 1.5s infinite 0.6s;
  1002. }
  1003.  
  1004. @keyframes pulse {
  1005. 0%, 100% {
  1006. transform: scale(1);
  1007. opacity: 0.6;
  1008. }
  1009. 50% {
  1010. transform: scale(1.3);
  1011. opacity: 1;
  1012. }
  1013. }
  1014.  
  1015. .bot-tabs {
  1016. display: flex;
  1017. gap: 2px;
  1018. margin-bottom: -15px;
  1019. }
  1020.  
  1021. .tab-button {
  1022. background-color: #313244;
  1023. color: #a6adc8;
  1024. border: none;
  1025. border-radius: 8px 8px 0 0;
  1026. padding: 8px 16px;
  1027. cursor: pointer;
  1028. font-size: 14px;
  1029. font-weight: 500;
  1030. transition: all 0.2s;
  1031. flex: 1;
  1032. text-align: center;
  1033. }
  1034.  
  1035. .tab-button:hover {
  1036. background-color: #45475a;
  1037. color: #cdd6f4;
  1038. }
  1039.  
  1040. .tab-button.active {
  1041. background-color: #45475a;
  1042. color: #cdd6f4;
  1043. }
  1044.  
  1045. .bot-tabs-content {
  1046. background-color: #45475a;
  1047. border-radius: 0 8px 8px 8px;
  1048. padding: 16px;
  1049. }
  1050.  
  1051. .tab-content {
  1052. display: none;
  1053. }
  1054.  
  1055. .tab-content.active {
  1056. display: block;
  1057. }
  1058.  
  1059. .settings-section-title {
  1060. margin-top: 0;
  1061. margin-bottom: 12px;
  1062. color: #89b4fa;
  1063. font-size: 16px;
  1064. font-weight: 500;
  1065. text-align: center;
  1066. }
  1067.  
  1068. .bot-info {
  1069. display: flex;
  1070. justify-content: center;
  1071. margin-bottom: 5px;
  1072. }
  1073.  
  1074. .depth-card {
  1075. background-color: #313244;
  1076. border-radius: 8px;
  1077. padding: 12px 16px;
  1078. text-align: center;
  1079. width: 100%;
  1080. border: 1px solid #45475a;
  1081. }
  1082.  
  1083. .depth-display {
  1084. font-size: 16px;
  1085. margin: 0 0 5px 0;
  1086. font-weight: 400;
  1087. }
  1088.  
  1089. .depth-display strong {
  1090. color: #89b4fa;
  1091. font-weight: 600;
  1092. }
  1093.  
  1094. .key-hint {
  1095. font-size: 12px;
  1096. color: #a6adc8;
  1097. margin: 0;
  1098. font-weight: 300;
  1099. }
  1100.  
  1101. .bot-controls {
  1102. display: flex;
  1103. flex-direction: column;
  1104. gap: 16px;
  1105. }
  1106.  
  1107. .control-group {
  1108. display: grid;
  1109. grid-template-columns: 1fr 1fr;
  1110. gap: 12px;
  1111. }
  1112.  
  1113. .control-item {
  1114. display: flex;
  1115. flex-direction: column;
  1116. gap: 6px;
  1117. }
  1118.  
  1119. .toggle-container {
  1120. position: relative;
  1121. }
  1122.  
  1123. .toggle-input {
  1124. opacity: 0;
  1125. width: 0;
  1126. height: 0;
  1127. position: absolute;
  1128. }
  1129.  
  1130. .toggle-label {
  1131. display: flex;
  1132. align-items: center;
  1133. gap: 10px;
  1134. cursor: pointer;
  1135. }
  1136.  
  1137. .toggle-button {
  1138. position: relative;
  1139. display: inline-block;
  1140. width: 40px;
  1141. height: 20px;
  1142. background-color: #45475a;
  1143. border-radius: 20px;
  1144. transition: all 0.3s;
  1145. }
  1146.  
  1147. .toggle-button:before {
  1148. content: '';
  1149. position: absolute;
  1150. width: 16px;
  1151. height: 16px;
  1152. border-radius: 50%;
  1153. background-color: #cdd6f4;
  1154. top: 2px;
  1155. left: 2px;
  1156. transition: all 0.3s;
  1157. }
  1158.  
  1159. .toggle-input:checked + .toggle-label .toggle-button {
  1160. background-color: #89b4fa;
  1161. }
  1162.  
  1163. .toggle-input:checked + .toggle-label .toggle-button:before {
  1164. transform: translateX(20px);
  1165. }
  1166.  
  1167. .toggle-text {
  1168. font-size: 14px;
  1169. }
  1170.  
  1171. .slider-container {
  1172. display: flex;
  1173. flex-direction: column;
  1174. gap: 6px;
  1175. }
  1176.  
  1177. .slider-container label {
  1178. font-size: 13px;
  1179. color: #a6adc8;
  1180. }
  1181.  
  1182. .number-input {
  1183. width: 100%;
  1184. background: #313244;
  1185. border: 1px solid #45475a;
  1186. border-radius: 6px;
  1187. color: #cdd6f4;
  1188. padding: 8px 10px;
  1189. font-size: 14px;
  1190. transition: border-color 0.3s;
  1191. }
  1192.  
  1193. .number-input:focus {
  1194. outline: none;
  1195. border-color: #89b4fa;
  1196. }
  1197.  
  1198. .bot-actions {
  1199. display: grid;
  1200. grid-template-columns: 1fr 1fr;
  1201. gap: 12px;
  1202. margin-top: 5px;
  1203. }
  1204.  
  1205. .action-button {
  1206. display: flex;
  1207. align-items: center;
  1208. justify-content: center;
  1209. gap: 8px;
  1210. border: none;
  1211. border-radius: 8px;
  1212. padding: 10px 16px;
  1213. font-size: 14px;
  1214. font-weight: 500;
  1215. cursor: pointer;
  1216. transition: all 0.2s;
  1217. }
  1218.  
  1219. .primary-button {
  1220. background-color: #89b4fa;
  1221. color: #1e1e2e;
  1222. }
  1223.  
  1224. .primary-button:hover {
  1225. background-color: #b4befe;
  1226. transform: translateY(-2px);
  1227. box-shadow: 0 4px 8px rgba(137, 180, 250, 0.3);
  1228. }
  1229.  
  1230. .secondary-button {
  1231. background-color: #45475a;
  1232. color: #cdd6f4;
  1233. }
  1234.  
  1235. .secondary-button:hover {
  1236. background-color: #585b70;
  1237. transform: translateY(-2px);
  1238. box-shadow: 0 4px 8px rgba(69, 71, 90, 0.3);
  1239. }
  1240.  
  1241. .action-button:active {
  1242. transform: translateY(0);
  1243. }
  1244.  
  1245. .depth-control {
  1246. margin-top: 12px;
  1247. display: flex;
  1248. flex-direction: column;
  1249. gap: 8px;
  1250. }
  1251.  
  1252. .depth-control label {
  1253. font-size: 13px;
  1254. color: #a6adc8;
  1255. }
  1256.  
  1257. .slider-controls {
  1258. display: flex;
  1259. align-items: center;
  1260. gap: 8px;
  1261. }
  1262.  
  1263. .depth-slider {
  1264. flex: 1;
  1265. height: 6px;
  1266. -webkit-appearance: none;
  1267. appearance: none;
  1268. background: #45475a;
  1269. border-radius: 3px;
  1270. outline: none;
  1271. }
  1272.  
  1273. .depth-slider::-webkit-slider-thumb {
  1274. -webkit-appearance: none;
  1275. appearance: none;
  1276. width: 16px;
  1277. height: 16px;
  1278. border-radius: 50%;
  1279. background: #89b4fa;
  1280. cursor: pointer;
  1281. }
  1282.  
  1283. .depth-slider::-moz-range-thumb {
  1284. width: 16px;
  1285. height: 16px;
  1286. border-radius: 50%;
  1287. background: #89b4fa;
  1288. cursor: pointer;
  1289. }
  1290.  
  1291. .depth-button {
  1292. width: 24px;
  1293. height: 24px;
  1294. border-radius: 50%;
  1295. background: #45475a;
  1296. color: #cdd6f4;
  1297. border: none;
  1298. display: flex;
  1299. align-items: center;
  1300. justify-content: center;
  1301. cursor: pointer;
  1302. font-size: 16px;
  1303. font-weight: bold;
  1304. transition: background-color 0.2s;
  1305. }
  1306.  
  1307. .depth-button:hover {
  1308. background: #585b70;
  1309. }
  1310.  
  1311. #depthValue {
  1312. font-size: 14px;
  1313. font-weight: 500;
  1314. color: #89b4fa;
  1315. text-align: center;
  1316. }
  1317. `;
  1318. document.head.appendChild(botStyles);
  1319.  
  1320. //spinnerContainer
  1321. var spinCont = document.createElement('div');
  1322. spinCont.setAttribute('style','display:none;');
  1323. spinCont.setAttribute('id','overlay');
  1324. div.prepend(spinCont);
  1325.  
  1326. //spinner
  1327. var spinr = document.createElement('div')
  1328. spinr.setAttribute('style',`
  1329. margin: 0 auto;
  1330. height: 40px;
  1331. width: 40px;
  1332. animation: rotate 0.8s infinite linear;
  1333. border: 4px solid #89b4fa;
  1334. border-right-color: transparent;
  1335. border-radius: 50%;
  1336. box-shadow: 0 0 10px rgba(137, 180, 250, 0.4);
  1337. `);
  1338. spinCont.appendChild(spinr);
  1339. addAnimation(`@keyframes rotate {
  1340. 0% {
  1341. transform: rotate(0deg);
  1342. }
  1343. 100% {
  1344. transform: rotate(360deg);
  1345. }
  1346. }`);
  1347. $('#depthSlider').on('input', function() {
  1348. const depth = parseInt($(this).val());
  1349. $('#depthValue').text(depth);
  1350. lastValue = depth;
  1351. $('#depthText')[0].innerHTML = "Current Depth: <strong>" + depth + "</strong>";
  1352. });
  1353.  
  1354. $('#decreaseDepth').on('click', function() {
  1355. const currentDepth = parseInt($('#depthSlider').val());
  1356. if (currentDepth > 1) {
  1357. const newDepth = currentDepth - 1;
  1358. $('#depthSlider').val(newDepth).trigger('input');
  1359. }
  1360. });
  1361.  
  1362. $('#increaseDepth').on('click', function() {
  1363. const currentDepth = parseInt($('#depthSlider').val());
  1364. if (currentDepth < 26) {
  1365. const newDepth = currentDepth + 1;
  1366. $('#depthSlider').val(newDepth).trigger('input');
  1367. }
  1368. });
  1369.  
  1370. // Fix tab switching and initialize all controls
  1371. $(document).on('click', '.tab-button', function() {
  1372. $('.tab-button').removeClass('active');
  1373. $(this).addClass('active');
  1374.  
  1375. const tabId = $(this).data('tab');
  1376. $('.tab-content').removeClass('active');
  1377. $(`#${tabId}`).addClass('active');
  1378. });
  1379.  
  1380. // Initialize play style sliders with values from myVars
  1381. if (myVars.playStyle) {
  1382. $('#aggressiveSlider').val(Math.round(((myVars.playStyle.aggressive - 0.3) / 0.5) * 10));
  1383. $('#aggressiveValue').text($('#aggressiveSlider').val());
  1384.  
  1385. $('#defensiveSlider').val(Math.round(((myVars.playStyle.defensive - 0.3) / 0.5) * 10));
  1386. $('#defensiveValue').text($('#defensiveSlider').val());
  1387.  
  1388. $('#tacticalSlider').val(Math.round(((myVars.playStyle.tactical - 0.2) / 0.6) * 10));
  1389. $('#tacticalValue').text($('#tacticalSlider').val());
  1390.  
  1391. $('#positionalSlider').val(Math.round(((myVars.playStyle.positional - 0.2) / 0.6) * 10));
  1392. $('#positionalValue').text($('#positionalSlider').val());
  1393. }
  1394.  
  1395. // Set the blunder rate slider
  1396. const blunderRate = myVars.blunderRate !== undefined ? Math.round(myVars.blunderRate * 10) : 2;
  1397. $('#blunderRateSlider').val(blunderRate);
  1398. $('#blunderRateValue').text(blunderRate);
  1399.  
  1400. // Setup the style sliders
  1401. $('.style-slider').on('input', function() {
  1402. const value = $(this).val();
  1403. $(`#${this.id}Value`).text(value);
  1404.  
  1405. // Update the myVars.playStyle object
  1406. const styleType = this.id.replace('Slider', '');
  1407. if (styleType === 'blunderRate') {
  1408. myVars.blunderRate = parseFloat(value) / 10;
  1409. } else if (myVars.playStyle && styleType in myVars.playStyle) {
  1410. if (styleType === 'aggressive' || styleType === 'defensive') {
  1411. myVars.playStyle[styleType] = 0.3 + (parseFloat(value) / 10) * 0.5;
  1412. } else {
  1413. myVars.playStyle[styleType] = 0.2 + (parseFloat(value) / 10) * 0.6;
  1414. }
  1415. }
  1416. });
  1417.  
  1418. // Initialize advanced settings
  1419. if (myVars.adaptToRating !== undefined) {
  1420. $('#adaptToRating').prop('checked', myVars.adaptToRating);
  1421. }
  1422.  
  1423. if (myVars.useOpeningBook !== undefined) {
  1424. $('#useOpeningBook').prop('checked', myVars.useOpeningBook);
  1425. }
  1426.  
  1427. if (myVars.highlightColor) {
  1428. $('#highlightColor').val(myVars.highlightColor);
  1429. }
  1430.  
  1431. // Set up preferred opening selection
  1432. if (myVars.preferredOpenings && myVars.preferredOpenings.length === 1) {
  1433. $('#preferredOpeningSelect').val(myVars.preferredOpenings[0]);
  1434. } else {
  1435. $('#preferredOpeningSelect').val('random');
  1436. }
  1437.  
  1438. // Set up advanced settings event handlers
  1439. $('#adaptToRating').on('change', function() {
  1440. myVars.adaptToRating = $(this).prop('checked');
  1441. });
  1442.  
  1443. $('#useOpeningBook').on('change', function() {
  1444. myVars.useOpeningBook = $(this).prop('checked');
  1445. });
  1446.  
  1447. $('#highlightColor').on('input', function() {
  1448. myVars.highlightColor = $(this).val();
  1449. });
  1450.  
  1451. $('#preferredOpeningSelect').on('change', function() {
  1452. const selectedOpening = $(this).val();
  1453. if (selectedOpening === 'random') {
  1454. myVars.preferredOpenings = ["e4", "d4", "c4", "Nf3"].sort(() => Math.random() - 0.5);
  1455. } else {
  1456. myVars.preferredOpenings = [selectedOpening];
  1457. }
  1458. });
  1459.  
  1460. // Setup hotkey options and additional config
  1461. const extraSettings = `
  1462. <div class="advanced-section">
  1463. <div class="control-item toggle-container">
  1464. <input type="checkbox" id="enableHotkeys" name="enableHotkeys" class="toggle-input" checked>
  1465. <label for="enableHotkeys" class="toggle-label">
  1466. <span class="toggle-button"></span>
  1467. <span class="toggle-text">Enable keyboard shortcuts</span>
  1468. </label>
  1469. </div>
  1470.  
  1471. <div class="control-item toggle-container">
  1472. <input type="checkbox" id="randomizeTiming" name="randomizeTiming" class="toggle-input" checked>
  1473. <label for="randomizeTiming" class="toggle-label">
  1474. <span class="toggle-button"></span>
  1475. <span class="toggle-text">Randomize thinking time</span>
  1476. </label>
  1477. </div>
  1478.  
  1479. <div class="style-slider-container">
  1480. <label for="mouseMovementSlider">Mouse Movement Realism:</label>
  1481. <input type="range" id="mouseMovementSlider" min="1" max="10" value="7" class="style-slider">
  1482. <span id="mouseMovementSliderValue">7</span>
  1483. </div>
  1484.  
  1485. <div class="profile-selection">
  1486. <label for="playingProfileSelect">Playing Profile:</label>
  1487. <select id="playingProfileSelect" class="select-input">
  1488. <option value="custom">Custom Settings</option>
  1489. <option value="beginner">Beginner (≈800)</option>
  1490. <option value="intermediate">Intermediate (≈1200)</option>
  1491. <option value="advanced">Advanced (≈1600)</option>
  1492. <option value="expert">Expert (≈2000)</option>
  1493. <option value="master">Master (≈2400+)</option>
  1494. </select>
  1495. </div>
  1496. </div>
  1497. `;
  1498.  
  1499. $('#advanced-settings .advanced-controls').append(extraSettings);
  1500.  
  1501. // Initialize additional settings
  1502. myVars.enableHotkeys = true;
  1503. myVars.randomizeTiming = true;
  1504. myVars.mouseMovementRealism = 0.7;
  1505.  
  1506. // Setup additional event handlers
  1507. $('#enableHotkeys').on('change', function() {
  1508. myVars.enableHotkeys = $(this).prop('checked');
  1509. });
  1510.  
  1511. $('#randomizeTiming').on('change', function() {
  1512. myVars.randomizeTiming = $(this).prop('checked');
  1513. });
  1514.  
  1515. $('#mouseMovementSlider').on('input', function() {
  1516. const value = $(this).val();
  1517. $('#mouseMovementSliderValue').text(value);
  1518. myVars.mouseMovementRealism = parseFloat(value) / 10;
  1519. });
  1520.  
  1521. $('#playingProfileSelect').on('change', function() {
  1522. const profile = $(this).val();
  1523.  
  1524. if (profile !== 'custom') {
  1525. // Preset profiles with appropriate settings
  1526. switch(profile) {
  1527. case 'beginner':
  1528. $('#depthSlider').val(3).trigger('input');
  1529. $('#blunderRateSlider').val(7).trigger('input');
  1530. $('#aggressiveSlider').val(Math.floor(3 + Math.random() * 5)).trigger('input');
  1531. $('#tacticalSlider').val(3).trigger('input');
  1532. break;
  1533. case 'intermediate':
  1534. $('#depthSlider').val(6).trigger('input');
  1535. $('#blunderRateSlider').val(5).trigger('input');
  1536. $('#tacticalSlider').val(5).trigger('input');
  1537. break;
  1538. case 'advanced':
  1539. $('#depthSlider').val(9).trigger('input');
  1540. $('#blunderRateSlider').val(3).trigger('input');
  1541. $('#tacticalSlider').val(7).trigger('input');
  1542. break;
  1543. case 'expert':
  1544. $('#depthSlider').val(12).trigger('input');
  1545. $('#blunderRateSlider').val(2).trigger('input');
  1546. $('#tacticalSlider').val(8).trigger('input');
  1547. $('#positionalSlider').val(8).trigger('input');
  1548. break;
  1549. case 'master':
  1550. $('#depthSlider').val(15).trigger('input');
  1551. $('#blunderRateSlider').val(1).trigger('input');
  1552. $('#tacticalSlider').val(9).trigger('input');
  1553. $('#positionalSlider').val(9).trigger('input');
  1554. break;
  1555. }
  1556. }
  1557. });
  1558.  
  1559. // Add CSS for new elements
  1560. const extraStyles = document.createElement('style');
  1561. extraStyles.innerHTML = `
  1562. .advanced-section {
  1563. margin-top: 15px;
  1564. padding-top: 15px;
  1565. border-top: 1px solid #313244;
  1566. }
  1567.  
  1568. .profile-selection {
  1569. margin-top: 15px;
  1570. }
  1571.  
  1572. .playStyle-controls, .advanced-controls {
  1573. display: flex;
  1574. flex-direction: column;
  1575. gap: 12px;
  1576. }
  1577.  
  1578. .style-slider-container {
  1579. display: flex;
  1580. align-items: center;
  1581. gap: 10px;
  1582. }
  1583.  
  1584. .style-slider-container label {
  1585. font-size: 13px;
  1586. color: #cdd6f4;
  1587. width: 120px;
  1588. }
  1589.  
  1590. .style-slider {
  1591. flex: 1;
  1592. height: 6px;
  1593. -webkit-appearance: none;
  1594. appearance: none;
  1595. background: #313244;
  1596. border-radius: 3px;
  1597. outline: none;
  1598. }
  1599.  
  1600. .style-slider::-webkit-slider-thumb {
  1601. -webkit-appearance: none;
  1602. appearance: none;
  1603. width: 14px;
  1604. height: 14px;
  1605. border-radius: 50%;
  1606. background: #89b4fa;
  1607. cursor: pointer;
  1608. }
  1609.  
  1610. .style-slider-container span {
  1611. font-size: 14px;
  1612. font-weight: 500;
  1613. color: #89b4fa;
  1614. width: 20px;
  1615. text-align: center;
  1616. }
  1617.  
  1618. .highlight-color-picker {
  1619. display: flex;
  1620. align-items: center;
  1621. gap: 10px;
  1622. margin-top: 10px;
  1623. }
  1624.  
  1625. .highlight-color-picker label {
  1626. font-size: 13px;
  1627. color: #cdd6f4;
  1628. }
  1629.  
  1630. .color-input {
  1631. -webkit-appearance: none;
  1632. width: 30px;
  1633. height: 30px;
  1634. border: none;
  1635. border-radius: 50%;
  1636. background: none;
  1637. cursor: pointer;
  1638. }
  1639.  
  1640. .color-input::-webkit-color-swatch {
  1641. border: none;
  1642. border-radius: 50%;
  1643. box-shadow: 0 0 0 2px #45475a;
  1644. }
  1645.  
  1646. .opening-selection {
  1647. display: flex;
  1648. align-items: center;
  1649. gap: 10px;
  1650. margin-top: 10px;
  1651. }
  1652.  
  1653. .opening-selection label {
  1654. font-size: 13px;
  1655. color: #cdd6f4;
  1656. }
  1657.  
  1658. .select-input {
  1659. flex: 1;
  1660. background: #313244;
  1661. border: 1px solid #45475a;
  1662. border-radius: 6px;
  1663. color: #cdd6f4;
  1664. padding: 8px 10px;
  1665. font-size: 14px;
  1666. transition: border-color 0.3s;
  1667. }
  1668.  
  1669. .select-input:focus {
  1670. outline: none;
  1671. border-color: #89b4fa;
  1672. }
  1673. `;
  1674. document.head.appendChild(extraStyles);
  1675.  
  1676. // Load saved settings before applying them to the UI
  1677. myFunctions.loadSettings();
  1678.  
  1679. // Apply loaded settings to UI controls
  1680. $('#autoRun').prop('checked', myVars.autoRun);
  1681. $('#autoMove').prop('checked', myVars.autoMove);
  1682.  
  1683. $('#depthSlider').val(lastValue);
  1684. $('#depthValue').text(lastValue);
  1685. $('#depthText').html("Current Depth: <strong>" + lastValue + "</strong>");
  1686.  
  1687. if (myVars.highlightColor) {
  1688. $('#highlightColor').val(myVars.highlightColor);
  1689. }
  1690.  
  1691. // Update the play style sliders with saved values
  1692. if (myVars.playStyle) {
  1693. $('#aggressiveSlider').val(Math.round(((myVars.playStyle.aggressive - 0.3) / 0.5) * 10));
  1694. $('#aggressiveValue').text($('#aggressiveSlider').val());
  1695.  
  1696. $('#defensiveSlider').val(Math.round(((myVars.playStyle.defensive - 0.3) / 0.5) * 10));
  1697. $('#defensiveValue').text($('#defensiveSlider').val());
  1698.  
  1699. $('#tacticalSlider').val(Math.round(((myVars.playStyle.tactical - 0.2) / 0.6) * 10));
  1700. $('#tacticalValue').text($('#tacticalSlider').val());
  1701.  
  1702. $('#positionalSlider').val(Math.round(((myVars.playStyle.positional - 0.2) / 0.6) * 10));
  1703. $('#positionalValue').text($('#positionalSlider').val());
  1704. }
  1705.  
  1706. // Update blunder rate slider with saved value
  1707. if (myVars.blunderRate !== undefined) {
  1708. $('#blunderRateSlider').val(Math.round(myVars.blunderRate * 10));
  1709. $('#blunderRateValue').text($('#blunderRateSlider').val());
  1710. }
  1711.  
  1712. // Set advanced settings based on saved values
  1713. $('#adaptToRating').prop('checked', myVars.adaptToRating);
  1714. $('#useOpeningBook').prop('checked', myVars.useOpeningBook);
  1715. $('#enableHotkeys').prop('checked', myVars.enableHotkeys);
  1716. $('#randomizeTiming').prop('checked', myVars.randomizeTiming);
  1717.  
  1718. if (myVars.mouseMovementRealism !== undefined) {
  1719. $('#mouseMovementSlider').val(Math.round(myVars.mouseMovementRealism * 10));
  1720. $('#mouseMovementSliderValue').text($('#mouseMovementSlider').val());
  1721. }
  1722.  
  1723. if (myVars.preferredOpenings && myVars.preferredOpenings.length === 1) {
  1724. $('#preferredOpeningSelect').val(myVars.preferredOpenings[0]);
  1725. }
  1726.  
  1727. // Add event handlers to save settings when they change
  1728. $('#autoRun, #autoMove, #adaptToRating, #useOpeningBook, #enableHotkeys, #randomizeTiming').on('change', function() {
  1729. const id = $(this).attr('id');
  1730. myVars[id] = $(this).prop('checked');
  1731. myFunctions.saveSettings();
  1732. });
  1733.  
  1734. $('#depthSlider').on('input', function() {
  1735. // The existing handler already updates the UI
  1736. myFunctions.saveSettings();
  1737. });
  1738.  
  1739. $('#timeDelayMin, #timeDelayMax').on('change', function() {
  1740. myFunctions.saveSettings();
  1741. });
  1742.  
  1743. $('.style-slider').on('input', function() {
  1744. // The existing handler updates the playStyle object
  1745. myFunctions.saveSettings();
  1746. });
  1747.  
  1748. $('#highlightColor').on('input', function() {
  1749. // Existing handler already updates myVars.highlightColor
  1750. myFunctions.saveSettings();
  1751. });
  1752.  
  1753. $('#preferredOpeningSelect').on('change', function() {
  1754. // Existing handler updates preferredOpenings
  1755. myFunctions.saveSettings();
  1756. });
  1757.  
  1758. $('#playingProfileSelect').on('change', function() {
  1759. // After profile is applied
  1760. setTimeout(myFunctions.saveSettings, 100);
  1761. });
  1762.  
  1763. $('#autoMove').on('change', function() {
  1764. myVars.autoMove = $(this).prop('checked');
  1765. console.log(`Auto move set to: ${myVars.autoMove}`);
  1766. myFunctions.saveSettings();
  1767. });
  1768.  
  1769. loaded = true;
  1770. } catch (error) {console.log(error)}
  1771. }
  1772.  
  1773.  
  1774. function other(delay) {
  1775. // Create more natural timing pattern based on game situation
  1776. const gamePhase = estimateGamePhase();
  1777. const positionComplexity = estimatePositionComplexity();
  1778.  
  1779. // Apply more realistic timing adjustments
  1780. let naturalDelay = delay;
  1781.  
  1782. // Faster moves in openings
  1783. if (gamePhase < 10) {
  1784. naturalDelay *= (0.6 + Math.random() * 0.4);
  1785. }
  1786.  
  1787. // Slower in complex positions
  1788. if (positionComplexity > 0.7) {
  1789. naturalDelay *= (1 + Math.random() * 1.5);
  1790. }
  1791.  
  1792. // Add slight additional randomness
  1793. naturalDelay *= (0.85 + Math.random() * 0.3);
  1794.  
  1795. var endTime = Date.now() + naturalDelay;
  1796. var timer = setInterval(()=>{
  1797. if(Date.now() >= endTime){
  1798. myFunctions.autoRun(getAdjustedDepth());
  1799. canGo = true;
  1800. clearInterval(timer);
  1801. }
  1802. },10);
  1803. }
  1804.  
  1805. function getAdjustedDepth() {
  1806. // Vary search depth by ±5 to mimic human inconsistency
  1807. const variation = Math.floor(Math.random() * 11) - 5; // Random number between -5 and +5
  1808. return Math.max(1, Math.min(22, lastValue + variation)); // Keep within valid range 1-26
  1809. }
  1810.  
  1811. async function getVersion(){
  1812. var GF = new GreasyFork; // set upping api
  1813. var code = await GF.get().script().code(460208); // Get code
  1814. var version = GF.parseScriptCodeMeta(code).filter(e => e.meta === '@version')[0].value; // filtering array and getting value of @version
  1815.  
  1816. if(currentVersion !== version){
  1817. while(true){
  1818. alert('UPDATE THIS SCRIPT IN ORDER TO PROCEED!');
  1819. }
  1820. }
  1821. }
  1822.  
  1823. //Removed due to script being reported. I tried to make it so people can know when bug fixes come out. Clearly people don't like that.
  1824. //getVersion();
  1825.  
  1826. const waitForChessBoard = setInterval(() => {
  1827. if(loaded) {
  1828. board = $('chess-board')[0] || $('wc-chess-board')[0];
  1829. myVars.autoRun = $('#autoRun')[0].checked;
  1830. myVars.autoMove = $('#autoMove')[0].checked;
  1831. let minDel = parseFloat($('#timeDelayMin')[0].value);
  1832. let maxDel = parseFloat($('#timeDelayMax')[0].value);
  1833. myVars.delay = Math.random() * (maxDel - minDel) + minDel;
  1834. myVars.isThinking = isThinking;
  1835. myFunctions.spinner();
  1836. if(board.game.getTurn() == board.game.getPlayingAs()){myTurn = true;} else {myTurn = false;}
  1837. $('#depthText')[0].innerHTML = "Current Depth: <strong>"+lastValue+"</strong>";
  1838. } else {
  1839. myFunctions.loadEx();
  1840. }
  1841.  
  1842.  
  1843. if(!engine.engine){
  1844. myFunctions.loadChessEngine();
  1845. }
  1846. if(myVars.autoRun == true && canGo == true && isThinking == false && myTurn){
  1847. //console.log(`going: ${canGo} ${isThinking} ${myTurn}`);
  1848. canGo = false;
  1849. var currentDelay = myVars.delay != undefined ? myVars.delay * 1000 : 10;
  1850. other(currentDelay);
  1851. }
  1852. }, 100);
  1853.  
  1854. // Add these two functions for saving and loading settings
  1855. myFunctions.saveSettings = function() {
  1856. GM_setValue('autoRun', myVars.autoRun);
  1857. GM_setValue('autoMove', myVars.autoMove);
  1858. GM_setValue('timeDelayMin', $('#timeDelayMin').val());
  1859. GM_setValue('timeDelayMax', $('#timeDelayMax').val());
  1860. GM_setValue('depthValue', lastValue);
  1861. GM_setValue('highlightColor', myVars.highlightColor);
  1862. GM_setValue('playStyle', myVars.playStyle);
  1863. GM_setValue('blunderRate', myVars.blunderRate);
  1864. GM_setValue('adaptToRating', myVars.adaptToRating);
  1865. GM_setValue('useOpeningBook', myVars.useOpeningBook);
  1866. GM_setValue('preferredOpenings', myVars.preferredOpenings);
  1867. GM_setValue('enableHotkeys', myVars.enableHotkeys);
  1868. GM_setValue('randomizeTiming', myVars.randomizeTiming);
  1869. GM_setValue('mouseMovementRealism', myVars.mouseMovementRealism);
  1870. myFunctions.saveGameMemory(result, opponent, mistakes);
  1871. myVars.openingRepertoire = GM_getValue('openingRepertoire', {
  1872. white: {
  1873. main: getRandomOpenings(2),
  1874. experimental: getRandomOpenings(3, true),
  1875. success: {}
  1876. },
  1877. black: {
  1878. responses: {
  1879. e4: getRandomResponses('e4', 2),
  1880. d4: getRandomResponses('d4', 2),
  1881. c4: getRandomResponses('c4', 2),
  1882. other: getRandomResponses('other', 2)
  1883. },
  1884. success: {}
  1885. },
  1886. lastUpdated: Date.now()
  1887. });
  1888. updateOpeningRepertoire();
  1889. };
  1890.  
  1891. myFunctions.loadSettings = function() {
  1892. myVars.autoRun = GM_getValue('autoRun', false);
  1893. myVars.autoMove = GM_getValue('autoMove', false);
  1894. $('#timeDelayMin').val(GM_getValue('timeDelayMin', 0.1));
  1895. $('#timeDelayMax').val(GM_getValue('timeDelayMax', 1));
  1896. lastValue = GM_getValue('depthValue', 11);
  1897. myVars.highlightColor = GM_getValue('highlightColor', 'rgb(235, 97, 80)');
  1898. myVars.playStyle = GM_getValue('playStyle', {
  1899. aggressive: Math.random() * 0.5 + 0.3,
  1900. defensive: Math.random() * 0.5 + 0.3,
  1901. tactical: Math.random() * 0.6 + 0.2,
  1902. positional: Math.random() * 0.6 + 0.2
  1903. });
  1904. myVars.blunderRate = GM_getValue('blunderRate', 0.05);
  1905. myVars.adaptToRating = GM_getValue('adaptToRating', true);
  1906. myVars.useOpeningBook = GM_getValue('useOpeningBook', true);
  1907. myVars.preferredOpenings = GM_getValue('preferredOpenings', ["e4", "d4", "c4", "Nf3"]);
  1908. myVars.enableHotkeys = GM_getValue('enableHotkeys', true);
  1909. myVars.randomizeTiming = GM_getValue('randomizeTiming', true);
  1910. myVars.mouseMovementRealism = GM_getValue('mouseMovementRealism', 0.7);
  1911. };
  1912.  
  1913. myFunctions.saveGameMemory = function(result, opponent, mistakes) {
  1914. // Get existing memory
  1915. let gameMemory = GM_getValue('gameMemory', {
  1916. openingSuccess: {},
  1917. opponentHistory: {},
  1918. mistakePositions: []
  1919. });
  1920.  
  1921. // Store opening success rate
  1922. const opening = board.game.pgn.split('\n\n')[1].split(' ').slice(0, 6).join(' ');
  1923. if (!gameMemory.openingSuccess[opening]) {
  1924. gameMemory.openingSuccess[opening] = { wins: 0, losses: 0, draws: 0 };
  1925. }
  1926. gameMemory.openingSuccess[opening][result]++;
  1927.  
  1928. // Record opponent data
  1929. if (!gameMemory.opponentHistory[opponent]) {
  1930. gameMemory.opponentHistory[opponent] = { games: 0, style: 'unknown' };
  1931. }
  1932. gameMemory.opponentHistory[opponent].games++;
  1933.  
  1934. // Store mistake patterns for future reference
  1935. if (mistakes && mistakes.length) {
  1936. gameMemory.mistakePositions = gameMemory.mistakePositions.concat(mistakes).slice(-50);
  1937. }
  1938.  
  1939. GM_setValue('gameMemory', gameMemory);
  1940. };
  1941.  
  1942. function getThinkingTime(position) {
  1943. const baseTime = parseFloat($('#timeDelayMin').val()) * 1000;
  1944. const maxTime = parseFloat($('#timeDelayMax').val()) * 1000;
  1945.  
  1946. // Analyze position
  1947. const complexity = calculatePositionComplexity(position); // 0-1
  1948. const criticalness = determinePositionCriticalness(position); // 0-1
  1949. const familiarity = assessPositionFamiliarity(position); // 0-1
  1950.  
  1951. // Human-like time scaling
  1952. let thinkingTime = baseTime;
  1953.  
  1954. // Complex positions take more time
  1955. thinkingTime += complexity * (maxTime - baseTime) * 0.7;
  1956.  
  1957. // Critical positions deserve more attention
  1958. thinkingTime += criticalness * (maxTime - baseTime) * 0.5;
  1959.  
  1960. // Unfamiliar positions need more thought
  1961. thinkingTime += (1 - familiarity) * (maxTime - baseTime) * 0.3;
  1962.  
  1963. // Avoid predictable timing with small random variation
  1964. thinkingTime *= 0.85 + Math.random() * 0.3;
  1965.  
  1966. return Math.min(maxTime * 1.2, thinkingTime);
  1967. }
  1968.  
  1969. // Add placeholder functions that can be expanded
  1970. function calculatePositionComplexity(position) {
  1971. // Count material, tension, possible tactics
  1972. const pieceCount = position.split(/[prnbqkPRNBQK]/).length - 1;
  1973. const hasQueen = position.includes('q') || position.includes('Q');
  1974. const pawnStructure = analyzeBasicPawnStructure(position);
  1975.  
  1976. return Math.min(1, (pieceCount / 32) + (hasQueen ? 0.2 : 0) + pawnStructure * 0.3);
  1977. }
  1978.  
  1979. function adjustEngineEvaluation(position, move, evaluation) {
  1980. // Apply player's strategic preferences
  1981. const adjustedEval = { ...evaluation };
  1982.  
  1983. // Adjust based on fingerprint
  1984. if (myVars.playerFingerprint.favoredPieces === 'knights' && move.includes('N')) {
  1985. adjustedEval.score += 0.05 + Math.random() * 0.1;
  1986. }
  1987.  
  1988. if (myVars.playerFingerprint.favoredPieces === 'bishops' && move.includes('B')) {
  1989. adjustedEval.score += 0.05 + Math.random() * 0.1;
  1990. }
  1991.  
  1992. // Kingside/queenside attack preference
  1993. if (myVars.playerFingerprint.attackingStyle === 'kingside' && isKingsideMove(move)) {
  1994. adjustedEval.score += 0.07 + Math.random() * 0.08;
  1995. }
  1996.  
  1997. // Occasionally have a "brilliant" insight (1-2% of moves)
  1998. if (Math.random() < 0.015) {
  1999. // Temporary increase in effective depth for this move evaluation
  2000. console.log("Brilliant insight detected!");
  2001. return getDeepEvaluation(position, move);
  2002. }
  2003.  
  2004. return adjustedEval;
  2005. }
  2006.  
  2007. function isEndgame(position) {
  2008. // Basic endgame detection
  2009. const pieceCount = position.split(/[prnbqkPRNBQK]/).length - 1;
  2010. return pieceCount <= 10;
  2011. }
  2012.  
  2013. function adjustEndgamePlay(fen, moves) {
  2014. if (!isEndgame(fen)) return moves;
  2015.  
  2016. // Common human endgame patterns
  2017. const hasKingActivity = increasesKingActivity(moves[0], fen);
  2018. const promotionPotential = evaluatePromotionPotential(fen);
  2019.  
  2020. // King opposition knowledge (common human knowledge)
  2021. if (hasKingOpposition(fen) && Math.random() < 0.9) {
  2022. // Humans typically understand king opposition
  2023. return prioritizeOppositionMoves(moves);
  2024. }
  2025.  
  2026. // Activate king in endgames (humans know this)
  2027. if (hasKingActivity && Math.random() < 0.75) {
  2028. return moves; // Keep the engine's correct evaluation
  2029. } else if (hasKingActivity) {
  2030. // Sometimes miss the importance of king activity
  2031. return [moves[1] || moves[0], ...moves.slice(1)];
  2032. }
  2033.  
  2034. // Humans tend to focus on pawn promotion
  2035. if (promotionPotential > 0.7) {
  2036. return prioritizePawnAdvancement(moves);
  2037. }
  2038.  
  2039. return moves;
  2040. }
  2041.  
  2042. // Add to myVars at initialization
  2043. myVars.psychologicalState = {
  2044. confidence: 0.7 + Math.random() * 0.3, // 0.7-1.0
  2045. tiltFactor: 0, // 0-1, increases with blunders
  2046. focus: 0.8 + Math.random() * 0.2, // 0.8-1.0, decreases with time
  2047. playTime: 0 // tracks continuous play time
  2048. };
  2049.  
  2050. // Update in a function that runs periodically
  2051. function updatePsychologicalState(gameState) {
  2052. // Increase play time
  2053. myVars.psychologicalState.playTime += 1;
  2054.  
  2055. // Focus decreases with time (mental fatigue)
  2056. if (myVars.psychologicalState.playTime > 10) {
  2057. myVars.psychologicalState.focus = Math.max(0.5,
  2058. myVars.psychologicalState.focus - 0.01);
  2059. }
  2060.  
  2061. // Check for blunders in recent moves
  2062. if (detectBlunder(gameState)) {
  2063. // Increase tilt after mistakes
  2064. myVars.psychologicalState.tiltFactor = Math.min(1,
  2065. myVars.psychologicalState.tiltFactor + 0.25);
  2066. myVars.psychologicalState.confidence = Math.max(0.3,
  2067. myVars.psychologicalState.confidence - 0.15);
  2068. }
  2069.  
  2070. // Good moves restore confidence
  2071. if (detectGoodMove(gameState)) {
  2072. myVars.psychologicalState.confidence = Math.min(1,
  2073. myVars.psychologicalState.confidence + 0.05);
  2074. myVars.psychologicalState.tiltFactor = Math.max(0,
  2075. myVars.psychologicalState.tiltFactor - 0.1);
  2076. }
  2077.  
  2078. // Apply psychological state to blunder rate
  2079. const effectiveBlunderRate = myVars.blunderRate *
  2080. (1 + myVars.psychologicalState.tiltFactor) *
  2081. (2 - myVars.psychologicalState.focus);
  2082.  
  2083. return effectiveBlunderRate;
  2084. }
  2085.  
  2086. function detectTimeControl() {
  2087. try {
  2088. // Look for the clock element and determine time control
  2089. const clockEl = document.querySelector('.clock-component');
  2090. if (clockEl) {
  2091. const timeText = clockEl.textContent;
  2092. const minutes = parseInt(timeText.split(':')[0]);
  2093.  
  2094. if (minutes >= 15) return 'classical';
  2095. if (minutes >= 5) return 'rapid';
  2096. return 'blitz';
  2097. }
  2098. } catch (e) {}
  2099.  
  2100. return 'rapid'; // Default
  2101. }
  2102.  
  2103. function adaptToTimeControl() {
  2104. const timeControl = detectTimeControl();
  2105.  
  2106. switch (timeControl) {
  2107. case 'blitz':
  2108. // More intuitive play, faster moves, higher blunder rate
  2109. myVars.blunderRate *= 1.3;
  2110. $('#timeDelayMin').val(Math.max(0.1, parseFloat($('#timeDelayMin').val()) * 0.7));
  2111. $('#timeDelayMax').val(Math.max(0.3, parseFloat($('#timeDelayMax').val()) * 0.7));
  2112. // Use more recognizable patterns and opening theory
  2113. myVars.patternRecognitionWeight = 0.8;
  2114. break;
  2115.  
  2116. case 'rapid':
  2117. // Balanced approach
  2118. myVars.patternRecognitionWeight = 0.6;
  2119. break;
  2120.  
  2121. case 'classical':
  2122. // More calculation, deeper search, fewer blunders
  2123. myVars.blunderRate *= 0.7;
  2124. $('#timeDelayMin').val(parseFloat($('#timeDelayMin').val()) * 1.2);
  2125. $('#timeDelayMax').val(parseFloat($('#timeDelayMax').val()) * 1.3);
  2126. // More unique moves, less reliance on patterns
  2127. myVars.patternRecognitionWeight = 0.4;
  2128. break;
  2129. }
  2130. }
  2131.  
  2132. function updateOpeningRepertoire() {
  2133. // Only update periodically (simulating a player learning new openings)
  2134. if (Date.now() - myVars.openingRepertoire.lastUpdated < 7 * 24 * 60 * 60 * 1000) {
  2135. return; // Only update weekly
  2136. }
  2137.  
  2138. // Replace worst performing opening with a new one
  2139. const gameMemory = GM_getValue('gameMemory', { openingSuccess: {} });
  2140.  
  2141. // Find worst performing opening
  2142. let worstScore = Infinity;
  2143. let worstOpening = null;
  2144.  
  2145. for (const opening in gameMemory.openingSuccess) {
  2146. const stats = gameMemory.openingSuccess[opening];
  2147. const score = stats.wins - stats.losses;
  2148.  
  2149. if (score < worstScore && stats.wins + stats.losses + stats.draws >= 5) {
  2150. worstScore = score;
  2151. worstOpening = opening;
  2152. }
  2153. }
  2154.  
  2155. // Replace it if we found a bad one
  2156. if (worstOpening && worstScore < 0) {
  2157. console.log("Phasing out unprofitable opening: " + worstOpening);
  2158. // Replace with a new experimental opening
  2159. if (worstOpening.startsWith('1.')) {
  2160. // It's a white opening
  2161. myVars.openingRepertoire.white.experimental =
  2162. myVars.openingRepertoire.white.experimental.filter(o => o !== worstOpening);
  2163. myVars.openingRepertoire.white.experimental.push(getRandomOpenings(1, true)[0]);
  2164. } else {
  2165. // It's a black response
  2166. // Implementation would be similar to white
  2167. }
  2168. }
  2169.  
  2170. myVars.openingRepertoire.lastUpdated = Date.now();
  2171. GM_setValue('openingRepertoire', myVars.openingRepertoire);
  2172. }
  2173.  
  2174. // Then when evaluating positions:
  2175. function adjustForTacticalProfile(moves, position) {
  2176. for (let i = 0; i < moves.length; i++) {
  2177. const tacticalMotif = identifyTacticalMotif(moves[i], position);
  2178.  
  2179. // Boost strengths
  2180. if (myVars.tacticalProfile.strengths.includes(tacticalMotif)) {
  2181. // Higher chance of finding this tactic
  2182. if (i > 0 && Math.random() < 0.8) {
  2183. // Swap with the first move (more likely to be played)
  2184. [moves[0], moves[i]] = [moves[i], moves[0]];
  2185. }
  2186. }
  2187.  
  2188. // Miss weaknesses
  2189. if (myVars.tacticalProfile.weaknesses.includes(tacticalMotif)) {
  2190. // Higher chance of missing this tactic
  2191. if (i === 0 && moves.length > 1 && Math.random() < 0.7) {
  2192. // Swap with the second move (less likely to be played)
  2193. [moves[0], moves[1]] = [moves[1], moves[0]];
  2194. }
  2195. }
  2196. }
  2197.  
  2198. return moves;
  2199. }
  2200. }
  2201.  
  2202. //Touching below may break the script
  2203.  
  2204. var isThinking = false
  2205. var canGo = true;
  2206. var myTurn = false;
  2207. var board;
  2208.  
  2209.  
  2210. window.addEventListener("load", (event) => {
  2211. let currentTime = Date.now();
  2212. main();
  2213. });
  2214.  
  2215. function getAppropriateDepth() {
  2216. // Get player's rating if available
  2217. let playerRating = 1500; // Default
  2218. try {
  2219. const ratingEl = document.querySelector('.user-tagline-rating');
  2220. if (ratingEl) {
  2221. playerRating = parseInt(ratingEl.textContent);
  2222. }
  2223. } catch (e) {}
  2224.  
  2225. // Map ratings to appropriate depths
  2226. if (playerRating < 800) return Math.floor(Math.random() * 3) + 1; // 1-3
  2227. if (playerRating < 1200) return Math.floor(Math.random() * 3) + 3; // 3-5
  2228. if (playerRating < 1600) return Math.floor(Math.random() * 3) + 5; // 5-7
  2229. if (playerRating < 2000) return Math.floor(Math.random() * 3) + 7; // 7-9
  2230. if (playerRating < 2400) return Math.floor(Math.random() * 4) + 9; // 9-12
  2231. return Math.floor(Math.random() * 5) + 12; // 12-16
  2232. }
  2233.  
  2234. function getBezierPoint(t, p0, p1, p2, p3) {
  2235. const cX = 3 * (p1.x - p0.x);
  2236. const bX = 3 * (p2.x - p1.x) - cX;
  2237. const aX = p3.x - p0.x - cX - bX;
  2238. const cY = 3 * (p1.y - p0.y);
  2239. const bY = 3 * (p2.y - p1.y) - cY;
  2240. const aY = p3.y - p0.y - cY - bY;
  2241. const x = (aX * Math.pow(t, 3)) + (bX * Math.pow(t, 2)) + (cX * t) + p0.x;
  2242. const y = (aY * Math.pow(t, 3)) + (bY * Math.pow(t, 2)) + (cY * t) + p0.y;
  2243. return { x, y };
  2244. }
  2245.  
  2246. function executeMouseMovement(points, index, delay, callback) {
  2247. if (index >= points.length) {
  2248. if (callback) callback();
  2249. return;
  2250. }
  2251. // Simulate mouse movement
  2252. const point = points[index];
  2253. // In a real implementation, you would trigger actual mouse events
  2254. // For our purposes, we'll just move to the next point
  2255. setTimeout(() => {
  2256. executeMouseMovement(points, index + 1, delay, callback);
  2257. }, delay);
  2258. }
  2259.  
  2260. function getSquarePosition(square) {
  2261. // Convert chess notation (e.g., "e4") to screen coordinates
  2262. // This is a simplified version - in reality, you'd need to get actual board coordinates
  2263. const file = square.charCodeAt(0) - 'a'.charCodeAt(0);
  2264. const rank = parseInt(square.charAt(1)) - 1;
  2265. // Get board dimensions
  2266. const boardRect = board.getBoundingClientRect();
  2267. const squareSize = boardRect.width / 8;
  2268. // Calculate center of the square
  2269. const x = boardRect.left + (file + 0.5) * squareSize;
  2270. const y = boardRect.top + (7 - rank + 0.5) * squareSize;
  2271. return { x, y };
  2272. }