Introduction to AI

This is an introductory tutorial to the Artificial Intelligence addon.

The AI addon has a customized artificial intelligence algorithm written from scratch to support best with Construct's architecture, useful for programming intelligent object instances, including game bots.

It's a lightweight algorithm with mathematically balanced implementation. It's efficient and blazing fast, while also full-packed, with tools to handle most processing techniques, even flipping data.

The AI uses decision-making technique in recreating intelligence, with factors as properties. Factors include intelligent reports and options.

It also handles the received raw data through different processing features, like decision methods and data flipping value bias.

It's an ideal feature for game application projects with game bots, npcs, bosses and any artificially intelligent object instances, made with either Construct 3 or Construct 2.

 

Introduction

The Artificial Intelligence (AI) addon implements a decision-making based algorithm to artificially recreate or simulate intelligence.

The core features are the 2 decision types. The Intelligence Report Decision and Option Decision.

Decision Types :

  • Intelligence Report - is a factor-based decision making type. Inputting factors here for a decision output of yes, no and maybe in percentage value (0 to 100). Interpreting as Is a smart decision, Is not a smart decision or undecided.

    • Is smart decision - a decision that collected all the factors relative to the instance's intelligence and the output resulting greater than 50 ( > 50 )

    • Is not a smart decision - a decision that collected all the factors relative to the instance's intelligence and the output resulting lesser than 50 ( < 50 )

    • Undecided - a decision that collected all the factors relative to the instance's intelligence and the output resulting equal to exactly 50 ( = 50 )

  • Option - is a selection-based decision making type. Inputting each option with their own values. It outputs the selected option.

These decision types can be used together through nested decisions. This is done through using other decision types for their values, or having multiple layers of decisions through expressions.

Sample Nested Decision.png

Decisions can be nested just like as shown at the sample set option value for the NextMove option decision.

The AttackFactor decision, which is an intelligence report decision, contains the data values that determines if the instance is fit to attack.


This data can be processed and retrieved by using the expression Decide(), with the decision name as a param.

Doing that , the option will have the value based on the output data from the AttackFactor intelligence report decision.

Decision Methods :

The decision methods determine how the raw data is processed for all intelligence report factors or options.

  • Percentage - is a decision method that only accepts values from 0 to 100, which is a percentage.

    • Intelligence Report Decision - ​reports are all collected in this method, summed all values, then divided by the report count multiplied by 100. ( reportSum / reportCount x 100)

      • Direct Bias - if in direct bias, the value remains the same value. ( 75, is then = 75)

      • Inverse Bias - if in inverse bias, the value is inverted. ( 75, is then = 25)
        This is useful when flipping data, for opposing values.​​

    • Option Decision - ​in this method, the highest percentage gets the lower rank index, that starts from 0.

  • Scale - this is similar with the Percentage method, only that it accepts values from 0 to 1.0.

    • Intelligence Report Decision - ​this is similar with the Percentage method.

      • Direct Bias - ​this is similar with the Percentage method. (0.75, is then = 0.75)

      • Inverse Bias - ​this is similar with the Percentage method. (0.75, is then = 0.25)

    • Option Decision - ​in this method, the highest percentage gets the lower rank index, that starts from 0.

  • Highest - is a decision method that has no value limit. It accepts any number value.

    • Intelligence Report Decision - ​in this method, calculation process is different. Since there is no predefined total, the direct bias is divided by the inverse bias.

    • Option Decision - in this method, the highest option value gets the lowest rank index, and the rank index of 0 is selected.

  • Lowest - is a decision method that has no value limit. It accepts any number value, similar to the Highest method.

    • Intelligence Report Decision - ​in this method, calculation process is similar with the Highest method. Although, the inverse bias is the one divided by the direct bias.

    • Option Decision - in this method, the lowest option value gets the lowest rank index, and the rank index of 0 is selected.

Regardless of the decision type, the output format will still be the same.

  • Intelligence Report Decision - it will output the IntelDecisionPercentage, this is percentage value from 0 to 100, the output from the Intelligence Report Decision algorithm.
    If no report has been made, it will output
    50 %. ( = 50 )

    • Is Smart Decision​ - greater than 50 %. ( > 50 ) 

    • Is Not Smart Decision​ - lesser than 50 %. ( < 50 )

    • Is Undecided​ - exactly equal to 50 %. ( = 50 )​​

  • Option Decision - it will output the SelectedOption, this is name of the option with the lowest rank index, which is 0. If there are options with similar values, the option that is to be selected and ranked lower will be at random.​ 

Decision :

The Decide action runs a programmed decision made from events, once it finished, which is synchronously instantaneous. It will trigger the condition On Decision. Then these expressions will be updated to that recently processed decision:

  • CurDecision - this is basically the name of the decision.

  • CurDecisionVal - this is basically the value of the decision.

    • Intelligence Report Decision - this returns the Intelligence Percentage.​

    • Option Decision - this returns the selected option.

 

You can retrieve more values with the other expressions by specifying the Decision Name, where you can use the CurDecision expression to retrieve the current decision's other values.

For the complete Actions, Conditions and Expressions (ACE) list, click here.

The Decide expression works the same as the action. With an additional feature to return the CurDecisionVal, which is useful for making nested decisions. This is due to the synchronous but instantaneous nature of the intelligence algorithm.

 
 
 

Decision Algorithm

The Artificial Intelligence (AI) addon implements decision making from two (2) types, the Intelligence Report Decision and Option Decision.
Even though these 2 decision types are processed differently depending on the decision method and bias, at the core, they have common algorithms, which involves the following values:

  • Intelligence

  • Original Value

  • Median

  • Range by Intelligence

  • Perceived Value

  • Perceived Intelligence

  • Rank

  • Selected Option

  • Intelligence Percentage

Instance Defined

Instance defined properties are those values marked to each instance, used indirectly for later use on events and output decision data. Although, properties here can still be modified through events.

  • Intelligence - the percentage (0 to 100) used to determine the accuracy of getting the perceived value close to the original value, when each intelligence report or option is ran with the Smart Randomizer
    Technically, this determines the
    range (range by intellect) relative to the original value, from the smart randomizer. This is the range where the original value can be perceived differently, relatively scaled within the median.

    If the intelligence percentage is
    100%, for example, the accuracy would be 100% too, so the PerceivedValue would also be equal to the OriginalValue

    Hence, even when there is a
    Smart Randomizer, if the Range By Intelligence = 0, it still wouldn't reinterpret the value into an inaccurate form, since the Intelligence is 100%.
    The
    Perceived Intelligence also becomes 100%, in this case.

    More clarification below.

     

Event Defined

Event defined are values defined through events. These are mostly original input values pre-decision process.

  • Original Value - is the original input value on an intelligence report or option.

  • Median - the absolute midpoint from the lowest value to the highest value report or option of a decision.

Decision Output

  • Range by Intelligence - is the range where the perceived value from the original value can vary from the median, this is highly influenced by the Intelligence property of an object instance, where the range can lessen as the object instance's Intelligence property increases. Eventually reaches 0, if the Intelligence property is at 100%.

  • Perceived Value - is the processed counterpart value of the original value, that has undergone the Smart Randomizer process. The range of its variation is based on the range by intelligence, which is the median inversely proportionally scaled to the object instance's intelligence.

  • Perceived Intelligence - is the percentage scale from the original value to the perceived value, relative to the range by intelligence.

  • Rank - is the index from 0 that determines the ranking of an option on an option decision. The ranking depends on the decision method.

  • Selected Option - is the name of the option that has the lowest index, which is 0, on an option decision.

  • Intelligence Percentage - is the output percentage of an intelligence report decision. It determines how smart the decision is, based on the collected reports.

    • Is Smart Decision - ​if the output is greater than 50.

    • Is Not a Smart Decision - if the output is lesser than 50.

    • Is Undecided - if the output is exactly equal to 50.

 

Smart Randomizer

The Smart Randomizer is an algorithm that is common to the two (2) decision types, the intelligence report decision and option decision.
It mainly utilizes the
original value, the median of the original value and the instance's intelligence. To generate the perceived value and the perceived intelligence.

The process is explained here.

 

Intelligence Report Decision

Intelligence Report Decision.png

Intelligence Report Decision is a decision that determines if a decision is a smart, non-smart or undecidable.

It's useful for gathering yes, no and maybe outputs, either in toggle form or values.

Beside is a sample decision of a game bot deciding "Should I attack the Player?".

As shown, it tries to collect data from both the player and itself (AI). Each report becomes a factor of the decision making, the more reports and the better the report set construction, the smarter the AI would become.

The reports would have to be in percentage value (0 to 100), since it's in the Percentage decision method.

These are the following reports acting as factors for the "Should I attack the Player?" intelligence report decision:

  • My Health (AI Bot) - the percentage scale of the bot's health.

  • My Accuracy (AI Bot) - the percentage scale of the bot's accuracy.

  • Enemy Health (Player) - the percentage scale of the player's health.

  • Enemy Accuracy (Player) - the percentage scale of the player's accuracy.

  • Distance From Enemy - the percentage scale of the distance between the player and bot.

Then the median of the intelligence report decision is calculated from the lowest report value to the highest report value. Which will be used in the Smart Randomizer to calculate and get the perceived value and perceived intelligence.

You can then read the Intelligence Percentage value to determine if the decision is smart, not smart or indecisive.

Finally, if it's a Decide action, the condition trigger On Decision will fire. If it's an expression, it will trigger the On Decision condition trigger too, and also output the Intelligence Percentage instantaneously as a return value.

Option Decision

Option Decision.png

1. Option Decision is a decision type that uses the intelligence algorithm to choose from the given options, the selection depends on the decision method.

It's useful for making the instance decide to choose an option based on the value, intelligence and decision method.

Above is a sample decision of a game bot deciding its next move, either Attack or Run away.

As shown, it tries to get the Attack Chance as the Attack factor, then it also inverts the Attack Chance to use as the Run away factor. This would result into:

  • Attack : 80%

  • Run Away: 20%

Similar with the Intelligence Report Decision, the Smart Randomizer randomizes the value of each option through the intelligence algorithm, using the median, range by intelligence and the option's original value.

The range of randomness depends on the object instance's Intelligence property until it reaches 100%, where the exact original value is used as the perceived value,

while the perceived intelligence is 100% as it's 100% close to the original value, as explained here.

You can then read the Selected Option value to get the chosen option from the option decision.

Finally, if it's a Decide action, the condition trigger On Decision will fire. If it's an expression, it will trigger the On Decision condition trigger too, and also output the Selected Option instantaneously as a return value.

 

Easy Sample Projects

There is an easy sample project for the Intelligence Report Decision.

This teaches the basics for this decision type. Although, it's encouraged that you learn the advanced features afterwards.

Click here to get the easy sample.

There is an easy sample project for the Option Decision.

This teaches the basics for this decision type. Although, it's encouraged that you learn the advanced features afterwards.

Click here to get the easy sample.

Fight Bot Sample

There is a complete game demo project called Fight Bot.

This teaches a sample of a complete game implementation of the AI addon

It's a match game between a player and an AI game bot.

Click here to get the game demo.

Special thanks to Fricky for letting us use his game project concept and art to be rewritten for the AI addon. And also thanks to one of the supporters that suggested to use the amazing Fight AI game and asked the developer for permission.
To view the original game named
Fight AI, click here.

 
 

AI

The AI addon is the new replacement for the AI Behavior, with refactored implementation, efficient and blazing fast algorithms and customized & designed from scratch for Construct 2 and Construct 3, especially the c3runtime.

It's an ideal AI addon to implement intelligent object instances to games.

Get the tools

for your pro games!

Constuct Master Collection - Itch.io
Constuct Master Collection - Discord
Constuct Master Collection - Construct 3

© Construct Master Collection 2020 • All rights reserved

Contact Information: