How to Build a Turn Based Strategy Game

4

Index

Attached Files

The following files have been attached to this tutorial:

Stats

3,277 visits, 5,981 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 11 Feb, 2023. Last updated 28 Feb, 2023

5. AI Control

5.1 AI Selection and Targeting

First, event 50 we tell the computer to select a random unit and call “Find_Target” function. Next event 51 sets for the selected unit a target whereas event 52 does a similar thing in that it checks that such target exists and if target was destroyed then update target for current selected unit. In the end event 53, if no targets exist then find a random node to travel to.

5.2 Finding Target Function

The “Find_Target” function event 54 to 56 searches for all units that belong to player and adds the UID of those unit to the text object Turn variable target_list.

5.3 AI Ending Turn

The event 57 is similar to event 37 in that every time the “AI timer” is triggered the AI executes a set of instructions, which are nested under event 57. When it is AI’s turn check if it should end it’s turn, events 59 to 61, where it can do so if all AI units have ran out of moves or are all destroyed.

5.4 AI Selecting

Taking place in event 62 the AI picks a unit and extracts from it the variable target and stores it temporarily in a local variable target_uid. Next events 63 and 64 check around the selected unit its travel range.

5.5 AI Searching

In event 65 using the temporary variable target_uid we find our target and at what node it is located. From that, our temporary value goal is set to be equal to the found node IID value. Our event 66 performs a similar task as event 65 under the condition that no target exists. Going over to event 67, we find the starting node IID of our selected unit and execute the “A_Star” function. Once “A_Star” is complete the function will return a travel list to the text object called Turn. We format this travel list and store it in the select unit travel_list variable.

5.6 AI Moving

AI movement is performed using event 70 where for the selected unit from its variable travel_list we select the next node to travel to and update its trave_list variable.

5.7 AI Attacking

AI attack is performed using event 68 and 69 in similar fashion as when moving but this time check it target node is within range. Note that AI attack condition, event 68, is first to be executed where if the target is not in range then AI moves its unit executing event 70.

These events 68 to 70 are a basic example of the AI FSM. Where if the order of these event are reversed then the AI will prioritize movement over attacking behavior.

5.8 AI Resolving Problems

Using only events 69 and 70 are not enough as the AI can get stuck and we need the computer to resolve this. This is done using event 71 to resolve the targeting issue that occurs when AI destroys a unit belonging to a player or is stuck in a corner with nowhere to move. And event 72 which is similar to event 71 under the condition no enemy unit to target.

  • 2 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Hallo. Idont see AJAX plugin in add.

    • AJAX plugin already exists by default in Construct 2 and 3.

      When you double-click in one of your layouts a new window will appear for creating new objects.

      Inside that new window scroll all the way down to the Web category until you see the AJAX plugin. Or simply use the search tool and search for AJAX. Double-click the AJAX icon or click on the insert button to add AJAX into your project.

      If you do not see the AJAX plugin in your attempt to add it into your project, then it simply means that you have already added AJAX into your project already.