private void PlayDeploying(LinearizedGameRound round) { Deploying deploying = round.Deploying; foreach (var deployedArmies in deploying.ArmiesDeployed) { Region region = game.Map.Regions.First(x => x == deployedArmies.Region); region.Army = deployedArmies.Army; } }
private void PlayAttacking(LinearizedGameRound round) { var attacks = round.Attacking.Attacks; foreach (Attack attack in attacks) { // TODO: real calculation according to rules // get real attacker Region attacker = game.Map.Regions.First(region => region == attack.Attacker); // if attacking region changed owner, cancel attack if (attack.AttackingPlayer != attack.Attacker.Owner) { continue; } // get real defender Region defender = game.Map.Regions.First(x => x == attack.Defender); // situation might have changed => recalculate attacking army int realAttackingArmy = Math.Min(attack.AttackingArmy, attacker.Army); // if they have same owner == just moving armies if (defender.Owner == attacker.Owner) { // sum armies defender.Army += realAttackingArmy; // units were transfered attacker.Army -= realAttackingArmy; } // attacking else { // calculate defending army unis killed int defendingArmyUnitsKilled = GetUnitsKilled(realAttackingArmy, defender.Army, Global.AttackingUnitWillKillProbability); // calculate how many attacking army units were killed int attackingArmyUnitsKilled = GetUnitsKilled(defender.Army, realAttackingArmy, Global.DefendingUnitWillKillProbability); // attacker units were transfered attacker.Army -= realAttackingArmy; // army that survived as defender int remainingDefendingArmy = defender.Army - defendingArmyUnitsKilled; // army that remains after units being killed int remainingAttackingArmy = realAttackingArmy - attackingArmyUnitsKilled; // if region was conquered if (remainingAttackingArmy > 0 && remainingDefendingArmy == 0) { // move rest of the units remainingDefendingArmy = remainingAttackingArmy; // region was conquered defender.Owner = attack.Attacker.Owner; // cuz of negative units defender.Army = remainingDefendingArmy; } // none of the attackers survived else if (remainingDefendingArmy == 0) { remainingDefendingArmy = 1; defender.Army = remainingDefendingArmy; } // region was not conquered else { // send rest of attacking units back attacker.Army += remainingAttackingArmy; // defenderArmy = what survived defender.Army = remainingDefendingArmy; } } } }