Welcome to the AI documentation

If your not sure how you got here, go back to playing

To submit an AI, DM me (sojs) a link through the discord to either a repl or repo.

Im sorry if its hard to understand. I dislike writing documentation.

Parent Function


      var your_ai = (snake, roomkey){
        //the AI is untestable untill in production
        var snakehead = snake[0];
        //AI code. Edit snake direction with
        rooms[roomkey].snakes[snake.id].dir = 1;
        // 1 is up (lowers snake Y pos - snakehead[1])
        // 2 is right (increase snake X pos - snakeHead[0])
        // 3 is down (increases snake Y)
        // 4 is left (lowers snake X)
        //changing snake speed
        rooms[roomley].snakes[snake.id].speed = 1 || 2;
        //1 is normal speed. 2 is double as fast (skips every other block)
      }
    
    

Analyzing block position


      rooms[roomkey].blocks.forEach((block)=>{
        var blockX = block[0];
        var blockY = block[1];
        //checking against snakeHead
        var snakeHead = snake[0];
        if(blockX == snakeHead[0]){
          //same X
        }
        if(blockY == snakeHead[1]){
          //same Y
        }
        // etc., etc. Change direction based off of whether the snake will run into a block or not.
      })
    
    

Finding other snakes


      var snakesArray = json2array(rooms[roomkey].snakes);
      snakesArray.forEach((snakeBlock)=>{
        var blockX = snakeBlock[0];
        var blockY = snakeBlock[1];
        //checking against snakeHead
        var snakeHead = snake[0];
        if(blockX == snakeHead[0]){
          //same X
        }
        if(blockY == snakeHead[1]){
          //same Y
        }
      })
    
    

Apple position


      var applePos = rooms[roomkey].apple;
      var appleX = applePos[0];
      var appleY = apple[1];
    

Use these checks to analyze what to do next. For example, dodge either left or right if a block or snake block is in front, otherwise, move towards apple

Be warned that coding an AI or even understanding the code above takes a large quantity of coding experience. Send me a link to a code Repo or Repl and you might get featured

Misc

Checking room type


      rooms[roomkey].type = "normal" || 'redgreen' || 'small' || 'fog' || 'tag';
      //room type affects the rules that the bot has to constrain to. To fully understand each room type, play one of them and read the "how to play".
    

Checking if snake should freeze in redgreen mod


      //color of light is stored in the following:
      rooms[roomkey].color = "yellow" || 'red' || 'green';
      // green you can move around, yellow will turn to red, red you die if you move.
      //stop moving by changing snake frozen attribute;
      rooms[roomkey].frozen = true || false;