Advertisement
Etrugul

SERD324Fyg8

Jan 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 54.48 KB | None | 0 0
  1. Hotkeys
  2. Press 'R' if you want to toggle the line and dot drawing.
  3. Press 'T' if you want to use the manual controls.
  4. Press 'D' to toggle the dark mode.
  5. Press 'F' to toggle the show mass option.
  6. Press 'ESC' for the option menu.
  7.  
  8.  
  9. Copyright (c) 2015 Apostolique
  10. Permission is hereby granted, free of charge, to any person obtaining a copy
  11. of this software and associated documentation files (the "Software"), to deal
  12. in the Software without restriction, including without limitation the rights
  13. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. copies of the Software, and to permit persons to whom the Software is
  15. furnished to do so, subject to the following conditions:
  16. The above copyright notice and this permission notice shall be included in all
  17. copies or substantial portions of the Software.
  18. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. SOFTWARE.*/
  25.  
  26. // ==UserScript==
  27. // @name AposBot
  28. // @namespace AposBot
  29. // @include http://agar.io/*
  30. // @version 3.651
  31. // @grant none
  32. // @author http://www.twitch.tv/apostolique
  33. // ==/UserScript==
  34.  
  35. var aposBotVersion = 3.651;
  36.  
  37. //TODO: Team mode
  38. // Detect when people are merging
  39. // Split to catch smaller targets
  40. // Angle based cluster code
  41. // Better wall code
  42. // In team mode, make allies be obstacles.
  43.  
  44. /*
  45. Number.prototype.mod = function(n) {
  46. return ((this % n) + n) % n;
  47. };
  48. */
  49.  
  50. Array.prototype.peek = function() {
  51. return this[this.length - 1];
  52. };
  53.  
  54. //Load it from the two file in case one is not loaded
  55. window.log = function(message){
  56. if(window.logDebugging === true){
  57. console.log.apply(console, arguments);
  58. }
  59. }
  60.  
  61. var sha = "efde0488cc2cc176db48dd23b28a20b90314352b";
  62. (function () {
  63. window.jQuery.ajax({
  64. url: "https://api.github.com/repos/apostolique/Agar.io-bot/git/refs/heads/master",
  65. cache: false,
  66. dataType: "jsonp"
  67. }).done(function(data) {
  68. console.dir(data.data);
  69. window.log("hmm: " + data.data.object.sha);
  70. sha = data.data.object.sha;
  71.  
  72. function update(prefix, name, url) {
  73. window.jQuery(document.body).prepend("<div id='" + prefix + "Dialog' style='position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px; z-index: 100; display: none;'>");
  74. window.jQuery('#' + prefix + 'Dialog').append("<div id='" + prefix + "Message' style='width: 350px; background-color: #FFFFFF; margin: 100px auto; border-radius: 15px; padding: 5px 15px 5px 15px;'>");
  75. window.jQuery('#' + prefix + 'Message').append("<h2>UPDATE TIME!!!</h2>");
  76. window.jQuery('#' + prefix + 'Message').append("<p>Grab the update for: <a id='" + prefix + "Link' href='" + url + "' target=\"_blank\">" + name + "</a></p>");
  77. window.jQuery('#' + prefix + 'Link').on('click', function() {
  78. window.jQuery("#" + prefix + "Dialog").hide();
  79. window.jQuery("#" + prefix + "Dialog").remove();
  80. });
  81. window.jQuery("#" + prefix + "Dialog").show();
  82. }
  83.  
  84. $.get('https://raw.githubusercontent.com/Apostolique/Agar.io-bot/master/bot.user.js?' + Math.floor((Math.random() * 1000000) + 1), function(data) {
  85. var latestVersion = data.replace(/(\r\n|\n|\r)/gm,"");
  86. latestVersion = latestVersion.substring(latestVersion.indexOf("// @version")+11,latestVersion.indexOf("// @grant"));
  87.  
  88. latestVersion = parseFloat(latestVersion + 0.0000);
  89. var myVersion = parseFloat(aposBotVersion + 0.0000);
  90.  
  91. if(latestVersion > myVersion)
  92. {
  93. update("aposBot", "bot.user.js", "https://github.com/Apostolique/Agar.io-bot/blob/" + sha + "/bot.user.js/");
  94. }
  95. window.log('Current bot.user.js Version: ' + myVersion + " on Github: " + latestVersion);
  96. });
  97.  
  98. }).fail(function() {});
  99. })();
  100.  
  101. window.log("Running Apos Bot!");
  102.  
  103. var f = window;
  104. var g = window.jQuery;
  105.  
  106.  
  107. window.log("Apos Bot!");
  108.  
  109. window.botList = window.botList || [];
  110.  
  111. /*function QuickBot() {
  112. this.name = "QuickBot V1";
  113. this.customParameters = {};
  114. this.keyAction = function(key) {};
  115. this.displayText = function() {return [];};
  116. this.mainLoop = function() {
  117. return [screenToGameX(getMouseX()),
  118. screenToGameY(getMouseY())];
  119. };
  120. }
  121. window.botList.push(new QuickBot());*/
  122.  
  123. function AposBot() {
  124. this.name = "AposBot " + aposBotVersion;
  125.  
  126. this.toggleFollow = false;
  127. this.keyAction = function(key) {
  128. if (key.keyCode === 81) {
  129. window.log("Toggle Follow Mouse!");
  130. this.toggleFollow = !this.toggleFollow;
  131. }
  132. };
  133.  
  134. this.displayText = function() {
  135. return ["Q - Follow Mouse: " + (this.toggleFollow ? "On" : "Off")];
  136. };
  137.  
  138. // Using mod function instead the prototype directly as it is very slow
  139. this.mod = function(num, mod) {
  140. if (mod & (mod - 1) === 0 && mod !== 0) {
  141. return num & (mod - 1);
  142. }
  143. return num < 0 ? ((num % mod) + mod) % mod : num % mod;
  144. };
  145. this.splitDistance = 710;
  146.  
  147. this.isMerging = function(cell1, cell2) {
  148. var dist = this.computeDistance(cell1.x, cell1.y, cell2.x, cell2.y, cell1.size, cell2.size);
  149.  
  150. //debug logging
  151. window.log("Merge:", [cell1.x, cell1.y, cell2.x, cell2.y, cell1.size, cell2.size, dist].join(", "))
  152.  
  153. return dist <= -50;
  154. };
  155.  
  156. //Given an angle value that was gotten from valueAndleBased(),
  157. //returns a new value that scales it appropriately.
  158. this.paraAngleValue = function(angleValue, range) {
  159. return (15 / (range[1])) * (angleValue * angleValue) - (range[1] / 6);
  160. };
  161.  
  162. this.getMass = function(size) {
  163. return Math.pow(size / 10, 2);
  164. };
  165.  
  166. this.valueAngleBased = function(angle, range) {
  167. var leftValue = this.mod(angle - range[0], 360);
  168. var rightValue = this.mod(this.rangeToAngle(range) - angle, 360);
  169.  
  170. var bestValue = Math.min(leftValue, rightValue);
  171.  
  172. if (bestValue <= range[1]) {
  173. return this.paraAngleValue(bestValue, range);
  174. }
  175. return -1;
  176. };
  177.  
  178. this.computeDistance = function(x1, y1, x2, y2, s1, s2) {
  179. // Make sure there are no null optional params.
  180. s1 = s1 || 0;
  181. s2 = s2 || 0;
  182. var xdis = x1 - x2; // <--- FAKE AmS OF COURSE!
  183. var ydis = y1 - y2;
  184. var distance = Math.sqrt(xdis * xdis + ydis * ydis) - (s1 + s2);
  185.  
  186. return distance;
  187. };
  188.  
  189. // Get a distance that is Inexpensive on the cpu for various purpaces
  190. this.computeInexpensiveDistance = function(x1, y1, x2, y2, s1, s2) {
  191. // Make sure there are no null optional params.
  192. s1 = s1 || 0;
  193. s2 = s2 || 0;
  194. var xdis = x1 - x2;
  195. var ydis = y1 - y2;
  196. // Get abs quickly
  197. xdis = xdis < 0 ? xdis * -1 : xdis;
  198. ydis = ydis < 0 ? ydis * -1 : ydis;
  199.  
  200. var distance = xdis + ydis;
  201.  
  202. return distance;
  203. };
  204.  
  205. this.computeDistanceFromCircleEdgeDeprecated = function(x1, y1, x2, y2, s2) {
  206. var tempD = this.computeDistance(x1, y1, x2, y2);
  207.  
  208. var offsetX = 0;
  209. var offsetY = 0;
  210.  
  211. var ratioX = tempD / (x1 - x2);
  212. var ratioY = tempD / (y1 - y2);
  213.  
  214. offsetX = x1 - (s2 / ratioX);
  215. offsetY = y1 - (s2 / ratioY);
  216.  
  217. drawPoint(offsetX, offsetY, 5, "");
  218.  
  219. return this.computeDistance(x2, y2, offsetX, offsetY);
  220. };
  221.  
  222. this.compareSize = function(player1, player2, ratio) {
  223. if (player1.size * player1.size * ratio < player2.size * player2.size) {
  224. return true;
  225. }
  226. return false;
  227. },
  228.  
  229. this.canSplit = function(player1, player2) {
  230. return this.compareSize(player1, player2, 2.8) && !this.compareSize(player1, player2, 20);
  231. };
  232.  
  233. this.isItMe = function(player, cell) {
  234. if (getMode() == ":teams") {
  235. var currentColor = player[0].color;
  236. var currentRed = currentColor.substring(1,3);
  237. var currentGreen = currentColor.substring(3,5);
  238. var currentBlue = currentColor.substring(5,7);
  239.  
  240. var currentTeam = this.getTeam(currentRed, currentGreen, currentBlue);
  241.  
  242. var cellColor = cell.color;
  243.  
  244. var cellRed = cellColor.substring(1,3);
  245. var cellGreen = cellColor.substring(3,5);
  246. var cellBlue = cellColor.substring(5,7);
  247.  
  248. var cellTeam = this.getTeam(cellRed, cellGreen, cellBlue);
  249.  
  250. if (currentTeam == cellTeam && !cell.isVirus()) {
  251. return true;
  252. }
  253.  
  254. window.log("COLOR: " + color);
  255.  
  256. } else {
  257. for (var i = 0; i < player.length; i++) {
  258. if (cell.id == player[i].id) {
  259. return true;
  260. }
  261. }
  262. }
  263. return false;
  264. };
  265.  
  266. this.getTeam = function(red, green, blue) {
  267. if (red == "ff") {
  268. return 0;
  269. } else if (green == "ff") {
  270. return 1;
  271. }
  272. return 2;
  273. };
  274.  
  275. this.isFood = function(blob, cell) {
  276. if (!cell.isVirus() && this.compareSize(cell, blob, 1.33) || (cell.size <= 13)) {
  277. return true;
  278. }
  279. return false;
  280. };
  281.  
  282. this.isThreat = function(blob, cell) {
  283.  
  284. if (!cell.isVirus() && this.compareSize(blob, cell, 1.30)) {
  285. return true;
  286. }
  287. return false;
  288. };
  289.  
  290. this.isVirus = function(blob, cell) {
  291. if (blob == null) {
  292. if (cell.isVirus()) {
  293. return true;
  294. } else {
  295. return false;
  296. }
  297. }
  298. if (cell.isVirus() && this.compareSize(cell, blob, 1.1)) {
  299. return true;
  300. } else if (cell.isVirus() && cell.color.substring(3, 5).toLowerCase() != "ff") {
  301. return true;
  302. }
  303. return false;
  304. };
  305.  
  306. this.isSplitTarget = function(that, blob, cell) {
  307. if (that.canSplit(cell, blob)) {
  308. return true;
  309. }
  310. return false;
  311. };
  312.  
  313. this.getTimeToRemerge = function(mass){
  314. return Math.max(30, Math.floor(mass*0.02));
  315. //return ((mass*0.02) + 30);
  316. };
  317.  
  318. this.separateListBasedOnFunction = function(that, listToUse, blob) {
  319. var foodElementList = [];
  320. var threatList = [];
  321. var virusList = [];
  322. var splitTargetList = [];
  323.  
  324. var player = getPlayer();
  325.  
  326. var mergeList = [];
  327.  
  328. Object.keys(listToUse).forEach(function(element, index) {
  329. var isMe = that.isItMe(player, listToUse[element]);
  330.  
  331. if (!isMe) {
  332. if (that.isFood(blob, listToUse[element]) && listToUse[element].isNotMoving()) {
  333. //IT'S FOOD!
  334. foodElementList.push(listToUse[element]);
  335.  
  336.  
  337. } else if (that.isThreat(blob, listToUse[element])) {
  338. //IT'S DANGER!
  339. threatList.push(listToUse[element]);
  340. mergeList.push(listToUse[element]);
  341. } else if (that.isVirus(blob, listToUse[element])) {
  342. //IT'S VIRUS!
  343. virusList.push(listToUse[element]);
  344. }
  345. else if (that.isSplitTarget(that, blob, listToUse[element])) {
  346. drawCircle(listToUse[element].x, listToUse[element].y, listToUse[element].size + 50, 7);
  347. splitTargetList.push(listToUse[element]);
  348. //foodElementList.push(listToUse[element]);
  349. mergeList.push(listToUse[element]);
  350. }
  351. else {if (that.isVirus(null, listToUse[element])==false) {mergeList.push(listToUse[element]);}
  352. }
  353. }/*else if(isMe && (getBlobCount(getPlayer()) > 0)){
  354. //Attempt to make the other cell follow the mother one
  355. foodElementList.push(listToUse[element]);
  356. }*/
  357. });
  358.  
  359. foodList = [];
  360. for (var i = 0; i < foodElementList.length; i++) {
  361. foodList.push([foodElementList[i].x, foodElementList[i].y, foodElementList[i].size]);
  362. }
  363.  
  364. window.log("Merglist length: " + mergeList.length)
  365. //cell merging
  366. for (var i = 0; i < mergeList.length; i++) {
  367. for (var z = 0; z < mergeList.length; z++) {
  368. if (z != i && that.isMerging(mergeList[i], mergeList[z])) { //z != i &&
  369. //found cells that appear to be merging - if they constitute a threat add them to the theatlist
  370.  
  371. //clone us a new cell
  372. var newThreat = {};
  373. var prop;
  374.  
  375. for (prop in mergeList[i]) {
  376. newThreat[prop] = mergeList[i][prop];
  377. }
  378.  
  379. //average distance and sum the size
  380. newThreat.x = (mergeList[i].x + mergeList[z].x)/2;
  381. newThreat.y = (mergeList[i].y + mergeList[z].y)/2;
  382. newThreat.size = (mergeList[i].size + mergeList[z].size);
  383. newThreat.nopredict = true;
  384. //check its a threat
  385. if (that.isThreat(blob, newThreat)) {
  386. //IT'S DANGER!
  387. threatList.push(newThreat);
  388. }
  389.  
  390. }
  391. }
  392. }
  393.  
  394. return [foodList, threatList, virusList, splitTargetList];
  395. };
  396.  
  397. this.getAll = function(blob) {
  398. var dotList = [];
  399. var player = getPlayer();
  400. var interNodes = getMemoryCells();
  401.  
  402. dotList = this.separateListBasedOnFunction(this, interNodes, blob);
  403.  
  404. return dotList;
  405. };
  406.  
  407. this.clusterFood = function(foodList, blobSize) {
  408. var clusters = [];
  409. var addedCluster = false;
  410.  
  411. //1: x
  412. //2: y
  413. //3: size or value
  414. //4: Angle, not set here.
  415.  
  416. for (var i = 0; i < foodList.length; i++) {
  417. for (var j = 0; j < clusters.length; j++) {
  418. if (this.computeInexpensiveDistance(foodList[i][0], foodList[i][1], clusters[j][0], clusters[j][1]) < blobSize * 2) {
  419. clusters[j][0] = (foodList[i][0] + clusters[j][0]) / 2;
  420. clusters[j][1] = (foodList[i][1] + clusters[j][1]) / 2;
  421. clusters[j][2] += foodList[i][2];
  422. addedCluster = true;
  423. break;
  424. }
  425. }
  426. if (!addedCluster) {
  427. clusters.push([foodList[i][0], foodList[i][1], foodList[i][2], 0]);
  428. }
  429. addedCluster = false;
  430. }
  431. return clusters;
  432. };
  433.  
  434. this.getAngle = function(x1, y1, x2, y2) {
  435. //Handle vertical and horizontal lines.
  436.  
  437. if (x1 == x2) {
  438. if (y1 < y2) {
  439. return 271;
  440. //return 89;
  441. } else {
  442. return 89;
  443. }
  444. }
  445.  
  446. return (Math.round(Math.atan2(-(y1 - y2), -(x1 - x2)) / Math.PI * 180 + 180));
  447. };
  448.  
  449. this.slope = function(x1, y1, x2, y2) {
  450. var m = (y1 - y2) / (x1 - x2);
  451.  
  452. return m;
  453. };
  454.  
  455. this.slopeFromAngle = function(degree) {
  456. if (degree == 270) {
  457. degree = 271;
  458. } else if (degree == 90) {
  459. degree = 91;
  460. }
  461. return Math.tan((degree - 180) / 180 * Math.PI);
  462. };
  463.  
  464. //Given two points on a line, finds the slope of a perpendicular line crossing it.
  465. this.inverseSlope = function(x1, y1, x2, y2) {
  466. var m = this.slope(x1, y1, x2, y2);
  467. return (-1) / m;
  468. };
  469.  
  470. //Given a slope and an offset, returns two points on that line.
  471. this.pointsOnLine = function(slope, useX, useY, distance) {
  472. var b = useY - slope * useX;
  473. var r = Math.sqrt(1 + slope * slope);
  474.  
  475. var newX1 = (useX + (distance / r));
  476. var newY1 = (useY + ((distance * slope) / r));
  477. var newX2 = (useX + ((-distance) / r));
  478. var newY2 = (useY + (((-distance) * slope) / r));
  479.  
  480. return [
  481. [newX1, newY1],
  482. [newX2, newY2]
  483. ];
  484. };
  485.  
  486. this.followAngle = function(angle, useX, useY, distance) {
  487. var slope = this.slopeFromAngle(angle);
  488. var coords = this.pointsOnLine(slope, useX, useY, distance);
  489.  
  490. var side = this.mod(angle - 90, 360);
  491. if (side < 180) {
  492. return coords[1];
  493. } else {
  494. return coords[0];
  495. }
  496. };
  497.  
  498. //Using a line formed from point a to b, tells if point c is on S side of that line.
  499. this.isSideLine = function(a, b, c) {
  500. if ((b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]) > 0) {
  501. return true;
  502. }
  503. return false;
  504. };
  505.  
  506. //angle range2 is within angle range2
  507. //an Angle is a point and a distance between an other point [5, 40]
  508. this.angleRangeIsWithin = function(range1, range2) {
  509. if (range2[0] == this.mod(range2[0] + range2[1], 360)) {
  510. return true;
  511. }
  512. window.log("r1: " + range1[0] + ", " + range1[1] + " ... r2: " + range2[0] + ", " + range2[1]);
  513.  
  514. var distanceFrom0 = this.mod(range1[0] - range2[0], 360);
  515. var distanceFrom1 = this.mod(range1[1] - range2[0], 360);
  516.  
  517. if (distanceFrom0 < range2[1] && distanceFrom1 < range2[1] && distanceFrom0 < distanceFrom1) {
  518. return true;
  519. }
  520. return false;
  521. };
  522.  
  523. this.angleRangeIsWithinInverted = function(range1, range2) {
  524. var distanceFrom0 = this.mod(range1[0] - range2[0], 360);
  525. var distanceFrom1 = this.mod(range1[1] - range2[0], 360);
  526.  
  527. if (distanceFrom0 < range2[1] && distanceFrom1 < range2[1] && distanceFrom0 > distanceFrom1) {
  528. return true;
  529. }
  530. return false;
  531. };
  532.  
  533. this.angleIsWithin = function(angle, range) {
  534. var diff = this.mod(this.rangeToAngle(range) - angle, 360);
  535. if (diff >= 0 && diff <= range[1]) {
  536. return true;
  537. }
  538. return false;
  539. };
  540.  
  541. this.rangeToAngle = function(range) {
  542. return this.mod(range[0] + range[1], 360);
  543. };
  544.  
  545. this.anglePair = function(range) {
  546. return (range[0] + ", " + this.rangeToAngle(range) + " range: " + range[1]);
  547. };
  548.  
  549. this.computeAngleRanges = function(blob1, blob2) {
  550. var mainAngle = this.getAngle(blob1.x, blob1.y, blob2.x, blob2.y);
  551. var leftAngle = this.mod(mainAngle - 90, 360);
  552. var rightAngle = this.mod(mainAngle + 90, 360);
  553.  
  554. var blob1Left = this.followAngle(leftAngle, blob1.x, blob1.y, blob1.size);
  555. var blob1Right = this.followAngle(rightAngle, blob1.x, blob1.y, blob1.size);
  556.  
  557. var blob2Left = this.followAngle(rightAngle, blob2.x, blob2.y, blob2.size);
  558. var blob2Right = this.followAngle(leftAngle, blob2.x, blob2.y, blob2.size);
  559.  
  560. var blob1AngleLeft = this.getAngle(blob2.x, blob2.y, blob1Left[0], blob1Left[1]);
  561. var blob1AngleRight = this.getAngle(blob2.x, blob2.y, blob1Right[0], blob1Right[1]);
  562.  
  563. var blob2AngleLeft = this.getAngle(blob1.x, blob1.y, blob2Left[0], blob2Left[1]);
  564. var blob2AngleRight = this.getAngle(blob1.x, blob1.y, blob2Right[0], blob2Right[1]);
  565.  
  566. var blob1Range = this.mod(blob1AngleRight - blob1AngleLeft, 360);
  567. var blob2Range = this.mod(blob2AngleRight - blob2AngleLeft, 360);
  568.  
  569. var tempLine = this.followAngle(blob2AngleLeft, blob2Left[0], blob2Left[1], 400);
  570. //drawLine(blob2Left[0], blob2Left[1], tempLine[0], tempLine[1], 0);
  571.  
  572. if ((blob1Range / blob2Range) > 1) {
  573. drawPoint(blob1Left[0], blob1Left[1], 3, "");
  574. drawPoint(blob1Right[0], blob1Right[1], 3, "");
  575. drawPoint(blob1.x, blob1.y, 3, "" + blob1Range + ", " + blob2Range + " R: " + (Math.round((blob1Range / blob2Range) * 1000) / 1000));
  576. }
  577.  
  578. //drawPoint(blob2.x, blob2.y, 3, "" + blob1Range);
  579. };
  580.  
  581. this.debugAngle = function(angle, text) {
  582. var player = getPlayer();
  583. var line1 = this.followAngle(angle, player[0].x, player[0].y, 300);
  584. drawLine(player[0].x, player[0].y, line1[0], line1[1], 5);
  585. drawPoint(line1[0], line1[1], 5, "" + text);
  586. };
  587.  
  588. //TODO: Don't let this function do the radius math.
  589. this.getEdgeLinesFromPoint = function(blob1, blob2, radius) {
  590. var px = blob1.x;
  591. var py = blob1.y;
  592.  
  593. var cx = blob2.x;
  594. var cy = blob2.y;
  595.  
  596. //var radius = blob2.size;
  597.  
  598. /*if (blob2.isVirus()) {
  599. radius = blob1.size;
  600. } else if(canSplit(blob1, blob2)) {
  601. radius += splitDistance;
  602. } else {
  603. radius += blob1.size * 2;
  604. }*/
  605.  
  606. var shouldInvert = false;
  607.  
  608. var tempRadius = this.computeDistance(px, py, cx, cy);
  609. if (tempRadius <= radius) {
  610. radius = tempRadius - 5;
  611. shouldInvert = true;
  612. }
  613.  
  614. var dx = cx - px;
  615. var dy = cy - py;
  616. var dd = Math.sqrt(dx * dx + dy * dy);
  617. var a = Math.asin(radius / dd);
  618. var b = Math.atan2(dy, dx);
  619.  
  620. var t = b - a;
  621. var ta = {
  622. x: radius * Math.sin(t),
  623. y: radius * -Math.cos(t)
  624. };
  625.  
  626. t = b + a;
  627. var tb = {
  628. x: radius * -Math.sin(t),
  629. y: radius * Math.cos(t)
  630. };
  631.  
  632. var angleLeft = this.getAngle(cx + ta.x, cy + ta.y, px, py);
  633. var angleRight = this.getAngle(cx + tb.x, cy + tb.y, px, py);
  634. var angleDistance = this.mod(angleRight - angleLeft, 360);
  635.  
  636. /*if (shouldInvert) {
  637. var temp = angleLeft;
  638. angleLeft = this.mod(angleRight + 180, 360);
  639. angleRight = this.mod(temp + 180, 360);
  640. angleDistance = this.mod(angleRight - angleLeft, 360);
  641. }*/
  642.  
  643. return [angleLeft, angleDistance, [cx + tb.x, cy + tb.y],
  644. [cx + ta.x, cy + ta.y]
  645. ];
  646. };
  647.  
  648. this.addWall = function(listToUse, blob) {
  649. //var mapSizeX = Math.abs(f.getMapStartX - f.getMapEndX);
  650. //var mapSizeY = Math.abs(f.getMapStartY - f.getMapEndY);
  651. //var distanceFromWallX = mapSizeX/3;
  652. //var distanceFromWallY = mapSizeY/3;
  653. var distanceFromWallY = 1000;
  654. var distanceFromWallX = 1000;
  655. if (blob.x < getMapStartX() + distanceFromWallX) {
  656. //LEFT
  657. window.log("Left");
  658. listToUse.push([
  659. [115, true],
  660. [245, false], this.computeInexpensiveDistance(getMapStartX(), blob.y, blob.x, blob.y)
  661. ]);
  662. var lineLeft = this.followAngle(115, blob.x, blob.y, 190 + blob.size);
  663. var lineRight = this.followAngle(245, blob.x, blob.y, 190 + blob.size);
  664. drawLine(blob.x, blob.y, lineLeft[0], lineLeft[1], 5);
  665. drawLine(blob.x, blob.y, lineRight[0], lineRight[1], 5);
  666. drawArc(lineLeft[0], lineLeft[1], lineRight[0], lineRight[1], blob.x, blob.y, 5);
  667. }
  668. if (blob.y < getMapStartY() + distanceFromWallY) {
  669. //TOP
  670. window.log("TOP");
  671. listToUse.push([
  672. [205, true],
  673. [335, false], this.computeInexpensiveDistance(blob.x, getMapStartY(), blob.x, blob.y)
  674. ]);
  675. var lineLeft = this.followAngle(205, blob.x, blob.y, 190 + blob.size);
  676. var lineRight = this.followAngle(335, blob.x, blob.y, 190 + blob.size);
  677. drawLine(blob.x, blob.y, lineLeft[0], lineLeft[1], 5);
  678. drawLine(blob.x, blob.y, lineRight[0], lineRight[1], 5);
  679. drawArc(lineLeft[0], lineLeft[1], lineRight[0], lineRight[1], blob.x, blob.y, 5);
  680. }
  681. if (blob.x > getMapEndX() - distanceFromWallX) {
  682. //RIGHT
  683. window.log("RIGHT");
  684. listToUse.push([
  685. [295, true],
  686. [65, false], this.computeInexpensiveDistance(getMapEndX(), blob.y, blob.x, blob.y)
  687. ]);
  688. var lineLeft = this.followAngle(295, blob.x, blob.y, 190 + blob.size);
  689. var lineRight = this.followAngle(65, blob.x, blob.y, 190 + blob.size);
  690. drawLine(blob.x, blob.y, lineLeft[0], lineLeft[1], 5);
  691. drawLine(blob.x, blob.y, lineRight[0], lineRight[1], 5);
  692. drawArc(lineLeft[0], lineLeft[1], lineRight[0], lineRight[1], blob.x, blob.y, 5);
  693. }
  694. if (blob.y > getMapEndY() - distanceFromWallY) {
  695. //BOTTOM
  696. window.log("BOTTOM");
  697. listToUse.push([
  698. [25, true],
  699. [155, false], this.computeInexpensiveDistance(blob.x, getMapEndY(), blob.x, blob.y)
  700. ]);
  701. var lineLeft = this.followAngle(25, blob.x, blob.y, 190 + blob.size);
  702. var lineRight = this.followAngle(155, blob.x, blob.y, 190 + blob.size);
  703. drawLine(blob.x, blob.y, lineLeft[0], lineLeft[1], 5);
  704. drawLine(blob.x, blob.y, lineRight[0], lineRight[1], 5);
  705. drawArc(lineLeft[0], lineLeft[1], lineRight[0], lineRight[1], blob.x, blob.y, 5);
  706. }
  707. return listToUse;
  708. };
  709.  
  710. //listToUse contains angles in the form of [angle, boolean].
  711. //boolean is true when the range is starting. False when it's ending.
  712. //range = [[angle1, true], [angle2, false]]
  713.  
  714. this.getAngleIndex = function(listToUse, angle) {
  715. if (listToUse.length === 0) {
  716. return 0;
  717. }
  718.  
  719. for (var i = 0; i < listToUse.length; i++) {
  720. if (angle <= listToUse[i][0]) {
  721. return i;
  722. }
  723. }
  724.  
  725. return listToUse.length;
  726. };
  727.  
  728. this.addAngle = function(listToUse, range) {
  729. //#1 Find first open element
  730. //#2 Try to add range1 to the list. If it is within other range, don't add it, set a boolean.
  731. //#3 Try to add range2 to the list. If it is withing other range, don't add it, set a boolean.
  732.  
  733. //TODO: Only add the new range at the end after the right stuff has been removed.
  734.  
  735. var newListToUse = listToUse.slice();
  736.  
  737. var startIndex = 1;
  738.  
  739. if (newListToUse.length > 0 && !newListToUse[0][1]) {
  740. startIndex = 0;
  741. }
  742.  
  743. var startMark = this.getAngleIndex(newListToUse, range[0][0]);
  744. var startBool = this.mod(startMark, 2) != startIndex;
  745.  
  746. var endMark = this.getAngleIndex(newListToUse, range[1][0]);
  747. var endBool = this.mod(endMark, 2) != startIndex;
  748.  
  749. var removeList = [];
  750.  
  751. if (startMark != endMark) {
  752. //Note: If there is still an error, this would be it.
  753. var biggerList = 0;
  754. if (endMark == newListToUse.length) {
  755. biggerList = 1;
  756. }
  757.  
  758. for (var i = startMark; i < startMark + this.mod(endMark - startMark, newListToUse.length + biggerList); i++) {
  759. removeList.push(this.mod(i, newListToUse.length));
  760. }
  761. } else if (startMark < newListToUse.length && endMark < newListToUse.length) {
  762. var startDist = this.mod(newListToUse[startMark][0] - range[0][0], 360);
  763. var endDist = this.mod(newListToUse[endMark][0] - range[1][0], 360);
  764.  
  765. if (startDist < endDist) {
  766. for (var i = 0; i < newListToUse.length; i++) {
  767. removeList.push(i);
  768. }
  769. }
  770. }
  771.  
  772. removeList.sort(function(a, b){return b-a;});
  773.  
  774. for (var i = 0; i < removeList.length; i++) {
  775. newListToUse.splice(removeList[i], 1);
  776. }
  777.  
  778. if (startBool) {
  779. newListToUse.splice(this.getAngleIndex(newListToUse, range[0][0]), 0, range[0]);
  780. }
  781. if (endBool) {
  782. newListToUse.splice(this.getAngleIndex(newListToUse, range[1][0]), 0, range[1]);
  783. }
  784.  
  785. return newListToUse;
  786. };
  787.  
  788. this.getAngleRange = function(blob1, blob2, index, radius) {
  789. var angleStuff = this.getEdgeLinesFromPoint(blob1, blob2, radius);
  790.  
  791. var leftAngle = angleStuff[0];
  792. var rightAngle = this.rangeToAngle(angleStuff);
  793. var difference = angleStuff[1];
  794.  
  795. drawPoint(angleStuff[2][0], angleStuff[2][1], 3, "");
  796. drawPoint(angleStuff[3][0], angleStuff[3][1], 3, "");
  797.  
  798. window.log("Adding badAngles: " + leftAngle + ", " + rightAngle + " diff: " + difference);
  799.  
  800. var lineLeft = this.followAngle(leftAngle, blob1.x, blob1.y, 150 + blob1.size - index * 10);
  801. var lineRight = this.followAngle(rightAngle, blob1.x, blob1.y, 150 + blob1.size - index * 10);
  802.  
  803. if (blob2.isVirus()) {
  804. drawLine(blob1.x, blob1.y, lineLeft[0], lineLeft[1], 6);
  805. drawLine(blob1.x, blob1.y, lineRight[0], lineRight[1], 6);
  806. drawArc(lineLeft[0], lineLeft[1], lineRight[0], lineRight[1], blob1.x, blob1.y, 6);
  807. } else if(getCells().hasOwnProperty(blob2.id)) {
  808. drawLine(blob1.x, blob1.y, lineLeft[0], lineLeft[1], 0);
  809. drawLine(blob1.x, blob1.y, lineRight[0], lineRight[1], 0);
  810. drawArc(lineLeft[0], lineLeft[1], lineRight[0], lineRight[1], blob1.x, blob1.y, 0);
  811. } else {
  812. drawLine(blob1.x, blob1.y, lineLeft[0], lineLeft[1], 3);
  813. drawLine(blob1.x, blob1.y, lineRight[0], lineRight[1], 3);
  814. drawArc(lineLeft[0], lineLeft[1], lineRight[0], lineRight[1], blob1.x, blob1.y, 3);
  815. }
  816.  
  817. return [leftAngle, difference];
  818. };
  819.  
  820. //Given a list of conditions, shift the angle to the closest available spot respecting the range given.
  821. this.shiftAngle = function(listToUse, angle, range) {
  822. //TODO: shiftAngle needs to respect the range! DONE?
  823. for (var i = 0; i < listToUse.length; i++) {
  824. if (this.angleIsWithin(angle, listToUse[i])) {
  825. window.log("Shifting needed!");
  826.  
  827. var angle1 = listToUse[i][0];
  828. var angle2 = this.rangeToAngle(listToUse[i]);
  829.  
  830. var dist1 = this.mod(angle - angle1, 360);
  831. var dist2 = this.mod(angle2 - angle, 360);
  832.  
  833. if (dist1 < dist2) {
  834. if (this.angleIsWithin(angle1, range)) {
  835. return angle1;
  836. } else {
  837. return angle2;
  838. }
  839. } else {
  840. if (this.angleIsWithin(angle2, range)) {
  841. return angle2;
  842. } else {
  843. return angle1;
  844. }
  845. }
  846. }
  847. }
  848. window.log("No Shifting Was needed!");
  849. return angle;
  850. };
  851.  
  852. /**
  853. * This is the main bot logic. This is called quite often.
  854. * @return A 2 dimensional array with coordinates for every cells. [[x, y], [x, y]]
  855. */
  856. this.mainLoop = function() {
  857. var player = getPlayer();
  858. var interNodes = getMemoryCells();
  859.  
  860. if ( /*!toggle*/ 1) {
  861. //The following code converts the mouse position into an
  862. //absolute game coordinate.
  863. var useMouseX = screenToGameX(getMouseX());
  864. var useMouseY = screenToGameY(getMouseY());
  865. tempPoint = [useMouseX, useMouseY, 1];
  866.  
  867. //The current destination that the cells were going towards.
  868. var tempMoveX = getPointX();
  869. var tempMoveY = getPointY();
  870.  
  871. drawLine(getX() - (1920 / 2) / getZoomlessRatio(), getY() - (1080 / 2) / getZoomlessRatio(), getX() + (1920 / 2) / getZoomlessRatio(), getY() - (1080 / 2) / getZoomlessRatio(), 7);
  872. drawLine(getX() - (1920 / 2) / getZoomlessRatio(), getY() + (1080 / 2) / getZoomlessRatio(), getX() + (1920 / 2) / getZoomlessRatio(), getY() + (1080 / 2) / getZoomlessRatio(), 7);
  873. drawLine(getX() - (1920 / 2) / getZoomlessRatio(), getY() - (1080 / 2) / getZoomlessRatio(), getX() - (1920 / 2) / getZoomlessRatio(), getY() + (1080 / 2) / getZoomlessRatio(), 7);
  874. drawLine(getX() + (1920 / 2) / getZoomlessRatio(), getY() - (1080 / 2) / getZoomlessRatio(), getX() + (1920 / 2) / getZoomlessRatio(), getY() + (1080 / 2) / getZoomlessRatio(), 7);
  875.  
  876. //This variable will be returned at the end.
  877. //It will contain the destination choices for all the cells.
  878. //BTW!!! ERROR ERROR ABORT MISSION!!!!!!! READ BELOW -----------
  879. //
  880. //SINCE IT'S STUPID NOW TO ASK EACH CELL WHERE THEY WANT TO GO,
  881. //THE BOT SHOULD SIMPLY PICK ONE AND THAT'S IT, I MEAN WTF....
  882. var destinationChoices = []; //destination, size, danger
  883.  
  884. //Just to make sure the player is alive.
  885. if (player.length > 0) {
  886.  
  887. //Loop through all the player's cells.
  888. for (var k = 0; k < player.length; k++) {
  889. if (true) {
  890. drawPoint(player[k].x, player[k].y + player[k].size, 0, "" + (getLastUpdate() - player[k].birth) + " / " + parseInt((30000 + (player[k].birthMass * 57) - (getLastUpdate() - player[k].birth))) + " / " + player[k].birthMass);
  891. }
  892. }
  893.  
  894.  
  895. //Loops only for one cell for now.
  896. for (var k = 0; /*k < player.length*/ k < 1; k++) {
  897.  
  898. window.log("Working on blob: " + k);
  899.  
  900. drawCircle(player[k].x, player[k].y, player[k].size + this.splitDistance, 5);
  901. //drawPoint(player[0].x, player[0].y - player[0].size, 3, "" + Math.floor(player[0].x) + ", " + Math.floor(player[0].y));
  902.  
  903. //var allDots = processEverything(interNodes);
  904.  
  905. //loop through everything that is on the screen and
  906. //separate everything in it's own category.
  907. var allIsAll = this.getAll(player[k]);
  908.  
  909. //The food stored in element 0 of allIsAll
  910. var allPossibleFood = allIsAll[0];
  911. //The threats are stored in element 1 of allIsAll
  912. var allPossibleThreats = allIsAll[1];
  913. //The viruses are stored in element 2 of allIsAll
  914. var allPossibleViruses = allIsAll[2];
  915.  
  916. //The bot works by removing angles in which it is too
  917. //dangerous to travel towards to.
  918. var badAngles = [];
  919. var obstacleList = [];
  920.  
  921. var isSafeSpot = true;
  922. var isMouseSafe = true;
  923.  
  924. var clusterAllFood = this.clusterFood(allPossibleFood, player[k].size);
  925.  
  926. window.log("Looking for enemies!");
  927.  
  928. //Loop through all the cells that were identified as threats.
  929. for (var i = 0; i < allPossibleThreats.length; i++) {
  930.  
  931. var enemyDistance = this.computeDistance(allPossibleThreats[i].x, allPossibleThreats[i].y, player[k].x, player[k].y, allPossibleThreats[i].size);
  932.  
  933. allPossibleThreats[i].enemyDist = enemyDistance;
  934. }
  935.  
  936. /*allPossibleThreats.sort(function(a, b){
  937. return a.enemyDist-b.enemyDist;
  938. })*/
  939.  
  940. for (var i = 0; i < allPossibleThreats.length; i++) {
  941.  
  942. var enemyDistance = this.computeDistance(allPossibleThreats[i].x, allPossibleThreats[i].y, player[k].x, player[k].y);
  943.  
  944. var splitDangerDistance = allPossibleThreats[i].size + this.splitDistance + 150;
  945.  
  946. var normalDangerDistance = allPossibleThreats[i].size + 150;
  947.  
  948. var shiftDistance = player[k].size;
  949.  
  950. window.log("Found distance.");
  951.  
  952. var enemyCanSplit = this.canSplit(player[k], allPossibleThreats[i]);
  953. var secureDistance = (enemyCanSplit ? splitDangerDistance : normalDangerDistance);
  954.  
  955. for (var j = clusterAllFood.length - 1; j >= 0 ; j--) {
  956. if (this.computeDistance(allPossibleThreats[i].x, allPossibleThreats[i].y, clusterAllFood[j][0], clusterAllFood[j][1]) < secureDistance + shiftDistance)
  957. clusterAllFood.splice(j, 1);
  958. }
  959.  
  960. window.log("Removed some food.");
  961.  
  962. if (enemyCanSplit) {
  963. drawCircle(allPossibleThreats[i].x, allPossibleThreats[i].y, splitDangerDistance, 0);
  964. drawCircle(allPossibleThreats[i].x, allPossibleThreats[i].y, splitDangerDistance + shiftDistance, 6);
  965. } else {
  966. drawCircle(allPossibleThreats[i].x, allPossibleThreats[i].y, normalDangerDistance, 3);
  967. drawCircle(allPossibleThreats[i].x, allPossibleThreats[i].y, normalDangerDistance + shiftDistance, 6);
  968. }
  969.  
  970. if (allPossibleThreats[i].danger && getLastUpdate() - allPossibleThreats[i].dangerTimeOut > 1000) {
  971.  
  972. allPossibleThreats[i].danger = false;
  973. }
  974.  
  975. /*if ((enemyCanSplit && enemyDistance < splitDangerDistance) ||
  976. (!enemyCanSplit && enemyDistance < normalDangerDistance)) {
  977. allPossibleThreats[i].danger = true;
  978. allPossibleThreats[i].dangerTimeOut = f.getLastUpdate();
  979. }*/
  980.  
  981. window.log("Figured out who was important.");
  982.  
  983. if ((enemyCanSplit && enemyDistance < splitDangerDistance) || (enemyCanSplit && allPossibleThreats[i].danger)) {
  984.  
  985. badAngles.push(this.getAngleRange(player[k], allPossibleThreats[i], i, splitDangerDistance).concat(allPossibleThreats[i].enemyDist));
  986.  
  987. } else if ((!enemyCanSplit && enemyDistance < normalDangerDistance) || (!enemyCanSplit && allPossibleThreats[i].danger)) {
  988.  
  989. badAngles.push(this.getAngleRange(player[k], allPossibleThreats[i], i, normalDangerDistance).concat(allPossibleThreats[i].enemyDist));
  990.  
  991. } else if (enemyCanSplit && enemyDistance < splitDangerDistance + shiftDistance) {
  992. var tempOb = this.getAngleRange(player[k], allPossibleThreats[i], i, splitDangerDistance + shiftDistance);
  993. var angle1 = tempOb[0];
  994. var angle2 = this.rangeToAngle(tempOb);
  995.  
  996. obstacleList.push([[angle1, true], [angle2, false]]);
  997. } else if (!enemyCanSplit && enemyDistance < normalDangerDistance + shiftDistance) {
  998. var tempOb = this.getAngleRange(player[k], allPossibleThreats[i], i, normalDangerDistance + shiftDistance);
  999. var angle1 = tempOb[0];
  1000. var angle2 = this.rangeToAngle(tempOb);
  1001.  
  1002. obstacleList.push([[angle1, true], [angle2, false]]);
  1003. }
  1004. window.log("Done with enemy: " + i);
  1005. }
  1006.  
  1007. window.log("Done looking for enemies!");
  1008.  
  1009. var goodAngles = [];
  1010. var stupidList = [];
  1011.  
  1012. for (var i = 0; i < allPossibleViruses.length; i++) {
  1013. if (player[k].size < allPossibleViruses[i].size) {
  1014. drawCircle(allPossibleViruses[i].x, allPossibleViruses[i].y, allPossibleViruses[i].size + 10, 3);
  1015. drawCircle(allPossibleViruses[i].x, allPossibleViruses[i].y, allPossibleViruses[i].size * 2, 6);
  1016.  
  1017. } else {
  1018. drawCircle(allPossibleViruses[i].x, allPossibleViruses[i].y, player[k].size + 50, 3);
  1019. drawCircle(allPossibleViruses[i].x, allPossibleViruses[i].y, player[k].size * 2, 6);
  1020. }
  1021. }
  1022.  
  1023. for (var i = 0; i < allPossibleViruses.length; i++) {
  1024. var virusDistance = this.computeDistance(allPossibleViruses[i].x, allPossibleViruses[i].y, player[k].x, player[k].y);
  1025. if (player[k].size < allPossibleViruses[i].size) {
  1026. if (virusDistance < (allPossibleViruses[i].size * 2)) {
  1027. var tempOb = this.getAngleRange(player[k], allPossibleViruses[i], i, allPossibleViruses[i].size + 10);
  1028. var angle1 = tempOb[0];
  1029. var angle2 = this.rangeToAngle(tempOb);
  1030. obstacleList.push([[angle1, true], [angle2, false]]);
  1031. }
  1032. } else {
  1033. if (virusDistance < (player[k].size * 2)) {
  1034. var tempOb = this.getAngleRange(player[k], allPossibleViruses[i], i, player[k].size + 50);
  1035. var angle1 = tempOb[0];
  1036. var angle2 = this.rangeToAngle(tempOb);
  1037. obstacleList.push([[angle1, true], [angle2, false]]);
  1038. }
  1039. }
  1040. }
  1041.  
  1042. if (badAngles.length > 0) {
  1043. //NOTE: This is only bandaid wall code. It's not the best way to do it.
  1044. stupidList = this.addWall(stupidList, player[k]);
  1045. }
  1046.  
  1047. for (var i = 0; i < badAngles.length; i++) {
  1048. var angle1 = badAngles[i][0];
  1049. var angle2 = this.rangeToAngle(badAngles[i]);
  1050. stupidList.push([[angle1, true], [angle2, false], badAngles[i][2]]);
  1051. }
  1052.  
  1053. //stupidList.push([[45, true], [135, false]]);
  1054. //stupidList.push([[10, true], [200, false]]);
  1055.  
  1056. stupidList.sort(function(a, b){
  1057. window.log("Distance: " + a[2] + ", " + b[2]);
  1058. return a[2]-b[2];
  1059. });
  1060.  
  1061. window.log("Added random noob stuff.");
  1062.  
  1063. var sortedInterList = [];
  1064. var sortedObList = [];
  1065.  
  1066. for (var i = 0; i < stupidList.length; i++) {
  1067. window.log("Adding to sorted: " + stupidList[i][0][0] + ", " + stupidList[i][1][0]);
  1068. var tempList = this.addAngle(sortedInterList, stupidList[i]);
  1069.  
  1070. if (tempList.length === 0) {
  1071. window.log("MAYDAY IT'S HAPPENING!");
  1072. break;
  1073. } else {
  1074. sortedInterList = tempList;
  1075. }
  1076. }
  1077.  
  1078. for (var i = 0; i < obstacleList.length; i++) {
  1079. sortedObList = this.addAngle(sortedObList, obstacleList[i]);
  1080.  
  1081. if (sortedObList.length === 0) {
  1082. break;
  1083. }
  1084. }
  1085.  
  1086. var offsetI = 0;
  1087. var obOffsetI = 1;
  1088.  
  1089. if (sortedInterList.length > 0 && sortedInterList[0][1]) {
  1090. offsetI = 1;
  1091. }
  1092. if (sortedObList.length > 0 && sortedObList[0][1]) {
  1093. obOffsetI = 0;
  1094. }
  1095.  
  1096. var goodAngles = [];
  1097. var obstacleAngles = [];
  1098.  
  1099. for (var i = 0; i < sortedInterList.length; i += 2) {
  1100. var angle1 = sortedInterList[this.mod(i + offsetI, sortedInterList.length)][0];
  1101. var angle2 = sortedInterList[this.mod(i + 1 + offsetI, sortedInterList.length)][0];
  1102. var diff = this.mod(angle2 - angle1, 360);
  1103. goodAngles.push([angle1, diff]);
  1104. }
  1105.  
  1106. for (var i = 0; i < sortedObList.length; i += 2) {
  1107. var angle1 = sortedObList[this.mod(i + obOffsetI, sortedObList.length)][0];
  1108. var angle2 = sortedObList[this.mod(i + 1 + obOffsetI, sortedObList.length)][0];
  1109. var diff = this.mod(angle2 - angle1, 360);
  1110. obstacleAngles.push([angle1, diff]);
  1111. }
  1112.  
  1113. for (var i = 0; i < goodAngles.length; i++) {
  1114. var line1 = this.followAngle(goodAngles[i][0], player[k].x, player[k].y, 100 + player[k].size);
  1115. var line2 = this.followAngle(this.mod(goodAngles[i][0] + goodAngles[i][1], 360), player[k].x, player[k].y, 100 + player[k].size);
  1116. drawLine(player[k].x, player[k].y, line1[0], line1[1], 1);
  1117. drawLine(player[k].x, player[k].y, line2[0], line2[1], 1);
  1118.  
  1119. drawArc(line1[0], line1[1], line2[0], line2[1], player[k].x, player[k].y, 1);
  1120.  
  1121. //drawPoint(player[0].x, player[0].y, 2, "");
  1122.  
  1123. drawPoint(line1[0], line1[1], 0, "" + i + ": 0");
  1124. drawPoint(line2[0], line2[1], 0, "" + i + ": 1");
  1125. }
  1126.  
  1127. for (var i = 0; i < obstacleAngles.length; i++) {
  1128. var line1 = this.followAngle(obstacleAngles[i][0], player[k].x, player[k].y, 50 + player[k].size);
  1129. var line2 = this.followAngle(this.mod(obstacleAngles[i][0] + obstacleAngles[i][1], 360), player[k].x, player[k].y, 50 + player[k].size);
  1130. drawLine(player[k].x, player[k].y, line1[0], line1[1], 6);
  1131. drawLine(player[k].x, player[k].y, line2[0], line2[1], 6);
  1132.  
  1133. drawArc(line1[0], line1[1], line2[0], line2[1], player[k].x, player[k].y, 6);
  1134.  
  1135. //drawPoint(player[0].x, player[0].y, 2, "");
  1136.  
  1137. drawPoint(line1[0], line1[1], 0, "" + i + ": 0");
  1138. drawPoint(line2[0], line2[1], 0, "" + i + ": 1");
  1139. }
  1140.  
  1141. if (this.toggleFollow && goodAngles.length === 0) {
  1142. //This is the follow the mouse mode
  1143. var distance = this.computeDistance(player[k].x, player[k].y, tempPoint[0], tempPoint[1]);
  1144.  
  1145. var shiftedAngle = this.shiftAngle(obstacleAngles, this.getAngle(tempPoint[0], tempPoint[1], player[k].x, player[k].y), [0, 360]);
  1146.  
  1147. var destination = this.followAngle(shiftedAngle, player[k].x, player[k].y, distance);
  1148.  
  1149. destinationChoices = destination;
  1150. drawLine(player[k].x, player[k].y, destination[0], destination[1], 1);
  1151. //tempMoveX = destination[0];
  1152. //tempMoveY = destination[1];
  1153.  
  1154. } else if (goodAngles.length > 0) {
  1155. var bIndex = goodAngles[0];
  1156. var biggest = goodAngles[0][1];
  1157. for (var i = 1; i < goodAngles.length; i++) {
  1158. var size = goodAngles[i][1];
  1159. if (size > biggest) {
  1160. biggest = size;
  1161. bIndex = goodAngles[i];
  1162. }
  1163. }
  1164. var perfectAngle = this.mod(bIndex[0] + bIndex[1] / 2, 360);
  1165.  
  1166. perfectAngle = this.shiftAngle(obstacleAngles, perfectAngle, bIndex);
  1167.  
  1168. var line1 = this.followAngle(perfectAngle, player[k].x, player[k].y, verticalDistance());
  1169.  
  1170. destinationChoices = line1;
  1171. drawLine(player[k].x, player[k].y, line1[0], line1[1], 7);
  1172. //tempMoveX = line1[0];
  1173. //tempMoveY = line1[1];
  1174. } else if (badAngles.length > 0 && goodAngles.length === 0) {
  1175. //When there are enemies around but no good angles
  1176. //You're likely screwed. (This should never happen.)
  1177.  
  1178. window.log("Failed");
  1179. destinationChoices = [tempMoveX, tempMoveY];
  1180. /*var angleWeights = [] //Put weights on the angles according to enemy distance
  1181. for (var i = 0; i < allPossibleThreats.length; i++){
  1182. var dist = this.computeDistance(player[k].x, player[k].y, allPossibleThreats[i].x, allPossibleThreats[i].y);
  1183. var angle = this.getAngle(allPossibleThreats[i].x, allPossibleThreats[i].y, player[k].x, player[k].y);
  1184. angleWeights.push([angle,dist]);
  1185. }
  1186. var maxDist = 0;
  1187. var finalAngle = 0;
  1188. for (var i = 0; i < angleWeights.length; i++){
  1189. if (angleWeights[i][1] > maxDist){
  1190. maxDist = angleWeights[i][1];
  1191. finalAngle = this.mod(angleWeights[i][0] + 180, 360);
  1192. }
  1193. }
  1194. var line1 = this.followAngle(finalAngle,player[k].x,player[k].y,f.verticalDistance());
  1195. drawLine(player[k].x, player[k].y, line1[0], line1[1], 2);
  1196. destinationChoices.push(line1);*/
  1197. } else if (clusterAllFood.length > 0) {
  1198. for (var i = 0; i < clusterAllFood.length; i++) {
  1199. window.log("mefore: " + clusterAllFood[i][2]);
  1200. //This is the cost function. Higher is better.
  1201.  
  1202. var clusterAngle = this.getAngle(clusterAllFood[i][0], clusterAllFood[i][1], player[k].x, player[k].y);
  1203.  
  1204. clusterAllFood[i][2] = clusterAllFood[i][2] * 6 - this.computeDistance(clusterAllFood[i][0], clusterAllFood[i][1], player[k].x, player[k].y);
  1205. window.log("Current Value: " + clusterAllFood[i][2]);
  1206.  
  1207. //(goodAngles[bIndex][1] / 2 - (Math.abs(perfectAngle - clusterAngle)));
  1208.  
  1209. clusterAllFood[i][3] = clusterAngle;
  1210.  
  1211. drawPoint(clusterAllFood[i][0], clusterAllFood[i][1], 1, "");
  1212. window.log("After: " + clusterAllFood[i][2]);
  1213. }
  1214.  
  1215. var bestFoodI = 0;
  1216. var bestFood = clusterAllFood[0][2];
  1217. for (var i = 1; i < clusterAllFood.length; i++) {
  1218. if (bestFood < clusterAllFood[i][2]) {
  1219. bestFood = clusterAllFood[i][2];
  1220. bestFoodI = i;
  1221. }
  1222. }
  1223.  
  1224. window.log("Best Value: " + clusterAllFood[bestFoodI][2]);
  1225.  
  1226. var distance = this.computeDistance(player[k].x, player[k].y, clusterAllFood[bestFoodI][0], clusterAllFood[bestFoodI][1]);
  1227.  
  1228. var shiftedAngle = this.shiftAngle(obstacleAngles, this.getAngle(clusterAllFood[bestFoodI][0], clusterAllFood[bestFoodI][1], player[k].x, player[k].y), [0, 360]);
  1229.  
  1230. var destination = this.followAngle(shiftedAngle, player[k].x, player[k].y, distance);
  1231.  
  1232. destinationChoices = destination;
  1233. //tempMoveX = destination[0];
  1234. //tempMoveY = destination[1];
  1235. drawLine(player[k].x, player[k].y, destination[0], destination[1], 1);
  1236. } else {
  1237. //If there are no enemies around and no food to eat.
  1238. destinationChoices = [tempMoveX, tempMoveY];
  1239. }
  1240.  
  1241. drawPoint(tempPoint[0], tempPoint[1], tempPoint[2], "");
  1242. //drawPoint(tempPoint[0], tempPoint[1], tempPoint[2], "" + Math.floor(this.computeDistance(tempPoint[0], tempPoint[1], I, J)));
  1243. //drawLine(tempPoint[0], tempPoint[1], player[0].x, player[0].y, 6);
  1244. //window.log("Slope: " + slope(tempPoint[0], tempPoint[1], player[0].x, player[0].y) + " Angle: " + getAngle(tempPoint[0], tempPoint[1], player[0].x, player[0].y) + " Side: " + this.mod(getAngle(tempPoint[0], tempPoint[1], player[0].x, player[0].y) - 90, 360));
  1245. tempPoint[2] = 1;
  1246.  
  1247. window.log("Done working on blob: " + i);
  1248. }
  1249.  
  1250. //TODO: Find where to go based on destinationChoices.
  1251. /*var dangerFound = false;
  1252. for (var i = 0; i < destinationChoices.length; i++) {
  1253. if (destinationChoices[i][2]) {
  1254. dangerFound = true;
  1255. break;
  1256. }
  1257. }
  1258. destinationChoices.sort(function(a, b){return b[1] - a[1]});
  1259. if (dangerFound) {
  1260. for (var i = 0; i < destinationChoices.length; i++) {
  1261. if (destinationChoices[i][2]) {
  1262. tempMoveX = destinationChoices[i][0][0];
  1263. tempMoveY = destinationChoices[i][0][1];
  1264. break;
  1265. }
  1266. }
  1267. } else {
  1268. tempMoveX = destinationChoices.peek()[0][0];
  1269. tempMoveY = destinationChoices.peek()[0][1];
  1270. //window.log("Done " + tempMoveX + ", " + tempMoveY);
  1271. }*/
  1272. }
  1273. window.log("MOVING RIGHT NOW!");
  1274.  
  1275. window.log("______Never lied ever in my life.");
  1276.  
  1277. return destinationChoices;
  1278. }
  1279. };
  1280. };
  1281. window.botList.push(new AposBot());
  1282.  
  1283. if ( typeof window.updateBotList == 'function' ) {
  1284. window.updateBotList(); //This function might not exist yet.
  1285. } else {
  1286. window.log("The launcher is not yet started.");
  1287. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement