{% 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.

Lua global namespace

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:

Variable within selfTypeDescription
idnumberinternal identifier
segment_radiusnumberthe size of the snake
massnumberthe weight of the snake
sight_radiusnumberthe field of view of the snake, which increases with the size of the snake
consume_radiusnumberthe field of feed of the snake, which increases with the size of the snake
max_step_anglenumberunknown definition
start_framenumberthe game frame, when the snake was born
current_framenumberthe current game frame
speednumberdefault speed is 1, but it can change if a snake is using boost
food_consumed_naturalnumberunknown definition
food_consumed_hunted_selfnumberunknown definition
food_consumed_hunted_by_othersnumberunknown definition
colors{number}table of colors (default color is 0x0000FF00, maximum count is 100, set is available in init)
facenumbernot implemented yet (returns 0, set is available in init)
logonumbernot implemented yet (returns 0, set is available in init)

Functions

Function name Description
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 %}