@Override
  public void selectDragonMove(Set<Position> positions, int movesLeft) {
    initVars();
    Position dragonPosition = getGame().getPrincessAndDragonGame().getDragonPosition();
    double tensionX = 0, tensionY = 0;

    for (Meeple m : getGame().getDeployedMeeples()) {
      int distance = dragonPosition.squareDistance(m.getPosition());
      if (distance == 0 || distance > movesLeft) continue;
      if (m.getFeature() instanceof Castle) continue;

      double weight = 1.0 / (distance * distance);
      if (isMe(m.getPlayer())) {
        weight *= -0.8; // co takhle 0.8
      }
      tensionX += weight * (m.getPosition().x - dragonPosition.x);
      tensionY += weight * (m.getPosition().y - dragonPosition.y);
    }

    double minDiff = Double.MAX_VALUE;
    Position result = null;
    for (Position p : positions) {
      double diff =
          Math.abs(p.x - dragonPosition.x - tensionX) + Math.abs(p.y - dragonPosition.y - tensionY);
      if (diff < minDiff) {
        minDiff = diff;
        result = p;
      }
    }
    getServer().moveDragon(result);
  }
Exemplo n.º 2
0
 @Override
 public String toString() {
   if (position == null) {
     return getClass().getSimpleName();
   } else {
     return getClass().getSimpleName() + position.toString();
   }
 }
Exemplo n.º 3
0
 @Override
 public void zoomChanged(int squareSize) {
   Position prevSelectedPosition = selectedPosition;
   super.zoomChanged(squareSize);
   if (selectedPosition != null && selectedPosition.equals(prevSelectedPosition)) {
     // no square enter/leave trigger in this case - refresh areas
     areas = prepareAreas(gridPanel.getTile(selectedPosition), selectedPosition);
   }
 }
Exemplo n.º 4
0
 private Castle convertCityToCastle(Position pos, Location loc, boolean loadFromSnaphot) {
   Castle castle1 = replaceCityWithCastle(getBoard().get(pos), loc);
   Castle castle2 = replaceCityWithCastle(getBoard().get(pos.add(loc)), loc.rev());
   castle1.getEdges()[0] = castle2;
   castle2.getEdges()[0] = castle1;
   if (!loadFromSnaphot) {
     newCastles.add(castle1.getMaster());
   }
   game.post(new CastleDeployedEvent(game.getActivePlayer(), castle1, castle2));
   return castle1.getMaster();
 }
Exemplo n.º 5
0
 @Override
 public int hashCode() {
   return getClass().hashCode() + (position == null ? 1 : position.hashCode());
 }
Exemplo n.º 6
0
 public boolean at(Position p) {
   if (position == null) return false;
   return position.equals(p);
 }