The first and most important lesson of warfare is that the first casualty of any given battle is the plan. No matter how well-thought out your strategy, how overwhelming your numerical advantage, or how well-trained your troops are, there will always be factors you did not - could not - consider. These range from misjudging the terrain, to overestimating the fighting capacity of your soldiers, to simply not accounting for individual heroics from enemy soldiers.
All of these factors are combined into a single random augmentation known as the X Factor. This simulates all of the above, and allows for outnumbered and outgunned regiments to pull last-minute victories from the jaws of defeat, and keeps all commanders, no matter their experience, on their toes.
As you cannot accurately plan for each battle's outcome - make sure you always have a plan B.