docs.html 5.48 KB
Newer Older
nachtgold's avatar
nachtgold committed
1
2
3
4
5

{% extends 'base.html' %}

{% load static %}

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

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

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

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

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


<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
	<tr>
43
44
	<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
45
46
47
48
49
	</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
50
51
	</tr>
	<tr>
52
53
54
55
56
57
	<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
58
	</tr>
59
60
61
62
	<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
63
64
65
66
67
68
69
</table>


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

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

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







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


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




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

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


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




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

177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
</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
197
198
199
200
201
202
203
204
205
</dd>
</dl>


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

{% endblock %}