# Events Triggers Conditions

Note: A big part of quality scenario design is the logic box. Here, GaryOwen shares how to tap into the design power available in Steel Beasts Mission Editor.

Jayman made a great Excel Macro Spreadsheet to help understand how logic works. If you own Excel by Microsoft, then I highly recommend downloading this and referring to it as you read through this chapter:

(Also included in the ZIP file are Jayman's JPEG images of the different flow charts for those of you who do not have Excel.) I hope to be able to build a page that works the same way in HTML when I have the time for those of you who do not have Excel. - mm

## BOOLEAN Logic and how to use it. (by GaryOwen)

If you understand a little bit of symbolic logic, then you can unleash a lot of the potential complexity of Steel Beasts’ programmed instruction or ‘AI’. I’ll try to explain a bit of logic and show how to use logic to program behavior in computer controlled units.

A useful way to think of symbolic logic is to regard it as a way of doing algebra with words rather than numbers. In the algebraic equation, y = 2x+1, the variables x and y represent numbers. In the logical expression, A or (B and C), A, B, and C represent propositions. Propositions are statements about the world (in our case the virtual world of the Steel Beasts battlefield), that are either true or false. In algebra, you solve equations by using the mathematic functions of addition, subtraction, multiplication, and division to figure out which particular numbers the variables represent. Similarly, in symbolic logic you can figure out the truth value of expressions and propositions by using the logical operators: IF, THEN; AND; OR; NOT. (Footnote: There are other logical operators, however, these are the only ones important to our discussion here.)

So how do the operators work? First off, except for the operator NOT, they always connect two propositions. An expression containing two propositions that are related to each other by a logical operator is itself a proposition. For instance, the statement, "If Fluffy is either a cat or a dog, then she is a mammal," is a complex proposition that contains sub-propositions. If we want to evaluate the statement, we can break it down into its constituent parts. We have two propositions connected by the IF, THEN operator. We can symbolically represent this with the expression: If A, then B. A is the proposition, "Fluffy is either a cat or a dog;" B is the proposition, "She is a mammal." The proposition A, however, contains two sub-propositions connected by the operator OR. It can be symbolically represented as, C or D. C is the proposition, "Fluffy is a cat;" D is the proposition, "Fluffy is a dog." Thus, our original statement can be represented as, If (C or D), then B.

Once we’ve changed the original statement to its symbolic logical ‘equation’, we can compare its constituent propositions to the real world and using a few rules about how the operators function, we can perhaps make some deductions about things we can‘t find out by looking at the real world. Say that we find Fluffy and take a close look at her, and we find out that yes, she is indeed a cat. Assuming the validity of our original statement, we can now say with certainty, whether we know anything about biological classifications or not, that Fluffy is a mammal. Although this example seems incredibly trivial, it is helpful in demonstrating how to analyze statements.

Proper analysis requires an understanding of how the operators function, much like finding the proper solution to an algebraic equation requires the ability to perform the basic math functions of adding, subtracting, multiplying, and dividing. Fortunately for us here, the logical truth tables are much simpler than the times tables we had to learn in grade school. The following truth tables are logical expressions containing propositions and a single operator. We will substitute the truth values of True "T" or False "F" for the propositions and show the truth value of the expression for all the possible truth value combinations of its constituent propositions. ("P" & "Q" are used as generic place markers to denote any propositions, much like algebra uses variables in the formula, y = m(x) + b.)

REVISED TRUTH TABLES

The lower case letters to the right of the tables correspond to the red-lettered examples in the diagrams.

```(P AND Q) P  Q  Diagram
T     T  T     a
F     T  F     b
F     F  T     c
F     F  F     d

(P OR Q) P  Q   Diagram
T    T  T      a
T    T  F      b
T    F  T      c
F    F  F      d

(If P, THEN Q)  P  Q  Diagram
T        T  T     a
F        T  F     b
T        F  T     c
T        F  F     d

(NOT P)  P  Diagram
F     T    a, b
T     F    c, d

```

Now back to our original statement regarding Fluffy, If (C or D), then B. In our example we know that C is true. If we substitute a "T" for the "C" in the expression, we have If (T or D), then B. Now if we compare the proposition (T or D) to the truth table for OR we find that every time the first proposition in the expression is True, the expression itself is also True. (See the first and second lines of the truth table.) So, it must be the case that (T or D) is True. We can now substitute a "T" for (T or D) in our original expression. We now have, If T, then B. Assuming that the entire expression is true, we look at the truth table for IF, THEN and find that when the entire expression is True and the first proposition in the expression is True, the second proposition is also True. (See the first line of the truth table.) Since B represents the proposition, "Fluffy is a mammal," and B is true, we can now say that we know that Fluffy is indeed a mammal.

There are a number of ways that a designer can control the behavior of the units in a scenario. A unit may be ordered to embark along a route, retreat from a position, open fire, be passed from the control of the computer to the player, or pre-plotted artillery strikes may be called. In the mission editor, right clicking on a route will bring up a menu that includes the commands, "Embark If" and "Retreat Back If." Right clicking on a check point, unit, or route will bring up a menu that includes the command "Set Fire Ctrl," this command has a sub-menu that includes the command "Open Fire If." Also included in the unit menu is the command "Options," that has a sub-command "Set Owner," which in turn has a sub-command, "Player If." Right clicking on a spot on the map will bring up a menu that includes the command, "New Arty Call." All of these commands can be written as IF, THEN expressions. Additionally, there is a pull down menu at the top of the editor window labeled "Control Logic" that allows the designer to set Events and Conditions.

Selecting any of these commands will bring up what I call, for lack of a better term, the Logic Box. Figure 1 is a screen-shot of a logic box that I brought up by selecting the command, "Embark If."

The Logic Box is divided into two main parts. At the top in the left corner is an expression with empty places where the designer can set various propositions. In the bottom of the box is a list of propositions that the computer can compare to the virtual world of the Steel Beasts battlefield in order to determine their truth values. The Logic Boxes for the various commands are all functionally similar. There are minor differences between the Boxes for Conditions and the Boxes for Events, for example, but those differences are not important to our discussion here.

It will help to understand how the Logic Box works if we write out the expression in the

left top corner as: A AND/OR {(B AND C) OR (D AND E) OR (F AND G)}. (In order to simplify the discussion, I’ll refer to this expression as "the Sentence.") You should notice that I wrote the first operator as "AND/OR." This is because that operator can be changed from an AND to an OR and vice versa by clicking on it. See Figure 2.

You can select a proposition from the list at the bottom of the box for each variable position in the Sentence. In our example, I’ve selected the proposition "Unit 1/A is in region 1" for the ‘A’ variable position in the Sentence. This selection is performed by clicking on the dot next to the proposition and then clicking through the white shaded boxes until the proposition is acceptable. For example by clicking through the boxes in this proposition, you can select "Unit 1/A is not in region 1." See Figure 3.

Next I have clicked on the ‘B’ variable in the Sentence and it has turned green which means that I can select a proposition for that position. See Figure 4.

For the ‘B’ position, I have selected the proposition "Unit this is not under direct fire." See figure 5.

Finally, I have selected the proposition "mission time > 20:00" for position ‘D’. See Figure 6

Now we can rewrite our Sentence. I will use a dash ("-") for each unused position.

A and {(B and -) or (D and -) or ( - and - )}. If we remove the unused positions, we reduce our Sentence to: A and {(B) or (D)}. The positions of the propositions within the Sentence is very important. In order to determine the truth value of the entire Sentence, the truth conditions of operations contained within the parentheses should be evaluated first, next the operations within the brackets, and finally the truth condition of the first AND/OR operation. Using our Sentence as an example, the statement, "It is the case that A and B are true or that D is true," is entirely different from the statement, "It is the case that A is true and that either B or D is true." (The latter statement expresses our Sentence.)

We can now put our Sentence in the context of the Embark If command: IF [A and {(B) or (D)}], THEN any unit at the beginning of this route shall embark. We can translate this into English as: If it is the case that Unit 1/A is in Region 1 and it is also the case that either any unit at the beginning of this route is not under direct fire or the mission time is greater than twenty minutes, then any unit at the beginning of this route shall embark.

The computer will use the truth tables and the situation on the virtual battlefield to evaluate our Sentence and when it is true, it will follow our embark command. The computer will begin by evaluating the operation within the brackets, which we know from the OR truth table will be true when just B is true, when just D is true, and also when both B and D are true. It will then evaluate the AND operation, which we know from the AND truth table will only be true when both A is true and the operation within the brackets is also true.

So the embark command will be followed in the following circumstances:

Unit 1/A is in Region 1 and any unit at the beginning of the route is not under direct fire.

Unit 1/A is in Region 1 and the mission time is greater than twenty minutes.

Unit 1/A is in Region 1, any unit at the beginning of the route is not under direct fire, and the mission time is greater than twenty minutes.

Given the complexity of the entire Sentence, the number of proposition positions, and also the flexibility of the available propositions, the number of potential instructions you can give the computer is immense. Hopefully, if you’ve been bewildered by the logic box and how it works, this brief essay will help you to do what you need to do in order to really understand and master it. Experiment.