示例#1
0
  public boolean arrival() {
    List<Fleet> fleets = new ArrayList<>();
    boolean arrival = false;

    if (Fleets().size() == 0) {
      return true;
    }

    for (Fleet fleet : Fleets()) {
      if (fleet.TurnsRemaining() == 0) {
        arrival = true;
        fleets.add(fleet);
      }
    }
    fleets.forEach(
        fleet -> {
          Planet dest = GetPlanet(fleet.DestinationPlanet());
          if (fleet.Owner() != dest.Owner()) {
            dest.NumShips(dest.NumShips() - fleet.NumShips());
            if (dest.NumShips() < 0) {
              dest.Owner(fleet.Owner());
              dest.NumShips(Math.abs(dest.NumShips()));
            }

          } else {
            dest.NumShips(dest.NumShips() + fleet.NumShips());
          }
        });
    return arrival;
  }
  // Add each possible state in the currentNode.sons list.
  public void createSons() { // Tested
    SimulatedPlanetWars simpw = this.getSim();
    for (Planet myPlanet : simpw.MyPlanets()) {

      // avoid planets with only one ship
      if (myPlanet.NumShips() <= 1) continue;

      // We create a son for each of the possible situations
      for (Planet notMyPlanet : simpw.NotMyPlanets()) {

        // Create simulation environment for this son
        SimulatedPlanetWars simpw2 = new SimulatedPlanetWars(simpw);
        int value = Helper.Dcalculation(myPlanet, notMyPlanet);
        simpw2.IssueOrder(myPlanet, notMyPlanet);
        simpw2.simulateGrowth();
        simpw2.simulateFirstBotAttack();
        simpw2.simulateGrowth();

        MyNode son;
        if (this.isRoot()) {
          son = new MyNode(this, simpw2, value, myPlanet, notMyPlanet);
        } else {
          son =
              new MyNode(
                  this,
                  simpw2,
                  value,
                  this.getSource(),
                  this.getDest()); // We only need to know from where to where we want to send our
          // ships to get the best turn
        }
        this.addSon(son);
      }
    }
  }
  @SuppressWarnings("deprecation")
  @Command(
      value = "myplanet",
      desc = "Erzeugt einen Testplaneten",
      perm = "craftoplugin.galaxywar.generate",
      onlyplayers = true)
  public void generatePlanet(final CommandSender cs, final String command, final String[] args) {
    final Player p = (Player) cs;
    p.sendMessage("Aktiv!");
    final int r = 6;
    PlanetType type = PlanetType.SUN;
    if (args.length > 0) {
      try {
        type = PlanetType.valueOf(args[0].toUpperCase());
      } catch (final IllegalArgumentException e) {
      }
    }
    final World world = p.getWorld();

    final Planet planet = new Planet(new Position(p.getLocation()), r, type);
    final ArrayList<MaterialBlockPoint> blocks = planet.getMaterialBlockPoints();

    Block block;
    for (final MaterialBlockPoint b : blocks) {
      block = world.getBlockAt(b.getX(), b.getY(), b.getZ());
      block.setType(b.getMaterial());
      block.setData((byte) 0);
    }
  }
示例#4
0
 public boolean isPlaceEmpty(Vector2 pos, boolean considerPlanets) {
   Planet np = myPlanetManager.getNearestPlanet(pos);
   if (considerPlanets) {
     boolean inPlanet = np.getPos().dst(pos) < np.getFullHeight();
     if (inPlanet) return false;
   }
   SolSystem ns = myPlanetManager.getNearestSystem(pos);
   if (ns.getPos().dst(pos) < SunSingleton.SUN_HOT_RAD) return false;
   List<SolObject> objs = myObjectManager.getObjs();
   for (int i = 0, objsSize = objs.size(); i < objsSize; i++) {
     SolObject o = objs.get(i);
     if (!o.hasBody()) continue;
     if (pos.dst(o.getPos()) < myObjectManager.getRadius(o)) {
       return false;
     }
   }
   List<FarObjData> farObjs = myObjectManager.getFarObjs();
   for (int i = 0, farObjsSize = farObjs.size(); i < farObjsSize; i++) {
     FarObjData fod = farObjs.get(i);
     FarObj o = fod.fo;
     if (!o.hasBody()) continue;
     if (pos.dst(o.getPos()) < o.getRadius()) {
       return false;
     }
   }
   return true;
 }
示例#5
0
  public static void main(String[] args) {
    Planet sun = new Planet(0, 0, 1.0e9, 0.5);
    Planet planet = new Planet(1, 0, 100.0, 0.1);

    Rechner rechner = new Rechner();
    rechner.berechnen(sun.getCoords(), planet.getCoords(), sun.getMass());
  }
示例#6
0
  // region Events
  public void onSave(File file, World world) {
    isDirty = false;

    for (Planet planet : getPlanets()) {
      planet.onSave(file, world);
    }
  }
示例#7
0
 public Universe next() {
   List<Fleet> futureFleets = new ArrayList<Fleet>();
   List<Planet> newPlanets = new ArrayList<Planet>();
   for (Planet planet : planets.items) {
     newPlanets.add(planet.grow());
   }
   List<Fleet> arrivingFleets = new ArrayList<Fleet>();
   for (Fleet fleet : fleets.items) {
     Fleet movedFleet = fleet.move();
     if (movedFleet.turnsRemaining > 0) {
       futureFleets.add(movedFleet);
     } else {
       arrivingFleets.add(movedFleet);
     }
   }
   Fleets arriving = new Fleets(arrivingFleets);
   for (Fleet fleet : arrivingFleets) {
     Planet planet = new Planets(newPlanets).find(fleet.destinationPlanet);
     Fleets attacking = arriving.attacking(planet);
     if (attacking.enemyFleets().ships() != attacking.myFleets().ships()) {
       newPlanets.remove(planet);
       planet = planet.receive(fleet);
       newPlanets.add(planet);
     }
   }
   return new Universe(new Planets(newPlanets), new Fleets(futureFleets), turn + 1, reservations);
 }
示例#8
0
 public int predictShips(Planet planet, int turns) {
   if (NeutralPlanets().contains(planet)) {
     return planet.NumShips();
   } else {
     return planet.NumShips() + planet.GrowthRate() * turns;
   }
 }
示例#9
0
 public boolean isClaimed() {
   for (Planet planet : getPlanets()) {
     if (planet.hasOwner()) {
       return true;
     }
   }
   return false;
 }
示例#10
0
  private static double calculateDistance(Planet first, Planet second) {
    double a = (first.getX() - second.getX());
    double b = (first.getY() - second.getY());
    double c = Math.pow(a, 2) + Math.pow(b, 2);

    // Pythagorean theorem, a² + b² = c² ..

    return Math.sqrt(c);
  }
示例#11
0
 // Return a list of all the planets that are not owned by the current
 // player. This includes all enemy planets and neutral planets.
 public List<Planet> NotMyPlanets() {
   List<Planet> r = new ArrayList<Planet>();
   for (Planet p : planets) {
     if (p.Owner() != 1) {
       r.add(p);
     }
   }
   return r;
 }
示例#12
0
 // Return a list of all the planets owned by rival players. This excludes
 // planets owned by the current player, as well as neutral planets.
 public List<Planet> EnemyPlanets() {
   List<Planet> r = new ArrayList<Planet>();
   for (Planet p : planets) {
     if (p.Owner() >= 2) {
       r.add(p);
     }
   }
   return r;
 }
示例#13
0
 // Returns the production of the given player.
 public int Production(int playerID) {
   int prod = 0;
   for (Planet p : planets) {
     if (p.Owner() == playerID) {
       prod += p.GrowthRate();
     }
   }
   return prod;
 }
示例#14
0
 // Return a list of all neutral planets.
 public List<Planet> NeutralPlanets() {
   List<Planet> r = new ArrayList<Planet>();
   for (Planet p : planets) {
     if (p.Owner() == 0) {
       r.add(p);
     }
   }
   return r;
 }
 private void putPlanetImageToButton() {
   planetImageIcon = new ImageIcon(fileURL);
   planetImage = planetImageIcon.getImage().getScaledInstance(65, 65, java.awt.Image.SCALE_SMOOTH);
   imageButton[buttonIndex] =
       new JButton(planet.planetName().toUpperCase(), new ImageIcon(planetImage));
   imageButton[buttonIndex].addActionListener(
       PlanetActionListener.planetInformation(planet.toString())
           .andMultipleFramesContainer(multipleFramesContainer));
 }
示例#16
0
 @Override
 public String toString() {
   return "{"
       + type
       + ": "
       + (from != null ? from.getId() : null)
       + " -> "
       + (to != null ? to.getId() : null)
       + "}";
 }
示例#17
0
 /** @param args */
 public static void main(String[] args) {
   if (args.length != 1) {
     System.err.println("Usage: java Planet <earth_weight>");
     System.exit(-1);
   }
   double earthWeight = Double.parseDouble(args[0]);
   double mass = earthWeight / EARTH.surfaceGravity();
   for (Planet p : Planet.values())
     System.out.printf("Your weight on %s is %f%n", p, p.surfaceWeight(mass));
 }
示例#18
0
 public float value_myself() {
   // int myships = this.NumShips(1);
   // int myplanets = this.NumPlanets();
   int mygrowth = 0;
   float value;
   for (Planet planet : MyPlanets()) {
     mygrowth += planet.GrowthRate();
   }
   value = (float) mygrowth;
   return value;
 }
示例#19
0
 public boolean isDirty() {
   if (isDirty) {
     return true;
   } else {
     for (Planet planet : getPlanets()) {
       if (planet.isDirty()) {
         return true;
       }
     }
   }
   return false;
 }
示例#20
0
  // ------------------------------------------------//
  // ------- Custom methods and/or properties: ------//
  // ------------------------------------------------//
  private PlanetWars(PlanetWars _pw) {
    this.planets = new ArrayList<>();
    this.fleets = new ArrayList<>();
    for (Planet planet : _pw.Planets()) {
      Planet lol = planet.clone();
      this.planets.add(lol);
    }

    for (Fleet fleet : _pw.Fleets()) {
      fleets.add(fleet.clone());
    }
  }
示例#21
0
 public Planet releasePlanet(int id) {
   for (int x = 0; x < planets.size(); x++) {
     if (planets.get(x).getID() == id) {
       Planet p = planets.get(x);
       income = income - p.getIncome();
       p.setOwner(null);
       planets.remove(x);
       return p;
     }
   }
   return null;
 }
示例#22
0
  @Test
  public void testNumberOfHomePlanets() throws InvalidMoveException {
    Player player1 = new Player("Player 1", GameColor.BLACK);
    Assert.assertEquals(Player.DEFAULT_NUMBER_OF_PLANETS, player1.numberOfHomePlanets());

    List<Planet> homePlanets = player1.getHomePlanets();
    for (Planet planet : homePlanets) {
      planet.removeShips(player1);
    }

    Assert.assertEquals(0, player1.numberOfHomePlanets());
  }
 public void draw(SolGame game, GameDrawer drawer) {
   SolCam cam = game.getCam();
   Vector2 camPos = cam.getPos();
   Planet p = game.getPlanetMan().getNearestPlanet();
   Vector2 pPos = p.getPos();
   float toCamLen = camPos.dst(pPos);
   float vd = cam.getViewDist();
   float gh = p.getMinGroundHeight();
   if (toCamLen < gh + vd) {
     float sz = gh;
     drawer.draw(myTex, sz * 2, sz * 2, sz, sz, pPos.x, pPos.y, p.getAngle(), SolColor.W);
   }
 }
示例#24
0
 // Returns true if the named player owns at least one planet or fleet.
 // Otherwise, the player is deemed to be dead and false is returned.
 public boolean IsAlive(int playerID) {
   for (Planet p : planets) {
     if (p.Owner() == playerID) {
       return true;
     }
   }
   for (Fleet f : fleets) {
     if (f.Owner() == playerID) {
       return true;
     }
   }
   return false;
 }
示例#25
0
  public void generateMissing(NBTTagCompound tagCompound, GalaxyGenerator galaxyGenerator) {
    if (galaxyGenerator != null) {
      for (ISpaceBodyGen<Star> starGen : galaxyGenerator.getStarGen().getGens()) {
        galaxyGenerator.getStarRandom().setSeed(seed);
        if (starGen.generateMissing(tagCompound, this, galaxyGenerator.getStarRandom())) {
          break;
        }
      }

      for (Planet planet : getPlanets()) {
        planet.generateMissing(tagCompound, galaxyGenerator);
      }
    }
  }
示例#26
0
 // Returns the number of ships that the current player has, either located
 // on planets or in flight.
 public int NumShips(int playerID) {
   int numShips = 0;
   for (Planet p : planets) {
     if (p.Owner() == playerID) {
       numShips += p.NumShips();
     }
   }
   for (Fleet f : fleets) {
     if (f.Owner() == playerID) {
       numShips += f.NumShips();
     }
   }
   return numShips;
 }
示例#27
0
 Universe haveEveryPlanetAttack(Planet mine, Planets planetsToAttack) {
   List<Planet> newPlanets = new ArrayList<Planet>();
   List<Fleet> additionalFleets = new ArrayList<Fleet>();
   for (Planet p : planetsToAttack.minus(mine).items) {
     if (!p.isNeutral()) {
       newPlanets.add(p.removeShips(p.numShips));
       additionalFleets.add(p.attack(mine));
     }
   }
   return new Universe(
       planets.replace(new Planets(newPlanets)),
       fleets.union(new Fleets(additionalFleets)),
       turn,
       reservations);
 }
示例#28
0
 public Country(
     Planet parent,
     String iso3166alpha2Code,
     String iso3166alpha3Code,
     Integer iso3166numericCode,
     LocalizedString name,
     LocalizedString nationality,
     Class<AddressPrinter> iAddressPrinter) {
   super();
   setBennu(Bennu.getInstance());
   setUnit(
       Unit.create(
           parent.getUnit(),
           name,
           iso3166alpha3Code,
           getPartyType("País", COUNTRY_PARTYTYPE_NAME),
           getOrCreateAccountabilityType(),
           new LocalDate(),
           null,
           null));
   setIso3166alpha2Code(iso3166alpha2Code);
   setIAddressPrinter(iAddressPrinter);
   setIso3166alpha3Code(iso3166alpha3Code);
   setIso3166numericCode(iso3166numericCode);
   setNationality(nationality);
 }
示例#29
0
  public MailRocket() {
    // NB ! We need to create offices first!
    Planet.setRandomStartOfficeToRocket(this);

    Thread thread = new Thread(new FlyRunnable(this));
    thread.start();
  }
示例#30
0
 // If the game is not yet over (ie: at least two players have planets or
 // fleets remaining), returns -1. If the game is over (ie: only one player
 // is left) then that player's number is returned. If there are no
 // remaining players, then the game is a draw and 0 is returned.
 public int Winner() {
   Set<Integer> remainingPlayers = new TreeSet<Integer>();
   for (Planet p : planets) {
     remainingPlayers.add(p.Owner());
   }
   for (Fleet f : fleets) {
     remainingPlayers.add(f.Owner());
   }
   switch (remainingPlayers.size()) {
     case 0:
       return 0;
     case 1:
       return ((Integer) remainingPlayers.toArray()[0]).intValue();
     default:
       return -1;
   }
 }