private static bool MakeSweetestMoves(Universe uni, IEnumerable <AttackPlan> attackPlan) { bool attackPerformed = false; Planet Defender = null; Planet agressor = null; foreach (var attack in attackPlan) { agressor = attack.Source; if (agressor.PlanetID == 2) { } if (agressor.AttackMovesAllowed) { if ((agressor.AttackForce >= attack.ShipCount && agressor.CanSurviveIncommingAttack) || agressor.IsLost) { Defender = attack.Target; bool domination = Universe.IsDominating || attack.DominationMove; if (Defender.IsAttackable || domination) { //create bias towards planets for which we initiate battle Universe.AddToWishList(Defender); uni.MakeMove(agressor, Defender, attack.ShipCount); attackPerformed = true; } } } } return(attackPerformed); }
protected override void DefendOnwedPlanets() { foreach (Planet onwedPlanet in OrderOwnAttackedPlanetsFirst()) { #region Try defend any owned planets. bool shouldDefend = onwedPlanet.IsUnderAttack && !onwedPlanet.CanSurviveIncommingAttack; if (shouldDefend) { if (onwedPlanet.AttackForce > 0 && onwedPlanet.ShipsRequiredToSurviveAttack == 0) { shouldDefend = false; } else { IEnumerable <AttackPlan> defensePlan = BuildDefensePlan(onwedPlanet, 1000); if (onwedPlanet.IsLost) { foreach (var route in Universe.TravelMap[onwedPlanet.PlanetID]) { if (route.DistanceInTurns <= onwedPlanet.LostAfterNumberOfTurns) { Planet target = currentUniverse.AllPlanetsOnPlanetId[route.TagetPlanetId]; if (target.IsNeutral && target.MaxDesertersAllowed < onwedPlanet.NumShips) { currentUniverse.MakeMove(onwedPlanet, target, onwedPlanet.NumShips); break; } } else { break; } } //Recapture ! Universe.AddToWishList(onwedPlanet); } else { foreach (AttackPlan armada in defensePlan) { currentUniverse.MakeMove(armada.Source, armada.Target, armada.ShipCount); armada.Source.AttackMovesAllowed = false; } onwedPlanet.AttackMovesAllowed = false; } } } #endregion } }
private bool MakeSweetestMoves(Universe uni, IEnumerable<AttackPlan> attackPlan) { bool attackPerformed = false; Planet defender = null; double bestSweetness = Double.MaxValue; foreach (var attack in attackPlan) { defender = attack.Target; if (bestSweetness == Double.MaxValue) { bestSweetness = attack.Sweetness; } else { double relativeSweetness = attack.Sweetness / bestSweetness; if (relativeSweetness < 0.20) { // Compared to the moved that we like, this is really bad. // So instead of making a very bad move, we will just end our turn. break; } } foreach (AttackPlanParticipant order in attack.Participants) { Planet agressor = order.Source; if (agressor.AttackMovesAllowed) { bool domination = currentUniverse.IsDominating || attack.DominationMove; bool canConquer = agressor.DoesNotChangeOwner && Math.Max(defender.ShipsRequiredToSurviveAttack, defender.AttackForce) < agressor.AttackForce; if (domination || agressor.IsLost || canConquer) { if (defender.IsAttackable || domination) { uni.AddToWishList(defender); //uni.MakeUnsafeMove(agressor, Defender, attack.ShipCount); uni.MakeMove(agressor, defender, agressor.AttackForce); attackPerformed = true; } } } } } return attackPerformed; }