Giter Club home page Giter Club logo

slither.io-bot's Introduction

Project Update:

Project now permanently discontinued as the original authors have lost interest in the project however continued development from fellow developers is not to be discouraged, if you wish so. An improved version of this bot (improved fork) is and can be found here but both have been discontinued.

Slither.io bot

Just for fun and AI. Written in Javascript, this is a project which the aim is to make a computer play against humans inside a human-driven game, which is in this case Slither.io. The goal is simple - try and make the snake live and get as long as possible.

Gitter

Table of Contents

Installation instructions

NOTE: these instructions are for installing the bot at a production-ready, fully working and a fully tested state, which is recommended. For the latest bleeding edge code, which may not be fully tested, refer to the bot.user.js file in the current default develop branch as the instructions below refer the bot file in the master branch.

Interactive tutorial

http://slither.jlynx.net/

Visual tutorial

https://www.youtube.com/watch?v=d7mkAgQNuCA - Created by http://slither.jlynx.net/

https://youtu.be/mlEKp-ZAi7w - Created by http://slithere.com/

https://youtu.be/QF9JBMi-fLo?t=38s - Created by SeppeTutorials

https://youtu.be/IpsAazbVIcw - Created by TheFlyingPlatypus

Text tutorial

If you are on chrome, download the TamperMonkey extension.

On other browsers, use the GreaseMonkey extension.

Once installed, click on this, and choose Install.

Go to slither.io, and enjoy !

Hotkeys

Key Result
T / Right Click Bot enabled/disabled
O Mobile rendering - Try this if you experience lag
A/S Radius multiplier
D Quick radius change - "approach" and "avoid" mode
I Auto respawn
G Leaderboard overlay
Y Visual debugging
U Log debugging
H Overlays
B Background Change
Mouse wheel Zoom in/out
Z Reset zoom
ESC Quick respawn
Q Quit to menu

Contributing

Please refer to the guidelines for contributing for all the information you need.

Check the wiki for additional information

NOTE : For existing collaborators, please refer to the DEVELOPER.md file.

Documentation

Documentation Status

The online documentation is maintained in the /docs directory.

Authors

Ermiya Eskandary & Théophile Cailliau (ErmiyaEskandary & FliiFe)

Started as a collaborative and fun project between me and FliiFe on 2016/04/20, with this :

Slither.io bot could be cool

License

Licensed under the Mozilla Public License, v. 2.0

Read LICENSE.md for more info.

slither.io-bot's People

Contributors

cardridge avatar chadski avatar chancity avatar chzawist avatar clemens-tolboom avatar defimatt avatar dracco1993 avatar ermiyaeskandary avatar evanito avatar fliife avatar j-c-m avatar jlynx avatar joetex avatar k00sklust avatar kakol20 avatar kmatheussen avatar ksofiyuk avatar salvationdk avatar sp4ce avatar tjorim avatar tom-n96 avatar vasinwr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slither.io-bot's Issues

Sharing allowance ?

its laggy when you fix?, i'm mod of slithere.com can we share this bot too?

Food cluster calculation

Cluster food together that is within one snake radius from the cluster center and calculate distance from that to optimize calculations and fix priorities.

Todo list:

  • Calculate our snake's width
  • Use width to make clusters
  • Add value to clusters and do calculations on clusters as a whole.
  • Have bot target clusters

Okay here's a mockup for how I would do this:

Algorithm to check if point is within circle: (x - center_x)^2 + (y - center_y)^2 < pickup_radius^2

  1. Start with all of the points in the unassigned group.
  2. Pick one point and look at all the others in the unassigned group and see whether they are within 1 snake pickup radius (I think this is bigger than the visual radius.)
    1. If yes, start a group, and continue on with all the other points to see if they fit in this group (based on starting point), and if they fit in, move them from the unassigned group into this new one.
    2. But, if no point matches the criteria for a starting point, use the starting point as a cluster of one.
  3. At the end we will have grouped the points by radius.
  4. Sum the sizes of the food in the cluster.
  5. Find the distance of the cluster by finding the weighted center of the cluster and check distance from there.

After this, I think we should calculate clusters separately from calculating which one to target, clustering only once per few seconds.

Alternatively, we can base our code of off Apostolique's bot:

window.clusterFood = function(foodList, pickupRadius) {
        var clusters = [];
        var addedCluster = false;
        //1: x
        //2: y
        //3: size or value
        //4: Angle, not set here.
        for (var i = 0; i < foodList.length; i++) {
            for (var j = 0; j < clusters.length; j++) {
                if (window.getDistance(foodList[i][0], foodList[i][1], clusters[j][0], clusters[j][1]) < pickupRadius) {
                    clusters[j][0] = (foodList[i][0] + clusters[j][0]) / 2;
                    clusters[j][1] = (foodList[i][1] + clusters[j][1]) / 2;
                    clusters[j][2] += foodList[i][2];
                    addedCluster = true;
                    break;
                }
            }
            if (!addedCluster) {
                clusters.push([foodList[i][0], foodList[i][1], foodList[i][2], 0]);
            }
            addedCluster = false;
        }
        return clusters;
    };

Add persistent settings on home screen

Todo list:

  • Bot should have settings such as
    • To enable/disable console logging
    • Preferred graphics quality
    • Which distance formula to use when we implement the new one
    • Which name to use
    • Whether or not to "autorespawn"
  • We need the bot to not instantly join the game the second the page loads.
  • Settings should be saved locally so they are persistent.
  • Settings should be edited visually on the main screen or offer clear controls.
  • Saving code implemented
  • Loading code implemented

Automatically unblock skins

This code unlocks skins without needing a share on twitter or facebook.
window.localStorage.setItem("edttsg", "1");

Check FPS and auto change graphics

  • Add FPS check every several seconds.
  • When below ~20, switch to low graphics settings on the fly and disable unneeded features. Maybe slow down the bot clock a few milliseconds.
  • When above ~40, switch back (gap is needed between the two triggers so it doesn't turn on and off madly.) Or maybe have multiple intermediate graphics levels.
  • Be able to toggle this function.

Slight Offset

Slight offset when converting from canvas to screen so issue lies in :

window.screenToCanvas = function(x, y) {
    var canvasX = window.csc * x * window.canvasRatio[0] - window.csc * parseInt(window.mc.style.left);
    var canvasY = window.csc * y * window.canvasRatio[1] - window.csc * parseInt(window.mc.style.top);
    return [canvasX, canvasY];
};

This small offset causes issues with the visual element and other things. Variables which stores offset is unknown.

Won't Start

So I will have the user script install and go to slither.io and the bot won't start. Some times it can 5 - 6 reloads for the bot to start
INFO
Chrome
0.6.0
I have no idea what caused it

Change prey hunting range

Okay, so at a certain range, the snake will lose more than it gains when hunting down prey.

  • Find the length lost per distance when boosting
  • Use that measure to see if it is worth it to go after it.

You know, instead of just trying to sprint across the map.

Collision radius issue

It looks like zooming out in the game (with the bot and collision detection enabled),
increases the radius of detection. I'm not sure if this behaviour is intended.

Below are two screenshots of the problem, the first one at the standard zoom level.
Sorry for the bad quality, if necessary I can provide better ones tomorrow.
standard zoom
zoomed out

Bot lags

Am I the only one to notice huge lags ? It's fine in the beggining, and gets worse over time

Prioritize big food

Bot should prioritize big food since it is better in every way.

  • Maybe half its distance when calculating nearest food to give bot a preference?

But first, we need to be able to discern big food from the rest.

Bot randomly respawns

I have noticed that the bot will occasionally just start over. No death, no main menu screen, it just restarts.

Add collision prevention

Bot should treat snake bodies and the map border as obstacles, but treat heads as active threats.

Maybe have a mimicry form of self defense?

Gitter

I think we should use gitter so that anyone can join and voice what they think about the bot and also we will not have the invite issues of slack

Make the bot turn in a perfect circle as defense

When enemies are near, we could just turn in a perfect circle until they give up. This could prove successful as we can go in a perfect circle using programming but they can't - and eventually they will give up.

Not really an issue but I have no way of communicating so.....

This will build the snake bodies in the low rendering mode, it may be of use. I would really like to communicate with you guys on slack or skype...something.

window.hmm = function (){
    var b = window.mc.getContext("2d");
    for (h = window.snakes.length - 1; 0 <= h; h--) {

    if (c = window.snakes[h], c.iiv) {
        f = c.xx + c.fx;
        w = c.yy + c.fy;
        px = f;
        py = w;
        E = c.ehang;
        var t = c.sc,
            x = 29 * t,
            D = c.cfl;
        e = c.pts[c.pts.length - 1];
        if (1 == render_mode) {
            b.save();
            b.beginPath();
            b.moveTo(window.mww2 + (px - window.view_xx) * window.gsc, window.mhh2 + (py - window.view_yy) * window.gsc);
            z = !1;
            for (var y = c.pts.length - 1; 0 <= y; y--) {
                e = c.pts[y];
                lpx = px;
                lpy = py;
                px = e.xx;
                py = e.yy;
                var B = e.fx,
                    q = e.fy;
                0 < D && (px += B, py += q, lax = ax, lay = ay, ax = (px + lpx) / 2, ay = (py + lpy) / 2, z || (lax = ax, lay = ay), 1 > D && (u = 1 - D, lpx += (lax - lpx) * u, lpy += (lay - lpy) * u, ax += (lax - ax) * u, ay += (lay - ay) * u), z ? D-- : D -= c.chl + c.fchl, z ? b.quadraticCurveTo(window.mww2 + (lpx - window.view_xx) * window.gsc, window.mhh2 + (lpy - window.view_yy) * window.gsc,
                    window.mww2 + (ax - window.view_xx) * window.gsc, window.mhh2 + (ay - view_yy) * window.gsc) : (b.lineTo(window.mww2 + (ax - window.view_xx) * window.gsc, window.mhh2 + (ay - window.view_yy) * window.gsc), z = !0));
            }
            b.save();
            b.lineJoin = "round";
            b.lineCap = "round";
            is_firefox ? (c.sp > c.fsp && (y = c.alive_amt * (1 - c.dead_amt) * Math.max(0, Math.min(1, (c.sp - c.ssp) / (c.msp - c.ssp))), b.save(), b.strokeStyle = c.cs, b.globalAlpha = .3 * y, b.lineWidth = (x + 6) * window.gsc, b.stroke(), b.lineWidth = (x + 9) * window.gsc, b.stroke(), b.lineWidth = (x + 12) * window.gsc, b.stroke(), b.restore()), b.globalAlpha = 1 * c.alive_amt * (1 - c.dead_amt), b.strokeStyle = "#000000", b.lineWidth = (x + 5) *
               window.gsc) : (c.sp > c.fsp && (y = c.alive_amt * (1 - c.dead_amt) * Math.max(0, Math.min(1, (c.sp - c.ssp) / (c.msp - c.ssp))), b.save(), b.lineWidth = (x - 2) * window.gsc, b.shadowBlur = 30 * window.gsc, b.shadowColor = "rgba(" + c.rr + "," + c.gg + "," + c.bb + ", " + Math.round(1E4 * y) / 1E4 + ")", b.stroke(), b.stroke(), b.restore()), b.globalAlpha = .4 * c.alive_amt * (1 - c.dead_amt), b.strokeStyle = "#000000", b.lineWidth = (x + 5) * window.gsc, b.stroke(), b.strokeStyle = c.cs, b.lineWidth = x * window.gsc, b.strokeStyle = "#000000", b.globalAlpha = 1 * c.alive_amt * (1 - c.dead_amt));
            b.stroke();
            b.strokeStyle = c.cs;
            b.globalAlpha =
                .8 * c.alive_amt * (1 - c.dead_amt);
            b.lineWidth = x * window.gsc;
            b.stroke();
            b.restore();
            b.strokeStyle = c.cs;
            c.dead && (q = (.5 + .5 * Math.abs(Math.sin(5 * Math.PI * c.dead_amt))) * Math.sin(Math.PI * c.dead_amt), b.save(), b.lineJoin = "round", b.lineCap = "round", b.globalCompositeOperation = "lighter", b.lineWidth = (x - 3) * window.gsc, b.globalAlpha = q, b.strokeStyle = "#FFCC99", b.stroke(), b.restore());
            b.restore()
        }
        }
    }
};

[Suggestions] Two mouse buttons - disable/enable bot - "Fast Boost"

Hello

  1. Please restore the auto startup play game.
  2. Replace or add options: "Defense mode - bot turns around in a perfect circle"
    do not turn in a perfect circle always head protrudes - better add "auto distance" from others (and prevents collisions).
  3. To facilitate enable fast switching bot disable / enable the right mouse button - not key "T" (replace - key / button).
  4. "Fast Boost" - Always possible under the left mouse button (independently / regardless - bot enabled).
  5. Save / Remember selected skin + options.

I'm sorry for my language english is not good. Thank you in advance if possible to change the.
Thank you for your work. Regards. GL&HF ;)

Bot gets stuck circling food

Bot gets stuck trying to eat a single piece.

Potential solutions:

  • Ignore food closer than n units to the left or right (Do we have currentBotAngle detection?) since these food will most likely be within our turning radius.
  • Solve issue #13
  • If we solve #23 then the bot would be very unlikely to get stuck on one.

I started to work on collision...heres what i have

window.checkCollision = function() {
    var isTrue = false;
    for (var snake in window.snakes){
        if (window.snakes[snake].nk != window.snake.nk) {
            for (var y = window.snakes[snake].pts.length - 1; 0 <= y; y--){
                if(!window.snakes[snake].pts[y].dying) {
                    var enemyCoordinates = window.mapToMouse(window.snakes[snake].pts[y].xx, window.snakes[snake].pts[y].yy);
                    enemyCoordinates = window.mouseToScreen(enemyCoordinates[0], enemyCoordinates[1]);
                    enemyCoordinates = window.screenToCanvas(enemyCoordinates[0], enemyCoordinates[1]);

                    if (window.lineIntersect({xx: enemyCoordinates[0], yy: enemyCoordinates[1]}, 13*window.snakes[snake].sc*getScale())){
                        isTrue = true;
                    }
                }
            }
        }
    }

    return isTrue;
};

window.lineIntersect = function(circleMiddle, circleRadius){
    var A = window.mapToMouse(window.getX(),window.getY());
    A = window.mouseToScreen(A[0], A[1]);
    A = window.screenToCanvas(A[0], A[1]);

    var B = window.goalCoordinates;
    B = window.mouseToScreen(B[0], B[1]);
    B = window.screenToCanvas(B[0], B[1]);


    var C = circleMiddle;

    var Ax = A[0];
    var Ay = A[1];

    var Bx = B[0];
    var By = B[1];

    var Cx = C.xx;
    var Cy = C.yy;


    //console.log(Ax + ", " + Ay)
    //console.log(Bx + ", " + By)
    //console.log(Cx + ", " + Cy)
    // compute the euclidean distance between A and B
    var LAB = Math.sqrt(Math.pow(Bx-Ax, 2) + Math.pow(By-Ay,2))

    // compute the direction vector D from A to B
    var Dx = (Bx-Ax)/LAB
    var Dy = (By-Ay)/LAB

    // Now the line equation is x = Dx*t + Ax, y = Dy*t + Ay with 0 <= t <= 1.

    // compute the value t of the closest point to the circle center (Cx, Cy)
    var t = Dx*(Cx-Ax) + Dy*(Cy-Ay)    

    // This is the projection of C on the line from A to B.

    // compute the coordinates of the point E on line and closest to C
    var Ex = t*Dx+Ax
    var Ey = t*Dy+Ay

    // compute the euclidean distance from E to C
    LEC = Math.sqrt(Math.pow(Ex-Cx,2) + Math.pow(Ey-Cy,2))

    //console.log(LEC + ",  > " + window.csc * circleRadius)
    // test if the line intersects the circle
    if( LEC < window.csc * circleRadius){
        return true;
        // compute distance from t to circle intersection point
        dt = Math.sqrt(Math.pow(R,2) - Math.pow(LEC,2))

        // compute first intersection point
        Fx = (t-dt)*Dx + Ax
        Fy = (t-dt)*Dy + Ay

        // compute second intersection point
        Gx = (t+dt)*Dx + Ax
        Gy = (t+dt)*Dy + Ay

    // else test if the line is tangent to circle
    } else if( LEC == circleRadius) {
        return false;
    }else{
        return false;
    }
};

Error on start

Error in event handler for runtime.onMessage: TypeError: h is not a function
    at Object.forcedLoad

Angular movement

Move based on angles instead of rectilinear (cartesian) coordinates.

So if snake is [0,0] and food is relative [3,4]: convert the rectangular (cartesian) coordinates to polar using arccos(3/sqroot( 3^2 + 4^2)) to return the angle theta of the food relative to the snake.

The pythagorean theorem is part of the equation
var distance = Math.sqrt(Math.pow(xDistance, 2) + Math.pow(yDistance, 2));
var angle = 1/(Match.cos(xDistance / window.distance));

Todo list:

  • Calculate angle from bot of each food
  • Be able to move in direction of an angle
  • Implement this as replacement

Kill count

Can we make a count of how many kills we cause?

Perhaps add that to the leaderboard of #38 ?

Further prioritize bigger food (at a loss of CPU cycles)

What do you guys think of:

  • We currently use (distance / size) to calculate priority
  • Instead, we use (distance / size^2) in order to further prioritize larger food. I tested this and it is much better at not just ignoring the huge food from a dead snake.
  • Perhaps have this feature included with a "high" setting?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.