Implementing flexible logic?

Blitz3D Forums/Blitz3D Programming/Implementing flexible logic?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

All,
I'm after some suggestions as to how you'd tackle the following problem. I've simplified my idea and written code in pseudocode to hopefully make my problem easier to understand.

Lets say you have 2 random choices in your game logic.

eg.
50% chance enemy attacks
50% chance enemy waits

Coding that is easy.

Choice = random(100). 
If Choice < 50 then attacks
else if choice > 50 then waits.



But then you want to add some dynamic modifiers. eg. If game has gone on for too long then you want to increase the chance of attack.

You could code this like
Choice = random(100)
if game time = too long then
     If Choice < 80 then attacks
     else if choice > 20 then waits.
else
     If Choice < 50 then attacks
     else if choice > 50 then waits.
end if


but if you start having lots of modifiers, coding the whole tree would get difficult. What I'm thinking will hopefully be an easier solution, but I'm not sure how to code it nicely. What I'm thinking is

Chance_of_attack=50
Chance_of_wait=50

if gametime=too long then Chance_Of_Attack += 30

Choice = rand (Chance_of_Attack + Chance_of_wait)
if Choice < Chance of Attack then attack
else
Wait
[code]

Easy enough, but if you then want to add more modifiers based on conditions (eg. chance_of_randomly_exploding, chance_of_turning_blue) you'll end up with
[code]
Choice = rand (Chance_of_Attack + Chance_of_wait + ...)
...
if Choice > (Chance of Attack + chance_of_wait + chance_of_blue) &&  Choice < (Chance of Attack + chance_of_wait + chance_of_blue + Chance_of_randomly_exploding) then ...


which will get VERY messy! Any ideas how to make this cleaner? Sorry if my explaination is confusing!!!