docs.html 5.48 KB
Newer Older
Hubert Denkmair's avatar
Hubert Denkmair committed
1
{% extends 'core/base.html' %}
nachtgold's avatar
nachtgold committed
2
3
{% load static %}

Hubert Denkmair's avatar
Hubert Denkmair committed
4
5
6
7
{% block title %}
    <title>Docs - Schlangenprogrammiernacht 2018</title>
{% endblock %}

nachtgold's avatar
nachtgold committed
8
9
10
11
12
{% block earlycss %}
    <link rel="stylesheet" type="text/css" href="{% static "docs/github-markdown.css" %}" />
{% endblock %}

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

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

nachtgold's avatar
nachtgold committed
22
23
24
25
26
27
28
29
30
31
{% 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
32
33
34
35
<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
36
37
38
39
40


<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
	<tr>
41
42
	<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
43
44
45
46
47
	</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
48
49
	</tr>
	<tr>
50
51
52
53
54
55
	<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
56
	</tr>
57
58
59
60
	<tr>
	<td class="name" nowrap><a href="#log">log (message)</a></td>
	<td class="summary">That method sends messages to the development console.</td>
	</tr>
nachtgold's avatar
nachtgold committed
61
62
63
64
65
66
67
</table>


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

    <dl class="function">
    <dt>
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
    <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
90
   <span class="keyword">return</span> <span class="number">0.005</span>
91
92
93
 <span class="keyword">end</span></code></pre>
    </ul>

nachtgold's avatar
nachtgold committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
</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







110
111
112
113
</dd>
    <dt>
    <a name = "findFood"></a>
    <strong>findFood (max_distance, minimum_food_value)</strong>
nachtgold's avatar
nachtgold committed
114
115
    </dt>
    <dd>
116
    That method returns all food as list.
nachtgold's avatar
nachtgold committed
117
118
119
120


    <h4>Parameters:</h4>
    <ul>
121
122
123
124
125
        <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
126
127
128
129
130
131
132
133
        </li>
    </ul>




    <h4>Usage:</h4>
    <ul>
134
135
136
137
138
        <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
139
140
141
142
    </ul>

</dd>
    <dt>
143
144
    <a name = "findSegments"></a>
    <strong>findSegments (max_distance, include_own)</strong>
nachtgold's avatar
nachtgold committed
145
146
    </dt>
    <dd>
147
148
    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
149
150


151
152
153
154
155
156
157
158
159
    <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
160
161
162
163
164
165




    <h4>Usage:</h4>
    <ul>
166
167
168
169
170
171
172
        <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
173
174
    </ul>

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
</dd>
    <dt>
    <a name = "log"></a>
    <strong>log (message)</strong>
    </dt>
    <dd>
    That method sends messages to the development console.


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





nachtgold's avatar
nachtgold committed
195
196
197
198
199
200
201
202
203
</dd>
</dl>


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

{% endblock %}