private boolean fleet_already_sent(Planet destination) { List<Fleet> fleets = Fleets(); for (Fleet fleet : fleets) { if (fleet.DestinationPlanet() == destination.PlanetID() && fleet.Owner() == 1) { return true; } } return false; }
// Sends an order to the game engine. An order is composed of a source // planet number, a destination planet number, and a number of ships. A // few things to keep in mind: // * you can issue many orders per turn if you like. // * the planets are numbered starting at zero, not one. // * you must own the source planet. If you break this rule, the game // engine kicks your bot out of the game instantly. // * you can't move more ships than are currently on the source planet. // * the ships will take a few turns to reach their destination. Travel // is not instant. See the Distance() function for more info. public void IssueOrder(Planet source, Planet dest, int numShips) { System.out.println("" + source.PlanetID() + " " + dest.PlanetID() + " " + numShips); System.out.flush(); }
// Small wrapper for the Distance method in PlanetWars public int Distance(Planet source, Planet destination) { return Distance(source.PlanetID(), destination.PlanetID()); }
@Override public void DoTurn(PlanetWars pw) { write("==TURN " + ++turnNum); if (mirrorMap == null) { write("==Generating mirrorMap"); mirrorMap = new HashMap<Integer, Planet>(); double mapCenterX = 0; double mapCenterY = 0; for (Planet p : pw.Planets()) { mapCenterX += p.X(); mapCenterY += p.Y(); } mapCenterX = mapCenterX / pw.Planets().size(); mapCenterY = mapCenterY / pw.Planets().size(); // write("Map Center: " + "(" + mapCenterX + ", " + mapCenterY + ")"); HashMap<Point, Planet> mirroredLocation = new HashMap<Point, Planet>(); for (Planet p : pw.Planets()) { if (p.X() == mapCenterX && p.Y() == mapCenterY) { write("-- Detected Center Planet --"); mirrorMap.put(p.PlanetID(), p); continue; } Point mirroredPoint = new Point(p.X(), p.Y()); // write("Looking for point of: " + mirroredPoint + " for " + p.PlanetID()); if (mirroredLocation.containsKey(mirroredPoint)) { Planet p1 = mirroredLocation.get(mirroredPoint); write("-- Detected Mirror Planet: " + p.PlanetID() + " = " + p1.PlanetID() + " --"); mirrorMap.put(p1.PlanetID(), p); mirrorMap.put(p.PlanetID(), p1); } else { mirroredPoint.x = mapCenterX + mapCenterX - p.X(); mirroredPoint.y = mapCenterY + mapCenterY - p.Y(); mirroredLocation.put(mirroredPoint, p); // write("Set mirror point of: " + mirroredPoint + " for " + p.PlanetID()); } } write("--Generated mirrorMap"); } if (pw.EnemyFleets().size() > 0) { write("Checking Enemy Fleets"); List<Fleet> fleets = pw.EnemyFleets(); for (Fleet o : mirroredFleets) { fleets.remove(o); } write("Fleet count: " + fleets.size() + " -- mirrored: " + mirroredFleets.size()); for (Fleet f : fleets) { boolean handled = false; Planet src = mirrorMap.get(f.SourcePlanet()); Planet dest = mirrorMap.get(f.DestinationPlanet()); // write("lamo: " + f.SourcePlanet() + " " + f.DestinationPlanet()); // write("lame: " + src.PlanetID() + " " + dest.PlanetID()); // write("owner: " + src.Owner() + " " + dest.Owner()); // Don't trade fleets between mirrored planets: if (src.PlanetID() != f.DestinationPlanet()) { write("Ships: " + src.PlanetID() + " -- " + src.NumShips() + " - " + f.NumShips()); if (src.NumShips() > f.NumShips() && src.Owner() == 1) { pw.IssueOrder(src, dest, f.NumShips()); // src.NumShips(src.NumShips() - f.NumShips()); handled = true; } } else { handled = true; } if (handled) mirroredFleets.add(f); // } // else { // write("Already handled fleet"); // } } } else { write("Waiting"); // write("Attacking Something"); // if (distances == null) { // distances = new PlanetDistances(pw); // } // // //Attack something // for (Planet p : pw.MyPlanets()) { // Planet attack = Find.NearestPlanetNotOwnedCanTake(pw.Planets(), distances, // p.PlanetID(), p.NumShips() - 10); // if (attack != null && p.NumShips() > 20) { // pw.IssueOrder(p.PlanetID(), attack.PlanetID(), p.NumShips() - 15); // } // } } }