cpu_manager:GetDefensiveBuildingsCostAt( cpu_manager.player_stats, self.defend_pos, 10 )
This is doing nothing. It should read
my_army_cost = my_army_cost + cpu_manager:GetDefensiveBuildingsCostAt( cpu_manager.player_stats, self.defend_pos, 10 )
Quite a difference as defensive buildings are now added to decide wether to defend at a certain position.