Exemplo n.º 1
0
        public int CompareDistanceToTargetPlanetLT(Planet planet1, Planet planet2)
        {
            if (TargetPlanet == null) throw new ArgumentNullException("planet1", "Target planet is not defined!");
            if (planet1.PlanetID() == planet2.PlanetID()) return planet1.PlanetID() - planet2.PlanetID();

            int result = (Context.Distance(planet1, TargetPlanet) - Context.Distance(planet2, TargetPlanet));
            if (result == 0) result = planet2.GrowthRate() - planet1.GrowthRate();
            if (result == 0) result = planet1.PlanetID() - planet2.PlanetID();

            return result;
        }
Exemplo n.º 2
0
 public Planet GetFutureState(int numberOfTurns)
 {
     FillFutureStatesIfNeeded();
     if (numberOfTurns > TurnsCount)
     {
         Planet futureState = new Planet(futureStates[TurnsCount]);
         if (futureState.Owner() <= 0) return futureState;
         futureState.NumShips(futureState.NumShips() +
                              futureState.GrowthRate() * (numberOfTurns - TurnsCount));
         return futureState;
     }
     return futureStates[numberOfTurns];
 }
Exemplo n.º 3
0
        public override List<MovesSet> RunAll()
        {
            List<MovesSet> setList = new List<MovesSet>();

            myPlanet = Context.MyPlanets()[0];
            enemyPlanet = Context.EnemyPlanets()[0];
            enemyDistance = Context.Distance(myPlanet, enemyPlanet);

            int canSend = Math.Min(myPlanet.NumShips(), myPlanet.GrowthRate() * Context.Distance(myPlanet, enemyPlanet));

            Planets neutralPlanets = Context.NeutralPlanets();
            Planets planets = new Planets(Config.MaxPlanets);
            planets.AddRange(neutralPlanets.Where(neutralPlanet => (Context.Distance(myPlanet, neutralPlanet) < Context.Distance(enemyPlanet, neutralPlanet)) && neutralPlanet.GrowthRate() > 0));

            setList.Add(BruteForce(planets, canSend));
            return setList;
        }
Exemplo n.º 4
0
 public int CompareGrowsRateGT(Planet planet1, Planet planet2)
 {
     int result = (planet2.GrowthRate() - planet1.GrowthRate());
     if (result == 0) result = planet1.PlanetID() - planet2.PlanetID();
     return result;
 }
Exemplo n.º 5
0
		public override Moves Run(Planet targetPlanet)
		{
			Moves moves = new Moves();

			if (targetPlanet == null) return moves;

			Planets nearestPlanets = Context.GetClosestPlanetsToTargetBySectors(targetPlanet, Context.MyPlanets());
			//Context.MyPlanets();
			//MyPlanetsWithinProximityToPlanet(planet, Config.InvokeDistanceForInvade);););
			if (nearestPlanets.Count == 0) return moves;

			if (nearestPlanets.Count > 1)
			{
				Comparer comparer = new Comparer(Context) { TargetPlanet = targetPlanet };
				nearestPlanets.Sort(comparer.CompareDistanceToTargetPlanetLT);
			}

			foreach (Planet nearestPlanet in nearestPlanets)
			{
				int canSend = Context.CanSendByPlanets(nearestPlanet, targetPlanet);
				if (canSend == 0) continue;

				int distance = Context.Distance(targetPlanet, nearestPlanet);

				Planet futurePlanet = Context.PlanetFutureStatus(targetPlanet, distance);
				if (futurePlanet.Owner() == 2)//Error?
				{
#if LOG
					Logger.Log("InvadeAdvizer: Error?");
#endif
					moves.Clear();
					return moves;
				}

				int needToSend = futurePlanet.NumShips() + 1;
				if (Config.InvadeSendMoreThanEnemyCanDefend)
				{
					int extraTurns = (int)Math.Ceiling(targetPlanet.NumShips() / (double)targetPlanet.GrowthRate());
					if (Context.MyFutureProduction < Context.EnemyFutureProduction) extraTurns = 0;
					if ((Context.MyFutureProduction == Context.EnemyFutureProduction) &&
						(Context.MyTotalShipCount <= Context.EnemyTotalShipCount)) extraTurns = 0;
					needToSend += Context.GetEnemyAid(targetPlanet, distance + extraTurns);
				}
				
				needToSend = moves.Aggregate(needToSend, (current, eachMove) => current - Context.CanSendByPlanets(Context.GetPlanet(eachMove.SourceID), Context.GetPlanet(eachMove.DestinationID)));
				
				//delay closer moves
				/*foreach (Move eachMove in moves)
				{
					int moveDistance = Context.Distance(eachMove.DestinationID, eachMove.SourceID);
					int turns = distance - moveDistance;
					eachMove.TurnsBefore = turns;
					needToSend -= Context.CanSend(Context.GetPlanet(eachMove.SourceID), turns);
				}*/

				if (needToSend <= 0) return moves;

				canSend = Math.Min(needToSend, canSend);
				needToSend -= canSend;
				Move move = new Move(nearestPlanet, targetPlanet, canSend);
				moves.Add(move);

				if (needToSend <= 0) return moves;
			}

			moves.Clear();
			return moves;
		}
Exemplo n.º 6
0
 private static void PlanetGrowth(Planet planetInFuture)
 {
     if (planetInFuture.Owner() != 0)
     {
         planetInFuture.NumShips(planetInFuture.NumShips() + planetInFuture.GrowthRate());
     }
 }
Exemplo n.º 7
0
		public int CanSendSafe(Planet planet)
		{
			Planet closestEnemyPlanet = GetClosestPlanet(planet, EnemyPlanets());
			if (closestEnemyPlanet == null)
			{
				return planet.NumShips();
			}
			int distance = Distance(planet, closestEnemyPlanet);
			Planets closePlanets = EnemyPlanetsWithinProximityToPlanet(planet, distance);

			int ships = 0;
			foreach (Planet closePlanet in closePlanets)
			{
				ships += closePlanet.NumShips();
			}

			int safeCanSend = Math.Max(0, (planet.NumShips() - (ships - planet.GrowthRate() * distance)));
			//Logger.Log("Safe: " + safeCanSend + "  notSafe:" + CanSend(planet));
			//if (MyPlanets().Count == 1) return safeCanSend;
			//if (distance > 6) return CanSend(planet);
				//GetEnemyAid(planet, safeTurns);));
			return Math.Min(safeCanSend, CanSend(planet));
		}
Exemplo n.º 8
0
		//# Generates a string representation of a planet. This is used to send data
		//# about the planets to the client programs.
		public static string SerializePlanet(Planet planet)
		{
			int owner = planet.Owner();
			string message = 
				"P " + 
				string.Format("{0:R}", planet.X()) + 
				" " + 
				string.Format("{0:R}", planet.Y()) + 
				" " + 
				owner +
				" " + 
				planet.NumShips() + 
				" " + 
				planet.GrowthRate();
			return message.Replace(".0 ", " ");
		}
Exemplo n.º 9
0
		public int CanSendByPlanets(Planet source, Planet dest, int turns)
		{
			if (dest.GrowthRate() > source.GrowthRate())
			{
				if (turns == 0) return CanSend(source);
				return CanSend(source, turns);
			}
			return CanSendSafe(source);
		}
Exemplo n.º 10
0
		public int CanSendByPlanets(Planet source, Planet dest)
		{
			if (dest.GrowthRate() < source.GrowthRate()) return CanSendSafe(source);
			return CanSend(source);


			/*Moves moves = new Moves();

			Planets enemyPlanets = EnemyPlanets();
			if (enemyPlanets.Count == 0) return 0;

			Comparer comparer = new Comparer(this) { TargetPlanet = source };
			enemyPlanets.Sort(comparer.CompareDistanceToTargetPlanetLT);

			PlanetHolder holder = GetPlanetHolder(source);

			foreach (Planet enemyPlanet in enemyPlanets)
			{
				int targetDistance = Distance(enemyPlanet, source);

				int numShips = enemyPlanet.NumShips();

				//enemyCanSend
				PlanetHolder enemyHolder = GetPlanetHolder(enemyPlanet.PlanetID());
				if (enemyHolder.GetOwnerSwitchesFromEnemyToMy().Count > 0)
				{
					numShips = 0;
				}
				else
				{
					int turnsCount = enemyHolder.TurnsCount;
					for (int turn = 1; turn < turnsCount; turn++)
					{
						Planet futurePlanet = PlanetFutureStatus(enemyPlanet, turn);
						if (futurePlanet.NumShips() < numShips) numShips = futurePlanet.NumShips();
					}
				}

				int enemyCanSend = numShips;
				if (enemyCanSend == 0) continue;

				Planet futureSourcePlanet = PlanetFutureStatus(source, targetDistance);
				if (futureSourcePlanet.Owner() != 1) continue;

				int needToSend = 1 + futureSourcePlanet.NumShips();
				needToSend += GetEnemyAid(source, targetDistance);

				needToSend = moves.Aggregate(needToSend, (current, eachMove) => current - CanSend(GetPlanet(eachMove.SourceID)));

				if (needToSend <= 0) return 0;

				int canSend = Math.Min(needToSend, enemyCanSend);
				needToSend -= canSend;
				Move move = new Move(enemyPlanet, source, canSend);
				moves.Add(move);

				if (needToSend <= 0) return 0;
			}

			return 0;*/
		}