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

The University

Hop to:    
Welcome! You are not logged in. Please Login or Register.No replies
Age of Kings Heaven » Forums » The University » Usage of the Chance condition
Topic Subject:Usage of the Chance condition
posted 02-19-18 00:54 AM CT (US)         

The Chance Condition


I feel like this is the most obscure condition, partly because its behavior is a bit erratic. I'm here to make it a bit more translucent. I've mapped the varying performances of the chance condition so as to enable you to make better predictions in different setups and design better gameplay mechanics when creating scenarios. Specifically, how does the chance condition behave:
- With different values (straightforward)
- At different speeds (irrelevant)
- With different timer conditions (relevant!)
- by stacking chance conditions (relevant!)
- if used as a looping activator/generator/spawn trigger. (relevant!)

At the end of this post, you can also see the data I've gathered and a summation. Let's skip straight to the factoids...


- The chance condition takes integer values [0-100] (real quick).
- No negative values. (no shit, sherlock!)
- These integer values stand for percentages (probability, m'kay?).

The performance of the chance condition varies over different values used and not just because smaller values are less reliable than bigger ones in the same number of iterations. Here's an image (x-axis are chance values in percentage, y-axis is the average deviation from expected values, over all test setups):

A rough approximation: There can be 4-10% differences in performance for different values. The average deviation for 2% tests shouldn't be that much lower than for 5%, nor should the average '5% deviations' be that much higher than the 10% ones, nor the 10% ones fo... you get the point. I'm gonna do some more thorough testing later on (let these setups run for a night) to see how each integer behaves over 30000 iterations (that's 8h20m worth of testing). If those tests display the same discrepancies, you can be damned sure that this chance condition doesn't behave like a regular probability 'modifier'.

Game Speed

The game speed does not have any bearing on effects produced when using the chance condition. As a modifier on its own, it is statistically irrelevant at all speeds. To show you how irrelevant, my tests involving gamespeed 1 had -5.02% deviation from predicted number of effects on average and my tests involving gamespeed 1.5 had -5.84% deviation from predicted effects on average. This is the approximate case for all speeds. I've tested all of them, but I didn't include all speeds in the tables, since that would be overkill (and irrelevant anyway). However, at x4 and x8 speeds, when you're pairing or chaining triggers (f.e. a spawning trigger based on chance activation trigger), you may get less effects than your predictions based on probabilistic trigger logic. Unit tasking and/or walking speeds (to get out of the spawn area) are sometimes adversely affected by the highest Game Speeds and these chaotic effects stack! The following example is both exception and rule:

TRIGGER I [looping]
create Arbalest in area A
TRIGGER II [looping]
chance 95 (95% or 0.95)
task unit Arbalest from area A to [any other location]

This is an infinite spawn point for Arbalest that spawns an arbalest roughly 19 out of 20 times based on logic. In practice, however, because the Arbalest takes some time to move from area A to whatever the target location is in trigger II, at any game speed the Arbalest fails to respond adequately fast enough (something to do with the command/action stack order in the engine I guess) and the whole mechanic occasionally loses 1s and thus 1 effect was not produced, regardless of the chance (notice performance discrepancy on spreadsheet). With an added 2s timer condition in TRIGGER II, it does considerably better, as we would expect since the unit has more time to move. What we don't expect however, is that this whole mechanic now, with an added 2s timer, performs BETTER at 1.5 speed [8%error] (normal) than at 1 speed [14%error] (slow). Not sure why that is, except maybe that the devs maybe focused on testing for 1.5 speed? Luckily, normal speed is usually what we aim for, right? More on this in the following point... timer conditions!

The not so final countdown

While impossible to test for all cases here, I can make these claims based on my tests:
- Different timer conditions give different effect-producing behaviors:
- In cases where one trigger uses the chance condition in a self-contained manner,no timer is slightly better than 1s timer and 1s timer is significantly more reliable than the 2s timer.
- In cases where multiple triggers are chained in ways that lend themselves to cascading failure (like the spawn mechanic discussed above), no timer = 1s timer and the 2s timer might perform better.
- As a general rule, maybe remember that the 2s looping timer generally performs sub-optimal (~15% error).

Average errors for simple effects (4 different setups)
No timer condition used with chance: 0.8%
1s timer condition used with chance: 1.23%
2s timer condition used with chance: 15.25% (!)

Average errors in my only multiple trigger test-case
No timer condition used with chance: 44.24%
1s timer condition used with chance: 44.31%
2s timer condition used with chance: 11.16% (!)

As you can see, whether you're using one chance-based trigger or chaining triggers in a chance-based mechanic, the difference between using 'no timer' and a 1s timer is statistically irrelevant. The difference between those and a 2s timer are, however, very significant.

Stacked? Likely! Hood.

P(A and B) = P(A) * P(B)! In plain English: you can have multiple chance conditions to have them multiplied! Why would this be useful?
- To get non-integer percentages for finely tuned tweaking!
- To get even smaller chances than 1/100. (whait, isn't that the same as my previous point? Oh, well.. just pretend like there's a lot more benefits to having multiple chance conditions)
- I've only tested .5 percentage differences, since gathering data that is statistically relevant for smaller values takes too much time. I'm also pretty sure you can keep stacking chances (for that extremely rare 'divine armor' (+2500hp, +200/+200) you never want anyone to have).

If I wasn't clear enough in the previous paragraph, let me rephrase: When combining multiple chance conditions in one trigger, the different values are multiplied as follows:
cond A = 33 (-> 0.33)
cond B = 1 (-> 0.01)
A*B = 0.33*0.01 (chance of an effect = 0.33%)

Note: Odd enough, as opposed to the 1s timer usage with a double chance condition (f.e. 100 chance and 50 chance), using 2s timers with a double chance condition (f.e. 100 and 50), you're actually getting 100 + 50 / 2s --> 75% per second, not 25% or (1*0.5)/2, keep that in mind. I expected the chances to multiply, as you would for calculating the probability of two independent events happening based on their probabilities. P(A and B) = P(A) * P(B), but not in hyperosecond-timed wololo-land! Or I'm missing something and being very thick here. Most probable!

Effects affect effects?

I've only tested:
- tribute (to test a non-unit stat)
- attack modifier (for the sake of modifying a unit stat)
- task object (for the sake of having an effect that is not modifying stats and to see how trigger combos relate to predicted effects)

There is no reason to believe different effects affect the chance performance whatsoever. With the exception, of course, of effects that in themselves alter the behavior of your effect-producing triggers (like the spawn mechanic mentioned earlier)


So, I hope this clears things up for people. Let me know if you want more information on something specific concerning the chance condition or have suggestions/comments/requests concerning the source material. If you didn't understand something in here, it's probably because I'm both more than a little crazy and a little lazy. You may have heard this before but it's not you, it's me.

Two last things, because this may not be apparent and/or self-evident:

I. A look at the 'effects over chance%' graph:

I wanted to show this graph, an analysis of produced effects in all the tests I've done @ different speeds and timer conditions, to demonstrate that the chance condition is not a 'one size fits all' kinda condition. Different setups and different goals require tweaking the chance condition. As with any properly balanced trigger-magick, a lot of testing is required if you want to be sure the number of effects accrued over time matches what you want it to be. However, most of the anomalous behavior has already been discussed in this post, so based on what I've researched so far, this post and my source material, I'm sure you're well on your way to use and explore the chance condition with confidence!

II. A Look at the deviation graph (from my spreadsheet):

I wanted to show these graphs to demonstrate that for smaller chance values, you will want to use a larger number of iterations if you want the produced effects to match the intended ones. On the other hand, if you want more chaotic effect production, you can have many smaller chances in separate triggers do the same thing. Using the chance condition in one or fewer iterations for game-deciding effects is not advised, as that would not be a balanced approach. (really, GL252?) Well, yes. Secondly, the white graph displays all tests used (t = tribute, m = modify attack, s = spawn; first "1" or "h" for one-and-a-half = gamespeed; "no", second"1" or "2" = timer condition) and their respective deviations. Each colored line from red to cyan represents the chance values used from 1 to 100. It clearly shows that some setups are more reliable than others and that, That is all! Have a nice day!

Sources (reproducible tests):

I. My calculations (you can view, comment & download):
II. My test environments: (links to 3 example test-case scenarios, compressed files)

Check me out on Steam: GL252 I'm very slowly building a scenario and eyecandy map portfolio.

[This message has been edited by GL252 (edited 03-04-2018 @ 01:06 AM).]

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

Hop to:    

Age of Kings Heaven | HeavenGames