예제 #1
0
        public override Moves Run(Planet supplyPlanet)
        {
            Moves moves = new Moves();

            if (supplyPlanet == null) return moves;

            Planets frontPlanets = Context.GetFrontPlanets();
            if (frontPlanets == null) return moves;
            if (frontPlanets.Count == 0) return moves;
            if (frontPlanets.IndexOf(supplyPlanet) != -1) return moves;

            IPathFinder pathFinder = new ClosestPathFinder(Context);
                //new DirectPathFinder(Context);
                //new DijkstraPathFinder(Context);
            Planet dest = pathFinder.FindNextPlanetInPath(supplyPlanet);
            if (dest != null)
            {
                int canSend = Context.CanSend(supplyPlanet);
                if (canSend == 0) return moves;

                Move move = new Move(supplyPlanet, dest, canSend);
                moves.Add(move);
            }
            return moves;
        }
예제 #2
0
파일: MovesSet.cs 프로젝트: rhiensch/pwbot
        public void AddMove(Move newMove)
        {
            SummaryNumShips += newMove.NumShips;
            int newDistance = context.Distance(newMove.SourceID, newMove.DestinationID);
            if (newDistance > MaxDistance) MaxDistance = newDistance;
            if (newDistance < MinDistance) MinDistance = newDistance;
            SumDistance += newDistance;
            //NumShipsByTurns += (newMove.NumShips * newDistance);

            moves.Add(newMove);

            AverageDistance = SumDistance / (double)moves.Count;
        }
예제 #3
0
        public override Moves Run(Planet planet)
        {
            Moves moves = new Moves();
            loseTurn = 0;

            //Planet planet = SelectPlanetForAdvise();
            if (planet == null) return moves;

            List<Step> saveSteps = Context.GetMyPlanetSaveSteps(planet);

            if (saveSteps.Count == 0) return moves;

            foreach (Step t in saveSteps)
            {
                Planets planetsCanHelp = Context.MyPlanetsWithinProximityToPlanet(planet, t.ToTurn);

                Comparer comparer = new Comparer(Context) {TargetPlanet = planet};
                planetsCanHelp.Sort(comparer.CompareDistanceToTargetPlanetLT);

                int sendedShipsNum = 0;
                foreach (Planet nearPlanet in planetsCanHelp)
                {
                    int canSend = Math.Min(t.NumShips - sendedShipsNum, Context.CanSendByPlanets(nearPlanet, planet));
                    if (canSend <= 0) continue;

                    int distance = Context.Distance(planet, nearPlanet);
                    Move move = new Move(nearPlanet.PlanetID(), planet.PlanetID(), canSend);
                    if (distance < t.ToTurn)
                    {
                        //delay move
                        move.TurnsBefore = t.ToTurn - distance;
                        //move = new Move(nearPlanet.PlanetID(), planet.PlanetID(), Context.CanSend(nearPlanet, move.TurnsBefore));
                    }
                    moves.Add(move);
                    sendedShipsNum += canSend;
                }
                if (sendedShipsNum < t.NumShips)
                {
                    loseTurn = t.NumShips;
                }
            }

            return moves;
        }
예제 #4
0
        public override Moves Run(Planet stealPlanet)
        {
            Moves moves = new Moves();

            PlanetHolder planetHolder = Context.GetPlanetHolder(stealPlanet);
            List<PlanetOwnerSwitch> switches = planetHolder.GetOwnerSwitchesFromNeutralToEnemy();
            if (switches.Count == 0) return moves;

            Planet futurePlanet = null;
            int turn = 0;
            for (int i = 0; i < switches.Count; i++)
            {
                turn = switches[i].TurnsBefore + 1;
                futurePlanet = Context.PlanetFutureStatus(stealPlanet, turn);
                if (futurePlanet.Owner() != 1) break;
                futurePlanet = null;
            }
            if (futurePlanet == null) return moves;

            Planets myPlanets = Context.MyPlanetsWithinProximityToPlanet(stealPlanet, turn);
            if (myPlanets.Count == 0) return moves;

            int needToSend = futurePlanet.NumShips() + 1;
            //needToSend += Context.GetEnemyAid(stealPlanet, turn);

            foreach (Planet myPlanet in myPlanets)
            {
                int distance = Context.Distance(myPlanet, stealPlanet);
                int canSend = Context.CanSendByPlanets(myPlanet, stealPlanet);
                if (canSend == 0) continue;

                int send = Math.Min(canSend, needToSend);
                needToSend -= send;

                Move move = new Move(myPlanet, stealPlanet, send) {TurnsBefore = turn - distance};
                moves.Add(move);

                if (needToSend <= 0) return moves;
            }

            moves.Clear();
            return moves;
        }
예제 #5
0
		public override Moves Run(Planet targetPlanet)
		{
			Moves moves = new Moves();
			if (targetPlanet == null) return moves;

			Planets myPlanets = Context.MyPlanets();
			if (myPlanets.Count == 0) return moves;

			Comparer comparer = new Comparer(Context) {TargetPlanet = targetPlanet};
			myPlanets.Sort(comparer.CompareDistanceToTargetPlanetLT);

			PlanetHolder holder = Context.GetPlanetHolder(targetPlanet);

			foreach (Planet myPlanet in myPlanets)
			{
				int targetDistance = Context.Distance(myPlanet, targetPlanet);
				int myCanSend = Context.CanSendByPlanets(myPlanet, targetPlanet);
				if (myCanSend == 0) continue;

				Planet futurePlanet = Context.PlanetFutureStatus(targetPlanet, targetDistance);
				if (futurePlanet.Owner() != 2) continue;
				if (holder.IsNeutralToEnemySwith(targetDistance)) continue;

				int needToSend = 1 + futurePlanet.NumShips();
				if (Config.AttackSendMoreThanEnemyCanDefend)
					needToSend += Context.GetEnemyAid(targetPlanet, targetDistance);

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

				if (needToSend <= 0) return moves;

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

				if (needToSend <= 0) return moves;
			}

			return new Moves();
		}
예제 #6
0
        public void TestMakeMove()
        {
            Move move = new Move(1, 2, 20);

            Context.IssueOrder(move);

            Assert.AreEqual(5, Context.Fleets().Count);
            Assert.AreEqual(3, Context.MyFleets().Count);
            Assert.AreEqual(40-20, Context.GetPlanet(1).NumShips());
            //Assert.AreEqual(Context.Distance(1, 2), Context.MyFleetsGoingToPlanet(Context.GetPlanet(2))[1].TotalTripLength());
            Assert.AreEqual(Context.Distance(1, 2), Context.MyFleetsGoingToPlanet(Context.GetPlanet(2))[1].TurnsRemaining());
        }
예제 #7
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;
		}
예제 #8
0
		private void MakeMove(Move move)
		{
			if (move.TurnsBefore == 0)
			{
				fleets.Add(MoveToFleet(1, move));
				//Logger.Log("planet:" + GetPlanet(move.SourceID) + " cansend: " + CanSend(GetPlanet(move.SourceID)) + " safecansend: " + CanSendSafe(GetPlanet(move.SourceID)) + " move: " +move);
				GetPlanet(move.SourceID).RemoveShips(move.NumShips);
				GetPlanetHolder(move.SourceID).ResetFutureStates();
				//Logger.Log("planet after:" + GetPlanet(move.SourceID) + " cansend after: " + CanSend(GetPlanet(move.SourceID)));
			}
			else
			{
				int min = move.NumShips;
				for (int i = 0; i < move.TurnsBefore; i++)
				{
					Planet futurePlanet = PlanetFutureStatus(GetPlanet(move.SourceID), i + 1);
					if (futurePlanet.Owner() != 1)
					{
						min = 0;
						break;
					}
					if (min > futurePlanet.NumShips()) min = futurePlanet.NumShips();
				}

				int canSend = min - move.NumShips;
				GetPlanet(move.SourceID).RemoveShips(canSend < 0 ? move.NumShips : canSend);
			}
			GetPlanetHolder(move.SourceID).ResetFutureStates();
		}
예제 #9
0
		public void IssueOrder(Move move)
		{
			if (!IsValid(move))
			{
			#if LOG
				Logger.Log("  !Invalid move: from " + move.SourceID + " to " + move.DestinationID + " num " + move.NumShips);
			#endif
				return;
			}

			if (move.TurnsBefore == 0)
			{
				Console.WriteLine("" + move.SourceID + " " + move.DestinationID + " " + move.NumShips);
				Console.Out.Flush();
			}
#if LOG
			//Logger.Log("" + move.SourceID + " " + move.DestinationID +" " + move.NumSheeps);
#endif

			MakeMove(move);
		}
예제 #10
0
		public bool IsValid(Move move)
		{
			return move.TurnsBefore > 0 || IsValid(move.SourceID, move.DestinationID, move.NumShips);
		}
예제 #11
0
		public Fleet MoveToFleet(int owner, Move move)
		{
			int distance = Distance(move.SourceID, move.DestinationID) + move.TurnsBefore;
			Fleet fleet = new Fleet(
				owner,
				move.NumShips,
				move.SourceID,
				move.DestinationID,
				distance,
				distance
				);
			return fleet;
		}