You must be logged in to post messages.
Please login or register

Scenario Design Discussions
Moderated by GoSailing

Hop to:    
loginhomeregisterhelprules
Bottom
Topic Subject: Attribute Mathematics
posted 03-26-04 05:47 PM EDT (US)   
YaY!, I have figured out a way to perform mathematical operations to unknown player attributes .

Summary for increasing your gold by half of your gold:

-Create an effect that increases P1's Variable0 by his gold (use the PA reference*)
-Put the effect in a trigger
-Create a condition: Player 1's Variable0 > 0
-Create an effect that increases P1's Variable1 by 1
-Create an effect that decreases P1's Variable0 by 2
-Put the condition and the two effects in a looping trigger.
-Create a condition: Player 1's Variable0 < 2
-Create an effect that increases P1's gold by Variable1 (use the PA reference again*)
-Put the condition and the effect in a trigger
-Check the "conditions true for" checkbox and increase it by 1

Now when you test your scenario, your gold will increase by half as much gold as you have. So if you have 100 gold, your gold will increase by 50.

Addition, Subtraction, and Multiplication are pretty easy...
For addition:
Create an effect that increases your gold by Variable0 (make sure you give an amount to Variable0 first)

For subtraction:
Create an effect that decreases your gold by Variable0 (make sure you give an amount to Variable0 first)

For multiplication:
Create an effect that increases your gold by your gold and add this to your trigger for as many times as you want to multiply it by, minus one. So if you want to triple an attribute, put the effect in your trigger two times.

Multiplying by a large number:
Similiar to division... Increase your gold by your gold and decrease Variable0 by 1. Set Variable0 to the amount that you want to times it by, minus one. So if you want to triple the amount of gold you have, set Variable0 to 2.

There is one problem: Division and multiplying by a large number both might take a long time to calculate (depending how big the numbers are). If you have 100 gold and want to increase it by half of it, it will take about 25 game seconds.

My head hurts now from all this thinking... and lack of sleep. I'll post a formula for getting the square root of an attribute later today or tommorrow.

*If you dont know what the PA reference is, click here:
http://empires.heavengames.com/cgi-bin/forums/display.cgi?action=st&fn=7&tn=973&st=recent&f=7,973,0,10

<edit> nevermind the square root, ittl be hard and I really dont feel like working at it right now =/. Maybe if someone needs it one day.

[This message has been edited by ZyN (edited 03-27-2004 @ 08:26 PM).]

Replies:
posted 03-27-04 03:21 PM EDT (US)     1 / 17  
Could u simplify by simple example?

.....................................
...............(\ /)................
..............(^.^)...............
.............<( < )...............
...............(/ (/................
...All American Bunny.....
posted 03-27-04 05:05 PM EDT (US)     2 / 17  
Increase variable1 by x amount for every time you decrease variable0 by y amount. Variable0 should be how much gold you have and variable1 will be the end result.

So if you want to increase your gold by half you would set variable0 to however much gold you have and then increase variable1 by 1 for every time you decrease variable0 by 2. After this is done you increase your gold by variable1.

If you want to increase your gold by 1/3 then you would set variable0 to however much gold you have and then increase variable1 by 1 for every time you decrease variable0 by 3. After this is done you increase your gold by variable1.

Note: The condition that it keeps checking to be true should be something like "P1's variable0 < z".
Z should be whatever number your decreasing variable0 by.
So if your decreasing variable0 by 2, then your condition should read: "P1's variable0 < 2". This is to make sure you get the closest possible answer and your variable1 doesnt rise uncontrollably.


Lets say you have two baskets and ten apples. Put the ten apples in basket #1, then put one apple into basket #2 for every two apples you take out of basket #1.

posted 03-27-04 05:32 PM EDT (US)     3 / 17  
I could make a comment if i knew what u were doing. I know alot about mathmatical attribute setting based on /#PA0001 methods, but what ur saying is a bit confused and not clarified by specific examples of how they could be used.

Quote:

Summary for getting half of your amount of gold:

Come on, don't tell me u can't see this as a totally ambiguous statement.



.....................................
...............(\ /)................
..............(^.^)...............
.............<( < )...............
...............(/ (/................
...All American Bunny.....

[This message has been edited by _o0XxX0o_ (edited 03-27-2004 @ 05:49 PM).]

posted 03-27-04 08:24 PM EDT (US)     4 / 17  
To find the efficiency of your army you could do this:

variable2(efficiency) starts at 100

If variable0(deaths) < variable1(kills) and variable0(deaths) > 0 then decrease variable0(deaths) by variable1(kills) and increase variable2(efficiency) by 10.

If variable0(deaths) > variable1(kills) and variable1(kills) > 0 then decrease variable1(kills) by variable0(deaths) and decrease variable2(efficiency) by 10.

Quote:

Come on, don't tell me u can't see this as a totally ambiguous statement.


Quote:

Now when you test your scenario, your gold will increase by half as much gold as you have. So if you have 100 gold, your gold will increase by 50.


I'll edit it so its a little more clear for the next person

I only recently came to these forums and discovered the whole #PA thing and I hadnt really given it too much thought until two days ago (when I started thinking up plans for one of my scenarios). If any person fluent with the editor were to sit and think about how to do math to their attributes, I'm sure they could figure it out too. I could have figured out how to increase the pop limit with triggers if I had sat and thought about it (after learning that increasing the pop limit increases the pop LIMIT, not the 'housing'). This thread is for all the people who don't already know how to do this (which I'm sure is the majority of them).

<edit> the efficiency could be used to reward the person with the best efficiency, or display statistics, or set a condition, etc..

[This message has been edited by ZyN (edited 03-28-2004 @ 01:13 PM).]

posted 03-28-04 02:49 AM EDT (US)     5 / 17  

Quote:

To find the efficiency of your army you could do this:

???????

It's kind of weird, increase the gold of the gold u have?

Are u trolling? or are u normally this clulessly ridged?


.....................................
...............(\ /)................
..............(^.^)...............
.............<( < )...............
...............(/ (/................
...All American Bunny.....

[This message has been edited by _o0XxX0o_ (edited 03-28-2004 @ 02:50 AM).]

posted 03-28-04 03:09 AM EDT (US)     6 / 17  
I understand you what you are doing (I have been practising with unit's variable a lot) but although I think it's very original, it has little practical use.
The idea is really good, but the fact that you are comparing P0 variable with P1 and they increase 1 and 2 per second has the problem os slowness as you said.
If you want to add the half of 10, it would be
1 - 8
2 - 6
3 - 4
4 - 2
5 - 0
You have 5, the half of ten, but it has taken 5 seconds (2.5 if you loop each 500ms).
Now imagine you have 1000 gold, or 10.000. It would be allmost impossible to calculate that 5.000 of gold in one scenario, or if it's, when you have the result then the player has forgot about it (if you bet for that, you can win the half of your gold - the player has 1000 of gold, he wins and after 8 minutes he receives 500 of gold...).

About multiplying, I think your method isn't practical too.
See, it's like computers. When the CPU has to calculate the multiplication of two numbers, it cannot say "lets see, 10x10, then lets add 10 to the result ten times". Why? Cause (according our teacher ) you DONT know how many cycles of clock it would need. When the CPU has to do an arithmetic op. it MUST know (well, the CPU doesn't, but the programmer must) how many cycles it would last.
So, how does a CPU multiply two numbers?
Exactly as you multiply two numbers on paper: first you multiply with the "less significant bit" (aka the righter number), then the second one, and so on until you reach the lefter number ("the most significant bit"). And you multiply per 10 each line.
The CPU do the same, it multiply the lsb (remember, it can be a 1 or a 0, as it's binary, so that multiplication is really easy), then the second lsb and it multiplies per 2 (again, it's binary, so muliplying per 2 is a displacement to the left, an easy operation) and so on. And then it sum all the results. So it only need x simple multiplications (where x is the amount of numbers) and one sum. So it needs x+1 operations. But with the "add method", if you want to multiply per 100 f.e., it would take 100 sums, 100 operations, and with the other method 4 operations.
However, can we implant that algorithm in Empires?
First, each cycle has at least 0.5 seconds so instead of doing 100 operations, doing 4 is an important saving.
However, Empires'trigger can only implant "elementary" operations, so for more complex it would take many cycles. And many cycles represent MANY time.
If you want to multiply 2 numbers, first we must isolate the first number, then the second, and so on. Can we do it? With one cycle I think it's impossible. Then we must multiplicate that isolated number with the entire cipher. As it isn't 0 and 1, we should do your system. Anyway for multiplying 999 it would take 27 cycles, instead of 999, so for large numbers it is still an advantage. We must have a counter that stores the position of the number. And add the same number of 0s (multiplying per 10). Perhaps (I haven't tested) we could do /*value0, but I don't think it would accept that as a 10 multiplier Imagine it does. Then it would take x cycles where x is the sum of all the number position. Hmmmm many cycles. But we are still saving many, so let's go on. Then we can sum all the results. It would take a few cycles, the first is to store the first result in one variable, and then add the following results in that variable. That's pretty easy.
And we have the multiplication result.
Is it worth the effort and time? As Empires hasn't got basic operations, we have had to create them with more elementary ones. We have saved many cyles FOR LARGE numbers, but we have wasted too many for LITTLE numbers. And that represent 0.5 extra seconds per cycle.
Conclusion:
except if you are using numbers smaller than 5, or you are very patient, your algorithm isn't worth. For larger numbers we could use the algorithm I exposed above, but doing it in Empires would be SUICIDE
So the only practical use of this is do "microoperations" with little numbers for, for example, using them for unit variables. Well, the option is here, then the designer has to think how to use it for a practical stuff.
The easiest solution: wait for SSSI to implement a trigger that allows you to do this operations in a few CPU cycles (miliseconds) in the next X pack
I am sorry for this suffocating post, as you can imagine I was VERY bored

[This message has been edited by Andres_age (edited 03-28-2004 @ 03:12 AM).]

posted 03-28-04 01:08 PM EDT (US)     7 / 17  
I have found several uses for it in my next scenario, I'll let you guys see it when(if :P) I finish it.

Good1 Andres... I have an idea on how to seperate the numbers for multiplication, I'm going to go see if it works .

I forgot a condition in my efficiency example... fixed now.

Quote:

Are u trolling? or are u normally this clulessly ridged?


I take it youve never or rarely used "units killed" as a condition before.

Some other things you could use it for:
1) casinos (win twice as much money as you bet, etc)
2) gain gold for every kill, lose gold for every loss
3) point system (points for kills/razes/etc, lose points for units lost/resources/etc)
4) Prices (things can get more or less expensive when you buy them)
5) Taxes (each citizen could pay you 1/4 of the resources that they collect)

posted 03-28-04 01:59 PM EDT (US)     8 / 17  

Quote:

Taxes (each citizen could pay you 1/4 of the resources that they collect)

Congrats, you have found a COOL use... I spent hours thinking how to do something like this in AoK

posted 03-28-04 02:33 PM EDT (US)     9 / 17  
1. just have triggers pay 150%

2. it's simpler to do a 2 trigger comparison with kills units lost with 2 variables

3. same as 2.

4. variable prices are a good use for /#PA..give a refund when each new unit is created, and/or disable tech till player has enough resources.

5. best use for ur mathmatic system. heres what i would do;

-condition; player x gold => unit variable0
-effect player x variable1 increase by 1
-effect player x variable0 increase by 4

the player x variable 1 will be 1/4 of the player's gold. Make a reverse trigger to decrease variable0 and var1 when player has less gold, and...

Make a reset trigger when the 1/4 taxes are paid.


.....................................
...............(\ /)................
..............(^.^)...............
.............<( < )...............
...............(/ (/................
...All American Bunny.....
posted 03-28-04 03:17 PM EDT (US)     10 / 17  

Quote:

I spent hours thinking how to do something like this in AoK


me too

Quote:

1. just have triggers pay 150%


You cant. Player-Attribute effects dont have the percent checkbox.

Quote:

3. same as 2.


depends on your point system.
posted 03-29-04 09:34 AM EDT (US)     11 / 17  
This is giving me a headache.

"Especially awe-inspiring is the fact that any single brain is made up of atoms that were forged in the hearts of countless stars billions of years ago... These atoms now form a conglomerate – your brain – that can not only ponder the very stars that gave it birth but can also think about its own ability to think and wonder about its own ability to wonder. With the arrival of humans…the universe has suddenly become conscious of itself. This, truly, is the greatest mystery of all." - Rama
posted 03-29-04 10:14 AM EDT (US)     12 / 17  
I knew it would give me a headache, so I never bothered beginning to read
also, the beginning post was rather long

Bah.
posted 03-29-04 04:44 PM EDT (US)     13 / 17  
This is probably the simplest example I can give you for the division:

Quote:

Lets say you have two baskets and ten apples. Put the ten apples in basket #1, then put one apple into basket #2 for every two apples you take out of basket #1.

The other three are pretty easy:

Quote:

For addition:
Create an effect that increases your gold by Variable0 (make sure you give an amount to Variable0 first)

For subtraction:
Create an effect that decreases your gold by Variable0 (make sure you give an amount to Variable0 first)

For multiplication:
Create an effect that increases your gold by your gold and add this to your trigger for as many times as you want to multiply it by, minus one. So if you want to triple an attribute, put the effect in your trigger two times.

\

--- Warning, if you thought any of the other stuff was confusing, dont read below! ---

Andres, my seperating the numbers idea worked . Though you might need alot of conditions (10 conditions for every 100 numbers). Heres what you do (to multiply food by wood):

Variable0 = food - 10 (make a condition to make sure the food => 10 and < 20)
Variable1 = wood - 10 (make a condition to make sure the wood => 10 and < 20)
Variable2 = 1

or..

Variable0 = food - 20
Variable1 = wood - 40
Variable2 = 2
Variable3 = 4

..etc

After seperating them youll need to multiply them together... to do this you will need another 8 conditions and a few more variables in order to accurately carry over the first digit (the "3" in 32).

15
x 45
____

five times five is 25... to seperate 25 into 2 and 5, youll need to do the above steps all over again and then store it in another variable which you will add to the answer of 5 x 1. After youve added that to five times one then youve somehow got to get the 7 next to the 5.

To get the 7 next to the five you would need to decrease the 7 by one for every time you increase ANOTHER variable by 10. This new variable will now be 70. Increase the 70 by the 5 and voila youve got the first line .

For the zero in the second line you would need to decrease the number next to the zero by 1 for every time you increase another variable by 10.

To make it even faster you should make sure that when you multiply the smaller numbers that you should multiply the larger number by the smaller number. (ie: adding 5 to 5 is easier than adding 2 to 2 five times).

All of this will be alot of work, but if getting a quick answer for a multiplication problem is important, then you now have a way to do it .

posted 03-31-04 07:28 AM EDT (US)     14 / 17  
Wov, great discovery! I had been thinking about how to separate the numbers, but I didn't think in that! Congrats!

So, let's see.
It would take 4 cycles in order to get the 5 from the 45.
Then multiplying 5 per 15 would take some more cycles:
you have to separate 5 from 15 (one cycle), multiply 5x5 (5 cycles, we have to sum), and multiplying 1 per 5 (one cycle). Then we have to multiply the result 5 per 10, so we get 50. Then we have to add 25 to 75. This is a special point. We could do a loop that adds 5 to 5 ten times (ten cycles) or we could find a way to "displace" the number to the left... adding 25 to 75 takes only 1 cycle.
Then we have to separate 4 from 5. Another special point.
we can use a counter to count the cycles it take to separate a 2 ciphers number, so that we can get the "4" directly when we separated the 5 from 45, and no more cycles would be needed!
Then we have to multiply 4 per 15. If we still got the 5 and the 1 separated, then multiplying 5x4 would take 4 cycles (if we optimize it to do only 4 cycles instead of 5, as you said!), and 4x1 would take only 1 cycle. Then we can displace the 1 to the left (or multiplying per 10) and add 5x4. Then we should displace that whole number. Multiply again per 10. And add the first number.
So it would take... 20 cycles if we find a way to displace a number. If not, and we have to multiply per 10, it would take... 50 cycles! So it would be faster if we add 45 to himself 15 times (15 cycles).
We could use both methods: if numbers are really small, we could multiply them adding to a variable. But if they are big (3 ciphers) then doing this method is faster.
Well, I don't know is someday I will see this in a scenario, but at least I am discovering really interesting things about Empires!!

posted 03-31-04 04:49 PM EDT (US)     15 / 17  
That wasnt really what I was saying, but that method is alot easier to create :P. Cant believe I didnt think about that. So with your improvement we will be able to figure out even the largest numbers with only maybe 20 conditions instead of hundreds.

Let me recalculate the number of cycles (in the improved method), just to make sure...
1 to seperate the 1 and 5 in 15
4 to seperate the 4 and 5 in 45
4 to multiply 5 times 5
2 to seperate the 2 and the 5 in 25
1 to multiply 5 times 1
7 to change 7 to 70

3 to multiply 5 times 4
2 to seperate the 2 and 0 in 20
1 to multiply 4 times 1
6 to change 6 to 600

We must wait four cycles to split all the original numbers, then we must wait another six to multiply the numbers, then we must wait seven to get the answers for the two lines. Finally, we will add the two lines together and send a chat message or whatever else for the final cycle. This totals up to 18.

Quote:

45 to himself 15 times (15 cycles).


This is 14 cycles, not 15 (this is also how you got 20 instead of 18 :P ). If you add 45 to itself 15 times you will get 720 (wrong =/ ). You must add 45 to itself 14 times because one 45 is already there, if you add 45 to itself 14 times you will get 675(correct).

Quote:

displace a number.


Quote:

youve somehow got to get the 7 next to the 5.

To get the 7 next to the five you would need to decrease the 7 by one for every time you increase ANOTHER variable by 10. This new variable will now be 70. Increase the 70 by the 5 and voila youve got the first line .

While writing this post, I think I may have just figured out an even easier way to do this using a new math trick I just figured out (too bad they dont teach it in school).

Take 24 x 36:
-The 24 is basically just 20 + 4
-The 36 is basically just 30 + 6
-Now we can multiply the 6 by the 4 and the 20... and the 30 by the 4 and the 20.
-After this is done we add the two numbers together on each line and then add the two lines together.

This will only take 20 cycles and it will be alot easier to do. 15x45 will take only 10 cycles. I'll see if I can shorten it further or find another new method tommorrow .


I guess I'll havto write up some step by step instructions one day in order to make it easier for everyone who has absolutely no idea what were talking about :P.
I'd probably use the instructions too... I'm gonna end up killing my brain thinking about this so much.

posted 04-01-04 06:30 AM EDT (US)     16 / 17  
Wov wov wov!!!
I have great news...
From the beginning we are supposing that multiplying a number is to add the number x times...
For this we are using a "while" condition.
Something like this
While x>0 loop
number:=number+1;
x:=x-1;
end loop; -- yeah, I know, it's ADA!!!

In a programming language it's ok. Every cycle takes miliseconds. But in Empires it takes 0,5 seconds!
Unfortunately we cannot change that: at least it will take 0,5 seconds. We have been trying to reduce that time, that is, optimizing this method.
HOWEVER there's a simpler method.
A looping trigger takes 0,5 seconds, but every effect takes 0,01 seconds or less.
So, instead of doing one simple loop that adds the number per 1, 2, 3 or 10 (if its 11-9999 we can descompose it in simpler ones), why not doing 10 triggers that multiplies x DIRECTLY?
I mean, if you want to multiply x per 7, just do
Effect: put x into player variable 0.
Effect: player variable 1 is 0.
Effect: activate trigger "multiply per 7".

Trigger "multiply per 7"
Condition: always true
Effect: add variable 0 to 1
Effect: add variable 0 to 1
Effect: add variable 0 to 1
Effect: add variable 0 to 1
Effect: add variable 0 to 1
Effect: add variable 0 to 1
Effect: add variable 0 to 1

At the end of the trigger we will have in player variable 1 7x. And it would have taken only... 1 cycle!!!!
We can do 10 triggers, "multiply per 1", "multiply per 2", etc.
And if the number is greater than 10, we can separate the ciphers with a few cycles and continue with the algorythm we already have. But multiplying any number per one cipher would take only 1 cycle. That is an IMPORTANT saving.
We can do 999 triggers, instead of 10: multiplying per 100, multiplying per 543, etc but as you can imagine, it's crazy: you have to put 543 effects in the trigger, and you will lost in the middle :P But it can be done, although it may produce some lag if the number is really greater. So I think the best is only to do 10 triggers, and descompose big numbers into ciphers.
But as I said, we will save LOADS of cycles!!

posted 04-03-04 05:34 PM EDT (US)     17 / 17  
Thats kinda what I suggested in my first post :P. But I hadnt really though about adding it to our method after you showed a way to do it with less work. Maybe we could save a few cycles with this.

I'm not really in the mood to experiment and search for an easier way right now (or write up the step-by-step instructions), I've got a lot of things to do =/. Maybe in a day or two.

Empires Heaven » Forums » Scenario Design Discussions » Attribute Mathematics
Top
You must be logged in to post messages.
Please login or register
Hop to:    
Empires Heaven | HeavenGames