docs.html 4.94 KB
Newer Older
nachtgold's avatar
nachtgold committed
1
2
3
4
5
6
7
8
9
10

{% extends 'base.html' %}

{% load static %}

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

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

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

nachtgold's avatar
nachtgold committed
20
21
22
23
24
25
26
27
28
29
{% 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
30
31
32
33
<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
 to frame.</p>
nachtgold's avatar
nachtgold committed
34
35
36
37
38


<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
	<tr>
39
40
	<td class="name" nowrap><a href="#step">step ()</a></td>
	<td class="summary">That method is called each frame.</td>
nachtgold's avatar
nachtgold committed
41
42
43
44
45
	</tr>
	<tr>
	<td class="name" nowrap><a href="#init">init ()</a></td>
	<td class="summary">This method is called upon creation of a bot
 Initialialize your environment here.</td>
nachtgold's avatar
nachtgold committed
46
47
	</tr>
	<tr>
48
49
50
51
52
53
	<td class="name" nowrap><a href="#findFood">findFood (max_distance, minimum_food_value)</a></td>
	<td class="summary">That method returns all food as list.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#findSegments">findSegments (max_distance, include_own)</a></td>
	<td class="summary">That method returns all segments of all snakes within a certain radius as list.</td>
nachtgold's avatar
nachtgold committed
54
55
56
57
58
59
60
61
	</tr>
</table>


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

    <dl class="function">
    <dt>
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
    <a name = "step"></a>
    <strong>step ()</strong>
    </dt>
    <dd>
    That method 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()
nachtgold's avatar
nachtgold committed
84
   <span class="keyword">return</span> <span class="number">0.005</span>
85
86
87
 <span class="keyword">end</span></code></pre>
    </ul>

nachtgold's avatar
nachtgold committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
</dd>
    <dt>
    <a name = "init"></a>
    <strong>init ()</strong>
    </dt>
    <dd>
    This method is called upon creation of a bot
 Initialialize your environment here.
 you can also access the "self" object here and, e.g. set your snake's colors







104
105
106
107
</dd>
    <dt>
    <a name = "findFood"></a>
    <strong>findFood (max_distance, minimum_food_value)</strong>
nachtgold's avatar
nachtgold committed
108
109
    </dt>
    <dd>
110
    That method returns all food as list.
nachtgold's avatar
nachtgold committed
111
112
113
114


    <h4>Parameters:</h4>
    <ul>
115
116
117
118
119
        <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
120
121
122
123
124
125
126
127
        </li>
    </ul>




    <h4>Usage:</h4>
    <ul>
128
129
130
131
132
        <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
133
134
135
136
    </ul>

</dd>
    <dt>
137
138
    <a name = "findSegments"></a>
    <strong>findSegments (max_distance, include_own)</strong>
nachtgold's avatar
nachtgold committed
139
140
    </dt>
    <dd>
141
142
    That method 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.
nachtgold's avatar
nachtgold committed
143
144


145
146
147
148
149
150
151
152
153
    <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
154
155
156
157
158
159




    <h4>Usage:</h4>
    <ul>
160
161
162
163
164
165
166
        <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
167
168
169
170
171
172
173
174
175
176
177
    </ul>

</dd>
</dl>


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

{% endblock %}