public override List<MovesSet> RunAll() { Planets enemyPlanets = Context.Planets(); //Context.EnemyPlanets(); List<MovesSet> movesSet = new List<MovesSet>(); foreach (Planet planet in enemyPlanets) { PlanetHolder planetHolder = Context.GetPlanetHolder(planet); if ((planet.Owner() != 2) && (planetHolder.GetOwnerSwitchesToEnemy().Count == 0)) continue; Moves moves = Run(planet); if (moves.Count <= 0) continue; MovesSet set = new MovesSet(moves, 0, GetAdviserName(), Context); //double score = enemyPlanet.GrowthRate() / Context.AverageMovesDistance(moves); double score = 2 * planet.GrowthRate() * Config.ScoreTurns - set.NumShipsByTurns / set.AverageDistance; set.Score = score; movesSet.Add(set); } return movesSet; }
public override List<MovesSet> RunAll() { List<MovesSet> movesSet = new List<MovesSet>(); Planets planetsForAdvise = Context.MyEndangeredPlanets(); foreach (Planet planet in planetsForAdvise) { Moves moves = Run(planet); if (moves.Count <= 0) continue; MovesSet set = new MovesSet(moves, 0, GetAdviserName(), Context); //double score = enemyPlanet.GrowthRate() / Context.AverageMovesDistance(moves); double score = 2 * planet.GrowthRate() * (loseTurn > 0 ? loseTurn : Config.ScoreTurns) - set.NumShipsByTurns / set.AverageDistance; set.Score = score; if (loseTurn == 0) { movesSet.Add(set); } else { //todo delete bigger then target Moves newMoves = new Moves(); foreach (Move move in set.GetMoves()) { if (Context.GetPlanet(move.SourceID).NumShips() < Context.GetPlanet(move.DestinationID).NumShips()) newMoves.Add(new Move(move)); } if (newMoves.Count > 0) { set = new MovesSet(newMoves, 0, GetAdviserName(), Context); movesSet.Add(set); } } } return movesSet; }
public MovesSet BruteForce(Planets planets, int canSend) { int scoreTurns = Config.ScoreTurns;//Context.Distance(myPlanet, enemyPlanet); int n = planets.Count; //int secondMoveCanSend = myPlanet.NumShips() - canSend + myPlanet.GrowthRate(); int secondMoveCanSend = Math.Min(myPlanet.NumShips() - canSend + myPlanet.GrowthRate(), myPlanet.GrowthRate() * Context.Distance(myPlanet, enemyPlanet)); List<MovesSet> sets = new List<MovesSet>(); int size = (1 << n); for (int i = 0; i < size; i++) { if (CheckTimeFunc != null) if (!CheckTimeFunc()) break; int ships = 0; int score = 0; int returners = 0; Moves moves = new Moves(); Planets targetPlanets = new Planets(Config.MaxPlanets); for (int j = 0; j < n; j++) { if (CheckTimeFunc != null) if (!CheckTimeFunc()) break; if ((i & (1 << j)) <= 0) continue; Planet target = planets[j]; targetPlanets.Add(target); int distance = Context.Distance(myPlanet, target); int needShips = target.NumShips() + 1; if (Context.Distance(myPlanet, target) >= Context.Distance(enemyPlanet, target)) needShips += 1; if (myPlanet.NumShips() > canSend && enemyDistance > distance * 2) { //HowMany ships can return to myPlanet before enemy returners += (enemyDistance - distance * 2) * myPlanet.GrowthRate(); if (returners > myPlanet.NumShips() - canSend) returners = myPlanet.NumShips() - canSend; } int growTurns = Math.Max(0, scoreTurns - Context.Distance(myPlanet.PlanetID(), target.PlanetID())); score += growTurns * target.GrowthRate() - needShips; ships += needShips; if (ships > canSend + returners) { break; } moves.Add( new Move( myPlanet.PlanetID(), target.PlanetID(), needShips) ); } if (ships > canSend + returners) continue; //clear set MovesSet set = new MovesSet(moves, score, GetAdviserName(), Context); sets.Add(set); //sets with additional planet, divided for 2 turns int firstMoveCanSend = canSend + returners - ships; if (firstMoveCanSend < 0) firstMoveCanSend = 0; foreach (Planet additionalPlanet in planets) { if (targetPlanets.Contains(additionalPlanet)) continue; int needShips = additionalPlanet.NumShips() + 1; if (Context.Distance(myPlanet, additionalPlanet) >= Context.Distance(enemyPlanet, additionalPlanet)) needShips += 1; if (firstMoveCanSend + secondMoveCanSend < needShips) continue; //this planet we can invade in another set: this set + this planet if (firstMoveCanSend >= needShips) continue; MovesSet additionalSet = new MovesSet(set, Context); if (firstMoveCanSend > 0) additionalSet.AddMove(new Move(myPlanet, additionalPlanet, firstMoveCanSend)); additionalSet.AddMove(new Move(myPlanet, additionalPlanet, needShips - firstMoveCanSend) { TurnsBefore = 1 }); int growTurns = Math.Max(0, scoreTurns - Context.Distance(myPlanet.PlanetID(), additionalPlanet.PlanetID())); additionalSet.Score += (growTurns - 1) * additionalPlanet.GrowthRate() - needShips; sets.Add(additionalSet); } } if (sets.Count == 0) return null; if (sets.Count > 1) { sets.Sort(new Comparer(null).CompareSetScoreGT); } /*foreach (MovesSet movesSet in sets) { Logger.Log("score: " + movesSet.Score + " " + movesSet); }*/ return sets[0]; }
public int CompareSetScoreGT(MovesSet set1, MovesSet set2) { int result = Math.Sign(set2.Score - set1.Score); if (result == 0) result = Math.Sign(set1.AverageDistance - set2.AverageDistance); if (result == 0) result = set1.MinDistance - set2.MinDistance; return result; }
public override List<MovesSet> RunAll() { List<MovesSet> movesSet = new List<MovesSet>(); Planets planetsForAdvise = Context.NeutralPlanets(); foreach (Planet planet in planetsForAdvise) { if (planet.GrowthRate() == 0) continue; PlanetHolder planetHolder = Context.GetPlanetHolder(planet); if (planetHolder.GetOwnerSwitchesFromNeutralToEnemy().Count == 0) continue; Moves moves = Run(planet); if (moves.Count <= 0) continue; MovesSet set = new MovesSet(moves, 0, GetAdviserName(), Context); double score = 2 * planet.GrowthRate() * Config.ScoreTurns - set.NumShipsByTurns / set.AverageDistance; set.Score = score; movesSet.Add(set); } return movesSet; }
public override List<MovesSet> RunAll() { List<MovesSet> movesSet = new List<MovesSet>(); Planets planetsForAdvise = Context.NeutralPlanets(); foreach (Planet planet in planetsForAdvise) { if (planet.GrowthRate() == 0) continue; PlanetHolder planetHolder = Context.GetPlanetHolder(planet); //if (planetHolder.GetOwnerSwitchesToEnemy().Count > 0) continue; if (planetHolder.OwnerSwitches.Count > 0) continue; Moves moves = Run(planet); if (moves.Count <= 0) continue; MovesSet set = new MovesSet(moves, 0, GetAdviserName(), Context); /*int enemyAid = Context.GetEnemyAid(planet, set.MaxDistance); double risk = 2.0; if (enemyAid != 0) risk = set.SummaryNumShips / (double)enemyAid; double score = Config.ScoreKoef * risk * (planet.GrowthRate() / (set.MaxDistance * 100.0 + planet.NumShips()));*/ double score = planet.GrowthRate() * Config.ScoreTurns - set.NumShipsByTurns / set.AverageDistance - planet.NumShips(); set.Score = score; //Logger.Log("planet: " + planet + " score " + score + " set.NumShipsByTurns" + set.NumShipsByTurns); movesSet.Add(set); } return movesSet; }
public MovesSet(MovesSet set, PlanetWars context) : this(set.GetMoves(), set.Score, set.AdviserName, context) { }
public void IssueOrder(MovesSet movesSet) { Moves moves = movesSet.GetMoves(); foreach (Move move in moves) { #if LOG Logger.Log(movesSet.AdviserName + ": " + move); #endif IssueOrder(move); } }