Commit 27f0aae5 authored by nachtgold's avatar nachtgold Committed by Hubert Denkmair
Browse files

doc is improved according to the current demo bot

parent 3f8b9d45
--- This is a brief overview of all usable functions within the bot logic. --- This is a brief overview of all usable functions within the bot logic.
--- Main cycle --- That method is called each frame.
-- Run is executed each frame. -- Here you can implement you bot logic. The return value must be an radiant angle.
-- @param current_heading first parameter -- A negative angle means turn left and a positive angle
-- @usage function run(current_heading) -- means turn right. With 0, the snake keeps its direction.
-- return (current_heading + 45) % 360 -- @return new angle relative to the head direction
-- @usage function step()
-- return 45
-- end -- end
function run(current_heading) function step()
x = 2 return 45
for n=1,x do
current_heading = current_heading + api:get_rotation_speed()
end
return current_heading
end end
--- API #1 --- That method returns all food as list.
-- @return allowed rotation speed by the game engine -- @param max_distance all food within the distance is included
-- @usage local x = current_heading + api:get_rotation_speed() -- @param minimum_food_value all lower food values are filtered (min: 0, max: unknown)
function api:get_rotation_speed() -- @usage local food = findFood(max_distance, 0.8)
-- for i, item in food:pairs() do
-- item.d -- angle in radian
-- item.dist -- distance
-- end
function findFood(max_distance, minimum_food_value)
end
--- 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.
-- @param max_distance all segements within that distance are included
-- @param 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
function findSegments(max_distance, include_own)
end end
\ No newline at end of file
...@@ -27,13 +27,16 @@ ...@@ -27,13 +27,16 @@
<h2><a href="#Functions">Functions</a></h2> <h2><a href="#Functions">Functions</a></h2>
<table class="function_list"> <table class="function_list">
<tr> <tr>
<td class="name" nowrap><a href="#run">run (current_heading)</a></td> <td class="name" nowrap><a href="#step">step ()</a></td>
<td class="summary">Main cycle <td class="summary">That method is called each frame.</td>
Run is executed each frame.</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#api:get_rotation_speed">api:get_rotation_speed ()</a></td> <td class="name" nowrap><a href="#findFood">findFood (max_distance, minimum_food_value)</a></td>
<td class="summary">API #1</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>
</tr> </tr>
</table> </table>
...@@ -42,18 +45,48 @@ ...@@ -42,18 +45,48 @@
<dl class="function"> <dl class="function">
<dt> <dt>
<a name = "run"></a> <a name = "step"></a>
<strong>run (current_heading)</strong> <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()
<span class="keyword">return</span> <span class="number">45</span>
<span class="keyword">end</span></code></pre>
</ul>
</dd>
<dt>
<a name = "findFood"></a>
<strong>findFood (max_distance, minimum_food_value)</strong>
</dt> </dt>
<dd> <dd>
Main cycle That method returns all food as list.
Run is executed each frame.
<h4>Parameters:</h4> <h4>Parameters:</h4>
<ul> <ul>
<li><code>current_heading</code> <li><code>max_distance</code>
first parameter all food within the distance is included
</li>
<li><code>minimum_food_value</code>
all lower food values are filtered (min: 0, max: unknown)
</li> </li>
</ul> </ul>
...@@ -62,32 +95,45 @@ ...@@ -62,32 +95,45 @@
<h4>Usage:</h4> <h4>Usage:</h4>
<ul> <ul>
<pre class="usage"><code class="lua"> <span class="keyword">function</span> run(current_heading) <pre class="usage"><code class="lua"> <span class="keyword">local</span> food = findFood(max_distance, <span class="number">0.8</span>)
<span class="keyword">return</span> (current_heading + <span class="number">45</span>) % <span class="number">360</span> <span class="keyword">for</span> i, item <span class="keyword">in</span> food:<span class="global">pairs</span>() <span class="keyword">do</span>
<span class="keyword">end</span></code></pre> item.d <span class="comment">-- angle in radian
</span> item.dist <span class="comment">-- distance
</span> <span class="keyword">end</span></code></pre>
</ul> </ul>
</dd> </dd>
<dt> <dt>
<a name = "api:get_rotation_speed"></a> <a name = "findSegments"></a>
<strong>api:get_rotation_speed ()</strong> <strong>findSegments (max_distance, include_own)</strong>
</dt> </dt>
<dd> <dd>
API #1 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.
<h4>Returns:</h4> <h4>Parameters:</h4>
<ol> <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>
allowed rotation speed by the game engine
</ol>
<h4>Usage:</h4> <h4>Usage:</h4>
<ul> <ul>
<pre class="usage"><code class="lua"><span class="keyword">local</span> x = current_heading + api:get_rotation_speed()</code></pre> <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>
</ul> </ul>
</dd> </dd>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment