Difference between revisions of "BotProgramming Basics"

From Gladiabots Wiki
Jump to: navigation, search
Line 29: Line 29:
 
[[File:Counterclockwise.png|thumb|Nodes are evaluated counterclockwise]]
 
[[File:Counterclockwise.png|thumb|Nodes are evaluated counterclockwise]]
  
To determine the action a bot should use in the current situation, the nodes are traversed by a [https://en.wikipedia.org/wiki/Depth-first_search depth-first search] algorithm:
+
To determine the action a bot should use in the current situation, the valid nodes are traversed by a [https://en.wikipedia.org/wiki/Depth-first_search depth-first search] algorithm beginning with the root node:
  
 
[[File:Depth-First-Search.gif]]
 
[[File:Depth-First-Search.gif]]
 +
 +
{{InformationCollapsed|1=Details of the AI checking process|2=Use the root node as reference node and start at step (1):
 +
* 1) Get a list of all subnodes linked from the bottom of the reference node. Traverse this list of subnodes ordered {{Tooltip|counterclockwise|Important is the link from the bottom of the reference node to the top of the subnode. The angle is computed between the vertical above the reference node and the link counterclockwise.}}:
 +
** 1a) If the current subnode is an action node and evaluated valid, then the AI checking is discontinued as a '''valid action''' is found.
 +
** 1b) If the current subnode is a sub-AI, then this sub-AI is evaluated. If a '''valid action''' is found in it the AI checking is discontinued.
 +
** 1c) If the current subnode is a condition or connector node and evaluated as valid, then use this subnode as reference node and start a recursive evaluation at step (1). If '''no valid action''' is found there, continue at step (1d) afterwards.
 +
** 1d) If there are further subnodes in step (1) continue with the next subnode at step (1a).
 +
* 2) If there are no further subnodes in step (1), try to backtrack to the previous evaluation in step (1c). If there is no previous evaluation '''no valid action''' could be found. The bot idles instead.
 +
}}
  
 
{{Information|Branches are not executed counterclockwise but checked counterclockwise.}}
 
{{Information|Branches are not executed counterclockwise but checked counterclockwise.}}
 +
 +
{{Information|The evaluation of nodes is instant and is not wasting any time from the current tick.}}
  
 
{{Warning|Rest of the page is a work in progress.}}
 
{{Warning|Rest of the page is a work in progress.}}
 
{{InformationCollapsed|1=Details of the AI checking process|2=Use the root node as reference node and start the following steps:
 
* 1) Get a list of all subnodes linked from the bottom of the reference node.
 
* 2) Traverse the list of the subnodes ordered {{Tooltip|counterclockwise|The angle is determined by the link from the bottom of the reference node to the top of the subnode.}}:
 
* 2.1) If the current subnode is of type action node and evaluated valid, then the search is discontinued as a valid action is found.
 
* 2.2) If the current subnode is of type sub-AI, then this sub-AI is evaluated. If a valid action is found the search is discontinued.
 
* 2.3) If the current subnode is of type condition or connector node and evaluated as valid, then use this sub node as reference node and start a recursive evaluation at step (1).
 
* 2.4) If there are further subnodes in step (2) continue with the next subnode.
 
* 3) If there was no valid action up to this point, let the bot idle instead.
 
}}
 
  
 
<!--
 
<!--
 
  
 
[[File:Screenshot 20170712-230926.png]]
 
[[File:Screenshot 20170712-230926.png]]
counterclockwise beginning with the root. As long as the nodes are evaluated valid the nodes connected from the bottom are explored below ar
 
  
are checked recursively starting with the root node as the reference node.
 
 
 
 
* 1) Try to get the first unchecked node
 
* 1.1) sdf
 
* 1.2)fgh
 
* 2) fgh
 
 
 
AI checking is discontinued
 
if not a single action is valid the idle action is used instead.
 
 
describe counterclockwise evaluation process.
 
and only elements linked to the root node can be evaluated during the execution of the AI
 
The evaluation needs no time do not take time to be executed. If they are evaluated as True, the evaluation of the current tree goes on. If they are evaluated as False, the current tree is terminated and the next tree (if any) is evaluated.
 
 
 
 
== ToDo ==
 
  
 
== Best practices for AI design ==
 
== Best practices for AI design ==
  
[[File:Screenshot 20170712-230926.png]]
 
 
 
== Subtrees / Sub-AIs ==
 
 
 
Links:
 
 
debugging If a bot is selected one can see the state of its AI. - lines between bots
 
Connectors Though they do not execute any computation or action, they have an interesting, though not commonly used or advised, use.
 
 
Connectors are the GOTOs of AIs. And just like any programming language, GOTOs here too are considered "bad" code. Still, they can save you a lot of work sometimes.
 
Connectors are the GOTOs of AIs. And just like any programming language, GOTOs here too are considered "bad" code. Still, they can save you a lot of work sometimes.
 
Ever have a group of Nodes that you regularly use, and the same thing is present in your AI again and again? Sub-AIs are used like Macros. You can just make an AI with the commonly used group of Nodes, and then add this as a Sub-AI in your main AI. Sub-AIs tend to improve game performance (more Nodes make the game laggier)
 
Ever have a group of Nodes that you regularly use, and the same thing is present in your AI again and again? Sub-AIs are used like Macros. You can just make an AI with the commonly used group of Nodes, and then add this as a Sub-AI in your main AI. Sub-AIs tend to improve game performance (more Nodes make the game laggier)
 
You can also use Sub-AIs to make Hybrids out of existing AIs. Remember, Sub-AIs are essentially AIs linking other AIs.
 
You can also use Sub-AIs to make Hybrids out of existing AIs. Remember, Sub-AIs are essentially AIs linking other AIs.
 
 
 
Readable code. To be readable avoid crossing lines. Divide in sub-AIs
 
Readable code. To be readable avoid crossing lines. Divide in sub-AIs
 
  > Comment it with empty sub-AIs
 
  > Comment it with empty sub-AIs
  
  
Bots are created using the AI Editor.
+
== ToDo ==
The AI editor is where you design your AIs.
+
 
 +
debugging If a bot is selected one can see the state of its AI. - lines between bots
  
  

Revision as of 00:40, 21 October 2017

Information.png This page needs improvement, you are welcome to contribute.

Basics

The robots in Gladiabots are autonomous and obey their Artificial Intelligence (AI). Bots can only execute one of the possible actions at a time. The AIs task is to determine what action to use in the current situation. Each bot checks its AI counterclockwise, searching for the first valid branch leading to an action.

Example AI.png

The AI of a bot is shaped like an upside down tree. It can be composed of the following elements:

Element Description
Root node Each AI contains exactly one root node that defines the starting point of the AI check. Nodes linked from the bottom of the root node are evaluated counterclockwise. The root node indicates the name of the AI.
Action node If a rectangular-shaped action node is evaluated valid during AI check, the described action is executed for the current tick. An action node is considered invalid if the bot cannot perform it.
Condition node If an oval-shaped condition node is evaluated valid during AI check, the nodes linked from the bottom of the condition node are evaluated counterclockwise. A condition node is considered invalid if the current situation doesn't fit it.
Connector node The diamond-shaped connector node is always evaluated valid during AI check. It connects every node linked to the top of the connector node with every node linked from the bottom of the connector node. A connector node can be used to simplify the layout of the AI.
Sub-AI node One can reuse an AI inside another one, by using a Sub-AI node. When evaluating this node the whole sub-AI is checked for a valid action. A sub-AI can again contain its own sub-AIs.
Link Nodes can be connected with a link. A link is a directed connection from the bottom of one node to the top of another node.

AI checking process

Nodes are evaluated counterclockwise

To determine the action a bot should use in the current situation, the valid nodes are traversed by a depth-first search algorithm beginning with the root node:

Depth-First-Search.gif

Information.png
Details of the AI checking process 

Use the root node as reference node and start at step (1):

  • 1) Get a list of all subnodes linked from the bottom of the reference node. Traverse this list of subnodes ordered counterclockwise:
    • 1a) If the current subnode is an action node and evaluated valid, then the AI checking is discontinued as a valid action is found.
    • 1b) If the current subnode is a sub-AI, then this sub-AI is evaluated. If a valid action is found in it the AI checking is discontinued.
    • 1c) If the current subnode is a condition or connector node and evaluated as valid, then use this subnode as reference node and start a recursive evaluation at step (1). If no valid action is found there, continue at step (1d) afterwards.
    • 1d) If there are further subnodes in step (1) continue with the next subnode at step (1a).
  • 2) If there are no further subnodes in step (1), try to backtrack to the previous evaluation in step (1c). If there is no previous evaluation no valid action could be found. The bot idles instead.
Information.png Branches are not executed counterclockwise but checked counterclockwise.
Information.png The evaluation of nodes is instant and is not wasting any time from the current tick.
Warning.png Rest of the page is a work in progress.