The logic above is wrong...

The three lines where "=55" is repeated, should NOT be so, because **at that point** the code calculates the CUMULATIVE value of each strategy, NOT the actual value of each strategy itself! So the new values should be ascending, not equal.

So, yes, if it is so, as long as the randomiser value is below or equal to 55, ONLY STRATEGY ONE will be chosen.

Else, (>55) it will always choose strategy 4.

The idea is:

1] Calculate the BASIC probability of each strategy, based on map size and optionally, closer enemy distance.

2] Modify the basic probability, based on closer enemy race, or other factors.

3] Add probabilities so that to get cumulative values, and choose based on that.

----------------------------------------

*More thoughts...*

First, let me say that I am **NOT** using that exact logic I described above, for the races I code.

I prefer a different approach in each, and I adapt and changes the code based on each race's needs.

Even so, the idea above is:

1] The probability of each build program is calculated initially, based on map size, and then modified by closest enemy. For example, in the Eldar strategy you posted (which is NOT generic, but highly specialised, for strategy 4)

if (sMapSize == "small" or iClosestEnemyDistance <= 100) then
iBuildProgram1 = 34
iBuildProgram2 = 33
iBuildProgram3 = 33
iBuildProgram4 = 0
elseif (sMapSize == "large" and iClosestEnemyDistance >= 100) then
iBuildProgram1 = 0
iBuildProgram2 = 0
iBuildProgram3 = 0
iBuildProgram4 = 100
else
iBuildProgram1 = 0
iBuildProgram2 = 0
iBuildProgram3 = 0
iBuildProgram4 = 100
end
-- Modify probabilities according to the closest enemy player
local oEnemy = cpu_manager:FindClosestEnemyPlayer(false)
local sEnemy = oEnemy:GetPlayerRaceName()
if (sEnemy == "space_marine_race" or "chaos_marine_race") then
iBuildProgram2 = iBuildProgram2 + 0
iBuildProgram3 = iBuildProgram3 - 0
elseif (sEnemy == "guard_race" or sEnemy == "tau_race" or sEnemy == "ork_race") then
iBuildProgram1 = iBuildProgram1 - 0
iBuildProgram2 = iBuildProgram2 + 0
iBuildProgram3 = iBuildProgram3 - 0
end

Say we have a small map, and the first enemy is closer than 100. The prorgam will follow the first IF, and set the original values thus:

iBuildProgram1 = 34
iBuildProgram2 = 33
iBuildProgram3 = 33
iBuildProgram4 = 0

2] Then, based on closest enemy, it will modify the values. Your code was:

-- Modify probabilities according to the closest enemy player
local oEnemy = cpu_manager:FindClosestEnemyPlayer(false)
local sEnemy = oEnemy:GetPlayerRaceName()
if (sEnemy == "space_marine_race" or "chaos_marine_race") then
iBuildProgram2 = iBuildProgram2 + 0
iBuildProgram3 = iBuildProgram3 - 0
elseif (sEnemy == "guard_race" or sEnemy == "tau_race" or sEnemy == "ork_race") then
iBuildProgram1 = iBuildProgram1 - 0
iBuildProgram2 = iBuildProgram2 + 0
iBuildProgram3 = iBuildProgram3 - 0
end

... Which does NOT modify the probabilities at all!!! Why so??? If you do not modify, then simply remove this part of the code

**Edited by Gambit, 17 March 2019 - 11:30 AM.**

-In search of Papasmurf...