Difference between revisions of "BotProgramming Basics"

From Gladiabots Wiki
Jump to: navigation, search
Line 22: Line 22:
 
|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.
 
|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          ||A link is a directed connection from the bottom of {{Tooltip|one node|Could be a root node, a condition node or a connector node.}} to the top of {{Tooltip|another node|Could be an action node, a condition node, a connector node or a sub-AI node.}}.
+
|Link          ||Nodes can be connected with a link. A link is a directed connection from the bottom of {{Tooltip|one node|Could be a root node, a condition node or a connector node.}} to the top of {{Tooltip|another node|Could be an action node, a condition node, a connector node or a sub-AI node.}}.
 
|}
 
|}
 +
 +
== AI checking process ==
 +
 +
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:
 +
 +
[[File:Depth-First-Search.gif]]
 +
 +
{{Information|Branches are not executed counterclockwise but checked counterclockwise.}}
  
 
{{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 {{Tooltip|counterclockwise|The angle is determined by the link from the bottom of the reference node to the top of the subnode.}}:
 +
}}
  
 
<!--
 
<!--
  
add output / Input and signal
+
 
 +
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 ==
 
== ToDo ==
== AI checking process ==
+
 
 
== Best practices for AI design ==
 
== Best practices for AI design ==
  
 
File:Screenshot 20170712-230926.png
 
File:Screenshot 20170712-230926.png
AI checking is discontinued
+
 
if not a single action is valid the idle action is used instead.
+
  
 
== Subtrees / Sub-AIs ==
 
== Subtrees / Sub-AIs ==
  
  
Links: Nodes can be connected with a link.
+
Links:  
 
+
describe counterclockwise evaluation process.
+
  
 
debugging If a bot is selected one can see the state of its AI. - lines between bots
 
debugging If a bot is selected one can see the state of its AI. - lines between bots
Branches are not executed counterclockwise but checked counterclockwise.
 
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.
 
 
Connectors Though they do not execute any computation or action, they have an interesting, though not commonly used or advised, use.
 
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.

Revision as of 23:45, 19 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

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

Depth-First-Search.gif

Information.png Branches are not executed counterclockwise but checked counterclockwise.
Warning.png Rest of the page is a work in progress.
Information.png
Details of the AI checking process 

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 counterclockwise: