docs.html 10.3 KB
Newer Older
Hubert Denkmair's avatar
Hubert Denkmair committed
1
{% extends 'core/base.html' %}
nachtgold's avatar
nachtgold committed
2
3
4
5
6
7
8
{% load static %}

{% block earlycss %}
    <link rel="stylesheet" type="text/css" href="{% static "docs/github-markdown.css" %}" />
{% endblock %}

{% block css %}
9
    <link rel="stylesheet" type="text/css" href="{% static "core/highlight.js/styles/agate.css" %}" />
nachtgold's avatar
nachtgold committed
10
11
12
    <link rel="stylesheet" type="text/css" href="{% static "docs/docs.css" %}" />
{% endblock %}

13
14
15
16
17
{% block js%}
    <script src="{% static "core/highlight.js/highlight.pack.js" %}"></script>
    <script>hljs.initHighlightingOnLoad();</script>
{% endblock %}

nachtgold's avatar
nachtgold committed
18
19
20
21
22
23
24
25
26
27
{% block content %}

<div class="docs_container markdown-body">


<h1>Bot Documentation</h1>

<div id="docs_content">

<p>This is a brief overview of all usable functions within the bot logic.</p>
nachtgold's avatar
nachtgold committed
28
29
30
<p>
 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
nachtgold's avatar
nachtgold committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
 to frame.
 <p>The following Lua standard functions are allowed:</p>
 <p><a href="http://pgl.yoyo.org/luai/i/assert">assert</a>,
 <a href="http://pgl.yoyo.org/luai/i/print">print</a>,
 <a href="http://pgl.yoyo.org/luai/i/ipairs">ipairs</a>,
 <a href="http://pgl.yoyo.org/luai/i/error">error</a>,
 <a href="http://pgl.yoyo.org/luai/i/next">next</a>,
 <a href="http://pgl.yoyo.org/luai/i/pairs">pairs</a>,
 <a href="http://pgl.yoyo.org/luai/i/pcall">pcall</a>,
 <a href="http://pgl.yoyo.org/luai/i/select">select</a>,
 <a href="http://pgl.yoyo.org/luai/i/tonumber">tonumber</a>,
 <a href="http://pgl.yoyo.org/luai/i/tostring">tostring</a>,
 <a href="http://pgl.yoyo.org/luai/i/type">type</a>,
 <a href="http://pgl.yoyo.org/luai/i/unpack">unpack</a>,
 <a href="http://pgl.yoyo.org/luai/i/_VERSION">_VERSION</a>,
 <a href="http://pgl.yoyo.org/luai/i/xpcall">xpcall</a></p>
 <p>From the module <code>math</code> you can use:</p>
 <p><a href="http://pgl.yoyo.org/luai/i/math.abs">abs</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.acos">acos</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.asin">asin</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.atan">atan</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.atan2">atan2</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.ceil">ceil</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.cos">cos</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.cosh">cosh</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.deg">deg</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.exp">exp</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.floor">floor</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.fmod">fmod</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.frexp">frexp</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.huge">huge</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.ldexp">ldexp</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.log">log</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.log10">log10</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.max">max</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.min">min</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.modf">modf</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.pi">pi</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.pow">pow</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.rad">rad</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.random">random</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.randomseed">randomseed</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.sin">sin</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.sinh">sinh</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.sqrt">sqrt</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.tan">tan</a>,
 <a href="http://pgl.yoyo.org/luai/i/math.tanh">tanh</a></p>
 <p>From the module <code>os</code> you can use:</p>
 <p><a href="http://pgl.yoyo.org/luai/i/os.clock">clock</a>,
 <a href="http://pgl.yoyo.org/luai/i/os.difftime">difftime</a>,
 <a href="http://pgl.yoyo.org/luai/i/os.time">time</a></p>
 <p>From the module <code>table</code> you can use:</p>
 <a href="http://pgl.yoyo.org/luai/i/table.maxn">maxn</a>,
 <a href="http://pgl.yoyo.org/luai/i/table.insert">insert</a>,
 <a href="http://pgl.yoyo.org/luai/i/table.remove">remove</a>,
 <a href="http://pgl.yoyo.org/luai/i/table.sort">sort</a></p>
 <p>Every snake can describe itself with the following attributes of the global variable <code>self</code>:</p>
 <ul><li>id (number): internal identifier</li>
 <li>segment_radius (number): the size of the snake</li>
 <li>mass (number): the weight of the snake</li>
 <li>sight_radius (number): the field of view of the snake, which increases with the size of the snake</li>
 <li>consume_radius (number): the field of feed of the snake, which increases with the size of the snake</li>
 <li>max_step_angle (number): unknown definition</li>
 <li>start_frame (number): the game frame, when the snake was born</li>
 <li>current_frame (number): the current game frame</li>
 <li>speed (number): default speed is 1, but it can change if a snake is using boost</li>
 <li>food_consumed_natural (number): unknown definition</li>
 <li>food_consumed_hunted_self (number): unknown definition</li>
 <li>food_consumed_hunted_by_others (number): unknown definition</li>
 <li>colors ({number}): table of colors (default color is 0x0000FF00, maximum count is 100, set is available in <a href="#init">init</a>)</li>
 <li>face (number): not implemented yet (returns 0, set is available in <a href="#init">init</a>)</li>
 <li>logo (number): not implemented yet (returns 0, set is available in <a href="#init">init</a>)</li></ul></p>
nachtgold's avatar
nachtgold committed
103
104
105
106


<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
nachtgold's avatar
nachtgold committed
107
108
	<tr>
	<td class="name" nowrap><a href="#init">init ()</a></td>
nachtgold's avatar
nachtgold committed
109
	<td class="summary">This function is called upon creation of a bot
nachtgold's avatar
nachtgold committed
110
 Initialialize your environment here.</td>
nachtgold's avatar
nachtgold committed
111
112
	</tr>
	<tr>
113
	<td class="name" nowrap><a href="#findFood">findFood (max_distance, minimum_food_value)</a></td>
nachtgold's avatar
nachtgold committed
114
	<td class="summary">That function returns all food as list.</td>
115
116
117
	</tr>
	<tr>
	<td class="name" nowrap><a href="#findSegments">findSegments (max_distance, include_own)</a></td>
nachtgold's avatar
nachtgold committed
118
	<td class="summary">That function returns all segments of all snakes within a certain radius as list.</td>
nachtgold's avatar
nachtgold committed
119
	</tr>
120
121
	<tr>
	<td class="name" nowrap><a href="#log">log (message)</a></td>
nachtgold's avatar
nachtgold committed
122
123
124
125
126
	<td class="summary">That function sends messages to the development console.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#step">step ()</a></td>
	<td class="summary">That function is called each frame.</td>
127
	</tr>
nachtgold's avatar
nachtgold committed
128
129
130
131
132
133
134
</table>


    <h2><a name="Functions"></a>Functions</h2>

    <dl class="function">
    <dt>
nachtgold's avatar
nachtgold committed
135
136
    <a name = "init"></a>
    <strong>init ()</strong>
137
138
    </dt>
    <dd>
nachtgold's avatar
nachtgold committed
139
140
141
    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.
142
143
144
145
146
147
148
149






    <h4>Usage:</h4>
    <ul>
nachtgold's avatar
nachtgold committed
150
151
        <pre class="usage"><code class="lua"> <span class="keyword">function</span> init()
     self.colors = { <span class="number">0xFF0000</span>, <span class="number">0xFFBF00</span>, <span class="number">0x80FF00</span>, <span class="number">0x00FF40</span>, <span class="number">0x00FFFF</span>, <span class="number">0x0015FF</span>, <span class="number">0x8000FF</span> }
152
153
154
155
156
157
158
 <span class="keyword">end</span></code></pre>
    </ul>

</dd>
    <dt>
    <a name = "findFood"></a>
    <strong>findFood (max_distance, minimum_food_value)</strong>
nachtgold's avatar
nachtgold committed
159
160
    </dt>
    <dd>
nachtgold's avatar
nachtgold committed
161
    That function returns all food as list.
nachtgold's avatar
nachtgold committed
162
163
164
165


    <h4>Parameters:</h4>
    <ul>
166
167
168
169
170
        <li><code>max_distance</code>
         all food within the distance is included
        </li>
        <li><code>minimum_food_value</code>
         all lower food values are filtered (min: 0, max: unknown)
nachtgold's avatar
nachtgold committed
171
172
173
174
175
176
177
178
        </li>
    </ul>




    <h4>Usage:</h4>
    <ul>
179
180
181
182
183
        <pre class="usage"><code class="lua"> <span class="keyword">local</span> food = findFood(max_distance, <span class="number">0.8</span>)
 <span class="keyword">for</span> i, item <span class="keyword">in</span> food:<span class="global">pairs</span>() <span class="keyword">do</span>
   item.d <span class="comment">-- angle in radian
</span>   item.dist <span class="comment">-- distance
</span> <span class="keyword">end</span></code></pre>
nachtgold's avatar
nachtgold committed
184
185
186
187
    </ul>

</dd>
    <dt>
188
189
    <a name = "findSegments"></a>
    <strong>findSegments (max_distance, include_own)</strong>
nachtgold's avatar
nachtgold committed
190
191
    </dt>
    <dd>
nachtgold's avatar
nachtgold committed
192
    That function returns all segments of all snakes within a certain radius as list.
193
 All attributes of each item in the segments list are measured between the center of your head the the center of the item center.
nachtgold's avatar
nachtgold committed
194
195


196
197
198
199
200
201
202
203
204
    <h4>Parameters:</h4>
    <ul>
        <li><code>max_distance</code>
         all segements within that distance are included
        </li>
        <li><code>include_own</code>
         If true, your snake segments are included. Otherwise you get only enemy segments
        </li>
    </ul>
nachtgold's avatar
nachtgold committed
205
206
207
208
209
210




    <h4>Usage:</h4>
    <ul>
211
212
213
214
215
216
217
        <pre class="usage"><code class="lua"> <span class="keyword">local</span> segments = findSegments(<span class="number">50.0</span>, <span class="keyword">false</span>)
 <span class="keyword">for</span> i, item <span class="keyword">in</span> segments:<span class="global">pairs</span>() <span class="keyword">do</span>
   item.d <span class="comment">-- angle in radian
</span>   item.r <span class="comment">-- radius of the item
</span>   item.dist <span class="comment">-- distance
</span>   item.bot <span class="comment">-- id of the other snake
</span> <span class="keyword">end</span></code></pre>
nachtgold's avatar
nachtgold committed
218
219
    </ul>

220
221
222
223
224
225
</dd>
    <dt>
    <a name = "log"></a>
    <strong>log (message)</strong>
    </dt>
    <dd>
nachtgold's avatar
nachtgold committed
226
    That function sends messages to the development console.
227
228
229
230
231
232
233
234
235
236
237
238
239


    <h4>Parameters:</h4>
    <ul>
        <li><code>message</code>
         this string will be transfered to the console
        </li>
    </ul>





nachtgold's avatar
nachtgold committed
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
</dd>
    <dt>
    <a name = "step"></a>
    <strong>step ()</strong>
    </dt>
    <dd>
    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.



    <h4>Returns:</h4>
    <ol>

        new angle relative to the head direction
    </ol>



    <h4>Usage:</h4>
    <ul>
        <pre class="usage"><code class="lua"> <span class="keyword">function</span> step()
   <span class="keyword">return</span> <span class="number">0.005</span>
 <span class="keyword">end</span></code></pre>
    </ul>

nachtgold's avatar
nachtgold committed
268
269
270
271
272
273
274
275
276
</dd>
</dl>


</div> <!-- id="content" -->
</div> <!-- id="main" -->
</div> <!-- id="container" -->

{% endblock %}