This is the mail archive of the xconq7@sources.redhat.com mailing list for the Xconq project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GDL Notice: Arithmetic Operators / Quasi-Formulae


Hello Xconq Game Designers,

  I just added the four basic arithmetic operators to GDL. They are:
"+", "-", "*", and "/" (all without the quotes). I think that when they
are used in conjunction with defined symbols in GDL, they can provide
much of the power and flexibility you might expect from having formulae
in GDL.

  Here are some rather unsophisticated examples of their usage that I
hacked into Wreckreation for testing:

(define VILLAGE_STORAGE_MULT 5)
(define HUMAN_BURDEN_CAP 40)
(table unit-storage-x add
    (village food 200)
    (village food (* HUMAN_BURDEN_CAP VILLAGE_STORAGE_MULT))
    (village food (/ (* HUMAN_BURDEN_CAP VILLAGE_STORAGE_MULT) 1))
    (village (food orc-food) ((+ 50 (- 200 50)) (/ 0 100)))
    (village (food orc-food) (+ 50 (150 50)))
    (village (food orc-food) (+ (150 50) 50))
    (village (food orc-food) (+ (50 50) (150 50)))
)

  The first 3 "(village food ..." declarations are all equivalent to one
another. The last 4 declarations are also all equivalent to one another,
and demonstrate the new operator's powerful ability to manipulate lists
and mixtures of numbers and lists. In all of the above declarations, the
gist is that the storage capacity of a 'village' for 'food' is always
200, despite the different methods of calculating it. In the last 4
declarations, all of the storage capacity for 'orc-food' is always 100,
despite the different methods of calculating it.

  Some things to note:
(1) I still consider this experimental. Although my testing did not
reveal any bugs (__well, it did, but I fixed them :-), there may be some
lurking in the code that handles the operators. Please kick the tires
some and tell me what you think about it.
(2) Note that the notation is postfix. So, operator first, then the
operands.
(3) There is no limit on the number of operands that can be supplied to
the operators.
(4) Division by zero will produce a warning if you attempt it. This is
to say that only the first operand (the dividend) of a division operator
can be 0; all others (the divisors) must be non-zero, and return an
empty result.
(5) List lengths must match, if lists are used. Failure to match list
lengths will produce an warning, and return an empty result.
(6) As can be seen above, you can nest operators. The innermost (most
deeply buried in parentheses) operations are performed first.
(7) Precedence is enforced by the parentheses; there is no natural
precedence order. Expressions are, of course, read from left to right.
(8) I will document this fairly soon. I want to make sure bugs are
ironed out, produce some neater examples, and add a bell and a whistle
before making this feature official.
(9) The "bell" (not yet added) is "(- n)", which will decrement n by 1.
(10) The "whistle" (not yet added) is "(+ n)", which will increment n by
1.
(11) Xconq does not support rational numbers (fractions), and so results
between 0 and 1 will be 0. This is standard integer arithmetic.
(12) I may, at some point, add a modulo operator ("%") for extracting
remainders of divisions.
(13) Lists and individual numbers can be mixed freely. Again, the only
constraint is that the lengths of all the lists must match.
(14) Doing math on dice specs is not recommended with this set of
operators. They treat dice specs like normal integers (> 16384), and
will likely screw with your dice specs in ways that you might not
imagine.

  Enjoy,
   Eric


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]