📜 ⬆️ ⬇️

Script Editor Age of Empires 2 can be turned into a Turing machine

image

Nothing can compare with the evening spent on the logic of statements, Turing machines
and script editor AOE2 ...

Among other great features available in the editor, the most awesome feature is the definition of triggers . They lead to performing an action based on conditions. It seemed to me obvious that it is worth starting from here, because here the task of rules is carried out. In this case, the question arose: what types of triggers do I need to look specifically for? Of course, those that meet the requirements of the Turing machine! This means that the conditions and actions of these triggers should allow to implement the following:

1. Read and write characters
2. Change position in my "memory space"
3. Have a "tape" or "memory"
4. Have a pool of used characters
')
Besides, I need to be able to write down some rules. It will also be very useful access to the logic of statements. With this, I began my research (that is, by searching in Google), and in half an hour I received all the answers I needed.

The following objects, conditions and effects sufficiently satisfy the requirements:

Character pool: any number of game units
Memory pool: all types of units available in the game (see note at the end of the post)

Position change in memory: Create Object

Write to memory position: Create Object, Task Object, Kill Object

Reading from memory: Own Objects, Own Fewer Objects

Here is an example of the use of game unit types as memory “cells”:


In this example, the memory looks like this: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1

But we can very easily change memory with triggers so that it looks like this:


That is: 8, 1, 8, 1, 1, 8, 1, 1, 1

In the next section, triggers are presented as a way to launch a “program” and display a very strange data stream. Triggers can be configured to automatically trigger when the game starts, as well as to constantly trigger to organize an infinite loop. This is the main driving force of the program, which allows you to structure such "programs" in two ways:

Parallel execution:

  T1 T2 T3
 C1 (T) C1 (F) C1 (F)
 C2 (F) C2 (T) C2 (F)
 C3 (F) C3 (F) C3 (T) 

All three triggers (T) are triggered at the same time and are configured so that conditions (C) force them to fire at the right time.

Tree execution:

  T1 launches T2 launches (T3 or T4) 

T1 "controls" the program, being the only trigger that starts working when the game starts and performs an infinite loop. It passes execution to T2 trigger, and then T2 starts T3 and T4, but they themselves decide among themselves which of them should be executed (similar to how the triggers behave when executed in parallel, or what XOR does below).

It seems to me that this is a more practical way of structuring such programs, and it is more efficient because it contains fewer instructions.

Does the script editor have any way to implement expression logic? Yes. We have access to conditions, that is, we can create if -> then, and this, in combination with Own Objects and Own Fewer Objects, allows us to access memory and perform comparisons.

We can combine two expressions / conditions, so you can simply implement the “AND” operations:

  Own Objects (Unit type: Soldiers, Amount: 7)
 Own Objects (Unit type: Archers, Amount: 10) 

Also with the help of triggers, you can implement a partial "OR". The problem with it is that if both branches are true, then both triggers will be executed. Therefore, a more useful operator would be "XOR":

  Trigger 1 Trigger 2
 Condition 1 (T) Condition 1 (F)
 Condition 2 (F) Condition 2 (T)
 Effects effects 

Both triggers are triggered simultaneously, but only one effect branch is executed, because Condition 1 must be true in one, but false in the other, and vice versa for Condition 2.

Also, using Own Fewer Objects, Create Object, Task Object and Kill Object, you can easily implement addition and subtraction:

  Trigger 1
 Own Fewer Objects (Unit type: Soldiers, Amount: 9)
 Create Object (Soldier)
 Task Object (Move to location)

 Trigger 2
 Own Fewer Objects (Unit type: Soldiers, Amount: 17)
 Create Object (Soldier)
 Task Object (Move to location) 

An example of how this might look like in a game:


We need a Task Object, because the game will not create more than one object at one point, so we make it move.

The result of this operation can be found in the unit counter at the top of the screen.

A more complex, but useful set of triggers and conditions allows performing operations to check for equality, including "equal", "less or equal", "greater or equal". However, for their proper operation, we need to enter a special “stop” symbol - the King:


The configuration for "whether 23 more than 9" will be:

  Trigger 1 (On-startup, Loop)
 Own Fewer Objects (Unit type: Soldiers, Amount: 23)
 Create Object (Soldier)
 Activate Trigger (2)

 Trigger 2 (No loop)
 Own Objects (Unit type: Soldiers, Amount: 9)
 Own Fewer Objects (Unit type: King, Amount: 0)
 Create Object (King) 

This system will constantly create soldiers until they become 23. If we have 9 or more, it will mean that 23 is more than 9 and to designate this we create a King. In the process of creating scripts, you can change the unit “stop” to any other, or create any desired number of them.

In general, this is not particularly useful, but still great!

Unfortunately, I could not find a simple way to record video, but if someone succeeds, then I will add them here.



So, it seems I did not quite understand what Turing is completeness. Not only should I be able to create a Turing machine, but it should also be any Turing machine. To realize it, I need an "infinite" memory. In our case, we are limited by the number of unit types, but we can create an arbitrary number to solve this problem: http://aok.heavengames.com/university/modding/an-introduction-to-creating-units-with-age-2 /

Source: https://habr.com/ru/post/349374/


All Articles