Optimization of the enemy detection mechanism

The first part of this video from the SOTL.13 Underrated Design Choices in AoE2 ,It is mentioned that when soldiers attack, they will calculate and prioritize attacking units that are easy to defeat.

However, the enemy detection mechanism places too much emphasis on individual victories and defeats. It is useful in small-scale battles, but since small-scale battles are all controlled manually, it is not very useful. In large-scale battles, its drawbacks become obvious: each individual unit prioritizes attacking easy targets, but there are too many units, resulting in a lot of time wasted on pathfinding.

Therefore, two mechanisms are added: one is to detect the number of enemy troops around, and attack nearby enemies if there are many; the other is to fight back immediately when being attacked while pathfinding. I’ve seen too many battles where units took damage for no reason due to their individual enemy detection mechanisms.