ok forum, please review the below algorithm for determining if a unit ought to anarchy charge (work in progress)
Precheck (ie if liable to charge at all):
1) If unit routing, fragmented, in close combat, pursuing, or off playable area, it cannot anarchy charge
2) check if target exists, is valid, is within charge range, in line of sight, and otherwise a valid charge based on pre existing algorithms for that sort of thing from the vanilla AI (i.e. cannot charge across diagonal that is occupied by two units already in combat, that sort of thing)
Chance to Anarchy Charge function:
*all percents are like points out of 100 going up and down, NOT multiplying the chance to charge by 1.x where x is the percent. It's just adding up.
*charge chance and anarchy charge chance both mean chance to anarchy charge here, i used them interchangeably
1) set base chance to charge value from 'Anarchic' column from squads file (something like 60,40,20, and 0 for different unit types, or whatever)
2) various bits of boilerplate code to acquire yours and the enemy's facing, location etc...for determining combat margins if the combat were to occur, disparities in relative shooting capacity, terrain disorder, etc...the raw material values for making your comparisons. This is not really a step so much as a preparation.
[FOG1 anarchy type rules checks follow in number 3]
3) a) Foot will not anarchy charge out of their own protective terrain, b) no unit will anarchy charge into protective terrain or against elephants (dunno about the into river banks bit...), c) no unit will anarchy charge if doing so would cause them to be disordered by the terrain (accounts for diff amounts of disorder based on unit type), d) medium foot (including warriors, bowmen, mob, medium foot), if in rough or difficult terrain, will not anarchy charge an enemy in the open, and e) no unit will anarchy charge lights (definitely up for debate, wasn't sure if this was exactly part of the original rules, but would help make them less annoying).
4) determine relative combat and shooting advantages (close combat margin and shooting margin), to be used for later comparisons (also more like a preparation than a step)
5) if charger has less than 50% chance of winning, decrease charge chance by 10%. If a much less than 50% chance of winning, decrease charge chance by an additional 20% (30% down total by this point)
6) if enemy is ranged and you are not, increase charge chance by 10%
7) if you are ranged, regardless of if enemy is, decrease charge chance by 20% (would be irrelevant if charge chance for shooters is 0 to begin with in all cases, but might end up only being relevant for shooty lancers)

if at major shooting disadvantage, whether ranged or not, and not at too great of a combat disadvantage, increase charge chance 20% (ie increase charge chance, even if at a little bit of disadvantage (or better), if you are getting shot at)
9) if marginal combat advantage, increase charge chance 10%, and if large combat advantage, increase charge chance 20% (not additional 20%, either or)
10) if you are foot and the enemy is mounted shock, then decrease anarchy charge chance by 60%
11) if you are mounted and steady and the enemy is fragmented, then increase charge chance 10%
12) if you are better off being charged than initiating the charge, and you have shooting advantage, then greatly decrease charge chance (by dividing it by 5). I think this is basically to prevent shooty lancers from anarchy charging when they ought to keep shooting and waiting to receive a charge.
13) if outside of general's command range then increase chance to anarchy charge by 20%
14) if mounted and the target are non fragmented pikes or spears then decrease charge chance to zero
15) if charging will involve opening yourself up to flank threat then decrease chance to anarchy charge down to zero.
16) do not allow anarchy charge chance to exceed 90% (ie always retain a random element)
thoughts on the numbers? The numbers are just made up by me and not tested at all. What should the different points values be for different conditions? new factors I am missing?