{% extends 'core/base.html' %} {% load static %} {% block earlycss %} {% endblock %} {% block css %} {% endblock %} {% block js%} {% endblock %} {% block content %}

Bot Documentation

This is a brief overview of all usable functions within the bot logic.

Every bot is allowed to store 100MB within the global namespace and the data persists until the bot dies. So the bot can save data from frame to frame.

The following Lua standard functions are allowed:

assert, print, ipairs, error, next, pairs, pcall, select, tonumber, tostring, type, unpack, _VERSION, xpcall

From the module math you can use:

abs, acos, asin, atan, atan2, ceil, cos, cosh, deg, exp, floor, fmod, frexp, huge, ldexp, log, log10, max, min, modf, pi, pow, rad, random, randomseed, sin, sinh, sqrt, tan, tanh

From the module os you can use:

clock, difftime, time

From the module table you can use:

maxn, insert, remove, sort

Every snake can describe itself with the following attributes of the global variable self:

Functions

init () This function is called upon creation of a bot Initialialize your environment here.
findFood (max_distance, minimum_food_value) That function returns all food as list.
findSegments (max_distance, include_own) That function returns all segments of all snakes within a certain radius as list.
log (message) That function sends messages to the development console.
step () That function is called each frame.

Functions

init ()
This function is called upon creation of a bot Initialialize your environment here. You can also access the "self" module here and, e.g. set your snake's colors.

Usage:

     function init()
         self.colors = { 0xFF0000, 0xFFBF00, 0x80FF00, 0x00FF40, 0x00FFFF, 0x0015FF, 0x8000FF }
     end
findFood (max_distance, minimum_food_value)
That function returns all food as list.

Parameters:

  • max_distance all food within the distance is included
  • minimum_food_value all lower food values are filtered (min: 0, max: unknown)

Usage:

     local food = findFood(max_distance, 0.8)
     for i, item in food:pairs() do
       item.d -- angle in radian
       item.dist -- distance
     end
findSegments (max_distance, include_own)
That function returns all segments of all snakes within a certain radius as list. All attributes of each item in the segments list are measured between the center of your head the the center of the item center.

Parameters:

  • max_distance all segements within that distance are included
  • include_own If true, your snake segments are included. Otherwise you get only enemy segments

Usage:

     local segments = findSegments(50.0, false)
     for i, item in segments:pairs() do
       item.d -- angle in radian
       item.r -- radius of the item
       item.dist -- distance
       item.bot -- id of the other snake
     end
log (message)
That function sends messages to the development console.

Parameters:

  • message this string will be transfered to the console
step ()
That function is called each frame. Here you can implement you bot logic. The return value must be an radiant angle. A negative angle means turn left and a positive angle means turn right. With 0, the snake keeps its direction.

Returns:

    new angle relative to the head direction

Usage:

     function step()
       return 0.005
     end
{% endblock %}