/// <summary> /// Performs a fight between two army compositions. /// Updates the experience of the winner army. /// </summary> /// <param name="winnerArmyComposition"></param> /// <param name="loserArmyComposition"></param> /// <returns></returns> public static ArmyComposition Fight(ArmyComposition winnerArmyComposition, ArmyComposition loserArmyComposition) { var powerDifference = winnerArmyComposition.ArmyPower() - loserArmyComposition.ArmyPower(); //The losses have the square root dependency. var mortalityRate = Math.Sqrt(powerDifference / winnerArmyComposition.ArmyPower()); //The experience increased quadratically, based on the relative power of armies. //Quadratic dependency mainly to decrease the huge role of the experience at the final part of the game. var experienceIncrease = 1 + Math.Pow(loserArmyComposition.ArmyPower() / winnerArmyComposition.ArmyPower(), 2); return(winnerArmyComposition.ArmyCompositionAfterFight(mortalityRate, winnerArmyComposition.Experience * experienceIncrease)); }
/// <summary> /// Checks that first army is more powerful than second. /// </summary> public static bool IsFirstWinner(ArmyComposition firstArmyComposition, ArmyComposition secondArmyComposition) { var firstArmyPower = firstArmyComposition.ArmyPower(); var secondArmyPower = secondArmyComposition.ArmyPower(); return(firstArmyPower >= secondArmyPower); }