/// <summary> /// Calculates units of given region that are left to attack. /// </summary> /// <param name="region">Given region.</param> /// <param name="deployingPhase">Deploying based on which it will be calculated.</param> /// <returns></returns> public int GetUnitsLeftToAttack(Region region, Deploying deployingPhase) { IEnumerable <int> deployRegionEnumerable = from tuple in deployingPhase.ArmiesDeployed where tuple.Region == region select tuple.Army; IEnumerable <int> attackRegionEnumerable = from attack in Attacks where attack.Attacker == region select attack.AttackingArmy; // nothing was deployed in this region if (!deployRegionEnumerable.Any()) { // nothing was attacked with if (!attackRegionEnumerable.Any()) { return(region.Army - Region.MinimumArmy); } return(region.Army - attackRegionEnumerable.Sum() - Region.MinimumArmy); } // nothing was attacked with if (!attackRegionEnumerable.Any()) { return(deployRegionEnumerable.Sum() - Region.MinimumArmy); } return(deployRegionEnumerable.Sum() - attackRegionEnumerable.Sum() - Region.MinimumArmy); }
public override ILinearizedRound Linearize() { Deploying deploying = new Deploying(new List<Deployment>()); Attacking attacking = new Attacking(new List<Attack>()); int index = 0; while (true) { // true if anything in this round of cycle was added // false if nothing happened => everything was solved => can break out bool didSomething = false; foreach (GameTurn round in Turns) { if (round.Deploying.ArmiesDeployed.Count > index) { Deployment armyDeployed = round.Deploying.ArmiesDeployed[index]; deploying.ArmiesDeployed.Add(armyDeployed); didSomething = true; } if (round.Attacking.Attacks.Count > index) { Attack attack = round.Attacking.Attacks[index]; attacking.Attacks.Add(attack); didSomething = true; } } if (!didSomething) { break; } index++; } return new LinearizedGameRound(deploying, attacking); }
public LinearizedGameRound(Deploying deploying, Attacking attacking) { Deploying = deploying; Attacking = attacking; }
public override void Reset() { Deploying.ResetDeploying(); Attacking.ResetAttacking(); }
public GameTurn(Player playerOnTurn) : base(playerOnTurn) { Deploying = new Deploying(new List <Deployment>()); Attacking = new Attacking(new List <Attack>()); }
public GameTurn(Deploying deploying, Attacking attacking, Player playerOnTurn) : base(playerOnTurn) { Deploying = deploying; Attacking = attacking; }