Slither.io auto play bot 2025

auto play bot for slither.io

  1. // ==UserScript==
  2. // @name Slither.io auto play bot 2025
  3. // @include http://slither.com/io
  4. // @author Saarlooswolf
  5. // @description auto play bot for slither.io
  6. // @namespace http://tampermonkey.net/
  7. // @version 0.2.1
  8. // @match *://Slither.com/io/*
  9. // @license MIT License
  10. // ==/UserScript==
  11.  
  12. /*Copyright 2025 Saarlooswolf
  13.  
  14. Permission is hereby granted, free of charge, to any person obtaining a copy of
  15. this software and associated documentation files (the “Software”), to deal in
  16. the Software without restriction, including without limitation the rights to
  17. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  18. the Software, and to permit persons to whom the Software is furnished to do so,
  19. subject to the following conditions:
  20.  
  21. The above copyright notice and this permission notice shall be included in all
  22. copies or substantial portions of the Software.
  23.  
  24. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  26. FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  27. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  28. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/
  30.  
  31. var el = document.getElementsByTagName('iframe');
  32.  
  33. for (var i = 0; i < el.length; i++) {
  34. var currentEl = el[i];
  35. currentEl.remove();
  36. }
  37.  
  38. // remove the vote text
  39. if (document.getElementById("votetxth") !== null) {
  40. document.getElementById("votetxth").remove()
  41. }
  42. if (document.getElementById("trumpbtnh") !== null) {
  43. document.getElementById("trumpbtnh").remove()
  44. }
  45. if (document.getElementById("kamalabtnh") !== null) {
  46. document.getElementById("kamalabtnh").remove()
  47. }
  48.  
  49.  
  50. if (window.top != window.self)
  51.  
  52. REALSCORE = 10;
  53. REALDNA = [1,1,1,1,1,1,1,1,1,1,1,1];
  54.  
  55. BESTRANK = 1000;
  56. BESTSCORE = 1;
  57.  
  58. printbot = function() {
  59. console.log("Dumping bot data:\nREALDNA = " + JSON.stringify(REALDNA) + ";\nREALSCORE = " + REALSCORE + ";\nBESTRANK = " + BESTRANK + ";\nBESTSCORE = " + BESTSCORE + ";");
  60. }
  61.  
  62. savedna = function() {
  63. if(typeof(Storage) !== "undefined") {
  64. localStorage["REALSCORE"] = REALSCORE;
  65. localStorage["REALDNA"] = JSON.stringify(REALDNA);
  66. localStorage["BESTRANK"] = BESTRANK;
  67. localStorage["BESTSCORE"] = BESTSCORE;
  68. }
  69. }
  70.  
  71. cleardna = function() {
  72. localStorage.removeItem("REALSCORE");
  73. localStorage.removeItem("REALDNA");
  74. localStorage.removeItem("BESTRANK");
  75. localStorage.removeItem("BESTSCORE");
  76. REALSCORE = 30;
  77. BESTRANK = 1000;
  78. var distavoid = 90;
  79. var preykerroin = 5;
  80. var viholliskerroin = 544;
  81. var vaarakerroin = 200;
  82. var chargedistance = 500;
  83. var pakoondistance = 70;
  84. var keskikerroin = 2.0;
  85. var keskihakukerroin = 0.1;
  86.  
  87. REALDNA = [distavoid,preykerroin,viholliskerroin,vaarakerroin,chargedistance,pakoondistance,keskikerroin,keskihakukerroin];
  88. TESTDNA = REALDNA.slice();
  89. TESTSCORE = REALSCORE;
  90. testingdna = 1;
  91. DNA = REALDNA.slice();
  92. savedna();
  93. }
  94.  
  95. if(typeof(Storage) !== "undefined") {
  96. // Code for localStorage/sessionStorage.
  97. if (!localStorage.REALSCORE || !localStorage.REALDNA || !localStorage.BESTRANK || !localStorage.BESTSCORE) {
  98. cleardna();
  99. }
  100. else
  101. {
  102. REALSCORE = localStorage["REALSCORE"]*1;
  103. REALDNA = JSON.parse(localStorage["REALDNA"]);
  104. BESTRANK = localStorage["BESTRANK"]*1;
  105. BESTSCORE = localStorage["BESTSCORE"]*1;
  106. }
  107. } else {
  108. // Sorry! No Web Storage support..
  109. }
  110.  
  111.  
  112. TESTDNA = REALDNA.slice();
  113. TESTSCORE = REALSCORE;
  114.  
  115. testingdna = 1;
  116. DNA = REALDNA.slice();
  117.  
  118. var injected_dead = true;
  119.  
  120. var lastscore = 0;
  121. var bestscore = 0;
  122.  
  123. var lastrank = 0;
  124. var bestrank = 1000;
  125. var uhka = false;
  126.  
  127.  
  128. var ruokakerroin = 1/40;
  129. var ruokapower = 1;
  130. var vihollispower = 2;
  131. var vaarapower = 2;
  132. var preypower = 1;
  133. var keskipower = 1;
  134.  
  135.  
  136. var preychase = true;
  137.  
  138. var learnrate = 0.3;
  139. var precision = 100;
  140. var EnableBot = true;
  141.  
  142. INJECTED = function() {
  143. var kerroin = 10000;
  144. // Enable or disable bot if E is pressed.
  145. document.addEventListener('keydown', (event) => {
  146. var ShouldHandleKeyDown = true;
  147. if (event.key === 'e' && ShouldHandleKeyDown === true) {
  148. console.log("Enableing bot")
  149. EnableBot = !EnableBot;
  150. }
  151. });
  152.  
  153. if (animating && EnableBot) {
  154. if (slither) {
  155. accelerate = false;
  156. injected_dead = false;
  157. //xm = grd-slither.xx;
  158. //ym = grd-slither.yy;
  159. xt = 0;
  160. yt = 0;
  161. mindist = grd;
  162. for (var i = 0; i < preys.length; i++) {
  163. xtd = (preys[i].xx-slither.xx);
  164. ytd = (preys[i].yy-slither.yy);
  165. dist = Math.sqrt(xtd*xtd + ytd*ytd);
  166. xt += xtd/Math.pow(dist,preypower+1)*DNA[1];
  167. yt += ytd/Math.pow(dist,preypower+1)*DNA[1];
  168. if (dist < DNA[4] && preychase)
  169. {
  170. accelerate = true;
  171. }
  172. }
  173.  
  174. uhka = false;
  175. for (var i = 0; i < slithers.length; i++) {
  176. //alert(myStringArray[i]);
  177. target = slithers[i];
  178. if (slither.id!=target.id)
  179. {
  180. xtd = (target.xx-slither.xx);
  181. ytd = (target.yy-slither.yy);
  182. dist = Math.sqrt(xtd*xtd + ytd*ytd)-DNA[0];
  183. dist = Math.max(1, dist);
  184. xt += -xtd/Math.pow(dist,vihollispower+1)*DNA[2];
  185. yt += -ytd/Math.pow(dist,vihollispower+1)*DNA[2];
  186. if (dist < DNA[5])
  187. {
  188. accelerate = true;
  189. }
  190. if (dist<mindist)
  191. {
  192. uhka = target;
  193. mindist = dist;
  194. /*if (mindist<300)
  195. {
  196. accelerate = true;
  197. }*/
  198. }
  199. parts = target.pts;
  200. for (var k = 0; k < parts.length; k++)
  201. {
  202. part = parts[k];
  203. xtd = (part.xx-slither.xx);
  204. ytd = (part.yy-slither.yy);
  205. dist = Math.sqrt(xtd*xtd + ytd*ytd)-DNA[0];
  206. dist = Math.max(1, dist);
  207. xt += -xtd/Math.pow(dist,vaarapower+1)*DNA[3];
  208. yt += -ytd/Math.pow(dist,vaarapower+1)*DNA[3];
  209. }
  210. }
  211. }
  212. if (!(preychase && preys.length>0))
  213. {
  214. for (var i = 0; i < foods_c; i++) {
  215. //alert(myStringArray[i]);
  216. xtd = (foods[i].xx-slither.xx);
  217. ytd = (foods[i].yy-slither.yy);
  218. dist = Math.sqrt(xtd*xtd + ytd*ytd);
  219. //xt += Math.pow(ruokakerroin*foods[i].fw,2)*xtd/Math.pow(dist,ruokapower+1);
  220. //yt += Math.pow(ruokakerroin*foods[i].fw,2)*ytd/Math.pow(dist,ruokapower+1);
  221. xt += Math.pow(foods[i].gr,2)*xtd/Math.pow(dist,ruokapower+1);
  222. yt += Math.pow(foods[i].gr,2)*ytd/Math.pow(dist,ruokapower+1);
  223. }
  224. xtd = (grd-slither.xx);
  225. ytd = (grd-slither.yy);
  226. dist = Math.sqrt(xtd*xtd + ytd*ytd);
  227. xt += xtd/Math.pow(grd-dist,keskipower+1)*DNA[6];
  228. yt += ytd/Math.pow(grd-dist,keskipower+1)*DNA[6];
  229. xt += xtd/grd*DNA[7];
  230. yt += ytd/grd*DNA[7];
  231. }
  232. xm = xt*kerroin;
  233. ym = yt*kerroin;
  234. lsxm = -xm;
  235. lsym = -ym;
  236. if (accelerate)
  237. {
  238. setAcceleration(1);
  239. }
  240. else
  241. {
  242. setAcceleration(0);
  243. }
  244. //console.log("xx:" + view_xx + "yy:" + view_yy);
  245. //console.log("slither.xx:" + slither.xx + "slither.yy:" + slither.yy);
  246. //console.log("slither.fx:" + slither.fx + "slither.fy:" + slither.fy);
  247. //console.log("fvx:" + fvx + "fvy:" + fvy);
  248. //console.log("");
  249. //console.log("foods_c:" + foods_c);
  250. //console.log("slithers.length:" + slithers.length);
  251. //console.log("D:" + Math.sqrt(xm*xm + ym*ym));
  252. lastscore = Math.floor(150 * (fpsls[slither.sct] + slither.fam / fmlts[slither.sct] - 1) - 50) / 10;
  253. if (!lastscore)
  254. {
  255. lastscore = 1;
  256. }
  257. lastrank = rank;
  258. if (!lastrank)
  259. {
  260. lastrank = 500;
  261. }
  262. }
  263. else
  264. {
  265. if (!injected_dead)
  266. {
  267. injected_dead = true;
  268. if (lastscore>bestscore)
  269. {
  270. console.log("Last score: " + lastscore + "(new best)");
  271. bestscore = lastscore;
  272. BESTSCORE = bestscore;
  273. }
  274. else
  275. {
  276. console.log("Last score: " + lastscore + " Best: " + bestscore);
  277. }
  278. if (lastrank<bestrank)
  279. {
  280. console.log("Last rank: " + lastrank + "(new best)");
  281. bestrank = lastrank;
  282. BESTRANK = bestrank;
  283. }
  284. else
  285. {
  286. console.log("Last rank: " + lastrank + " Best: " + bestrank);
  287. }
  288. if (testingdna>0)
  289. {
  290. TESTSCORE = lastscore/(lastrank+1);
  291.  
  292. }
  293. else
  294. {
  295. REALSCORE = (REALSCORE+lastscore/lastrank)/2;
  296. }
  297. lastscore = 0;
  298.  
  299. for (var key in DNA)
  300. {
  301. if (TESTSCORE > REALSCORE)
  302. {
  303. var mul = TESTSCORE/REALSCORE
  304. REALDNA[key] = (REALDNA[key] + TESTDNA[key]*mul)/(1+mul);
  305. REALDNA[key] = Math.round(REALDNA[key]*precision)/precision;
  306. }
  307.  
  308. if (testingdna<0)
  309. {
  310. TESTDNA[key] = REALDNA[key] + REALDNA[key]*(Math.random() - Math.random())*learnrate;
  311. TESTDNA[key] = Math.round(TESTDNA[key]*precision)/precision;
  312. }
  313. }
  314. savedna();
  315.  
  316. testingdna = -testingdna;
  317.  
  318. if (testingdna>0)
  319. {
  320. DNA = TESTDNA.slice();
  321. }
  322. else
  323. {
  324. DNA = REALDNA.slice();
  325. }
  326. //console.log("DNA = [" + DNA + "];");
  327. setTimeout(connect, 3000);
  328. //console.log("Reconnecting");
  329. }
  330. }
  331. }
  332. }
  333.  
  334. var injectbot = function() {
  335. if (typeof(redraw) != "undefined")
  336. {
  337. oldredraw = redraw;
  338.  
  339. redraw = function() {
  340. INJECTED();
  341. oldredraw();
  342. }
  343. console.log("injected")
  344. window.onmousemove = null;
  345. }
  346. else
  347. {
  348. setTimeout(injectbot, 1000);
  349. console.log("retrying")
  350. }
  351. }
  352. injectbot();