Esempio n. 1
0
 // called on continents that we don't own.
 // fortify our guys towards weak enemy countries.
 protected void fortifyContinentScraps(int cont) {
   CountryIterator e = new ContinentIterator(cont, countries);
   while (e.hasNext()) {
     Country c = e.next();
     if (c.getOwner() == ID && c.getMoveableArmies() > 0) {
       // we COULD move armies from 'c'
       int weakestArmies = 1000000;
       Country weakestLink = null;
       // if it has a neighbor with a weaker enemy then move there
       CountryIterator n = new NeighborIterator(c);
       while (n.hasNext()) {
         Country possMoveTo = n.next();
         if (possMoveTo.getOwner() == ID) {
           Country themWeak = possMoveTo.getWeakestEnemyNeighbor();
           if (themWeak != null && themWeak.getArmies() < weakestArmies) {
             weakestArmies = possMoveTo.getWeakestEnemyNeighbor().getArmies();
             weakestLink = possMoveTo;
           }
         }
       }
       Country hereWeakest = c.getWeakestEnemyNeighbor();
       // if a neighbor has a weaker country then we do here move our armies
       if (hereWeakest == null || weakestArmies < hereWeakest.getArmies()) {
         if (weakestLink != null) board.fortifyArmies(c.getMoveableArmies(), c, weakestLink);
       }
     }
   }
 }
Esempio n. 2
0
  public int moveArmiesIn(int cca, int ccd) {
    // test if they border any enemies at all:
    int attackerEnemies = countries[cca].getNumberEnemyNeighbors();
    int defenderEnemies = countries[ccd].getNumberEnemyNeighbors();

    if (attackerEnemies > defenderEnemies) return 0;
    else if (defenderEnemies > attackerEnemies) return 1000000;
    else if (attackerEnemies > 0) // then they are tied at above 0
    return countries[cca].getArmies() / 2;

    // move our armies into continents that we want.
    if (ourConts[countries[cca].getContinent()]
        && ourConts[countries[ccd].getContinent()]) { // we want both
      return countries[cca].getArmies() / 2;
    } else if (ourConts[countries[cca].getContinent()]) {
      return 0; // leave them in attacker
    } else if (ourConts[countries[ccd].getContinent()]) {
      return 1000000; // send to defender
    }

    // so now we want none of them
    // see if either of them border something we want
    int attackerEnemiesWanted = 0, defenderEnemiesWanted = 0;
    CountryIterator e = new NeighborIterator(countries[cca]);
    while (e.hasNext()) {
      Country test = e.next();
      if (test.getOwner() != ID && ourConts[test.getContinent()]) {
        attackerEnemiesWanted++;
      }
    }
    e = new NeighborIterator(countries[ccd]);
    while (e.hasNext()) {
      Country test = e.next();
      if (test.getOwner() != ID && ourConts[test.getContinent()]) {
        defenderEnemiesWanted++;
      }
    }

    if (attackerEnemiesWanted > defenderEnemiesWanted) return 0;
    else if (defenderEnemiesWanted > attackerEnemiesWanted) return 1000000;
    else if (attackerEnemiesWanted > 0) // then they are tied at above 0
    return countries[cca].getArmies() / 2;

    // So if we get here then they both border zero countries that we want.

    // Now if we are here then neither have any enemies.
    // we won't be able to use them to attack this turn

    // now just move in xxagentxx
    debug("Pixie moveArmiesIn not fully imped");
    return countries[cca].getArmies() / 2;
  }
Esempio n. 3
0
 // Execute all the attacks possible in this continent where we outnumber the enemy
 protected void attackInContinent(int cont) {
   CountryIterator continent = new ContinentIterator(cont, countries);
   while (continent.hasNext()) {
     Country c = continent.next();
     if (c.getOwner() != ID) {
       // try and find a neighbor that we own, and attack this country
       CountryIterator neighbors = new NeighborIterator(c);
       while (neighbors.hasNext()) {
         Country possAttack = neighbors.next();
         if (possAttack.getOwner() == ID
             && possAttack.getArmies() > c.getArmies() * outnumberBy
             && c.getOwner() != ID
             && possAttack.canGoto(c)) {
           board.attack(possAttack, c, true);
         }
       }
     }
   }
 }
Esempio n. 4
0
 // Do we own all of the continents that this country borders?
 // NOTE: This will not check countries that are in the same continent as 'center'
 protected boolean weOwnContsArround(Country center) {
   int cont = center.getContinent();
   CountryIterator n = new NeighborIterator(center);
   while (n.hasNext()) {
     Country neib = n.next();
     if (neib.getContinent() != cont
         && !BoardHelper.playerOwnsContinent(ID, neib.getContinent(), countries)) {
       return false;
     }
   }
   return true;
 }
Esempio n. 5
0
  protected void fortifyContinent(int cont) {
    // We work from the borders back, fortifying closer.
    // Start out by getting a List of the cont's borders:
    int[] borders = BoardHelper.getContinentBorders(cont, countries);
    List cluster = new ArrayList();
    for (int i = 0; i < borders.length; i++) {
      cluster.add(countries[borders[i]]);
    }

    // So now the cluster borders are in <cluster>. fill it up while fortifying towards the borders.
    for (int i = 0; i < cluster.size(); i++) {
      CountryIterator neighbors = new NeighborIterator((Country) cluster.get(i));
      while (neighbors.hasNext()) {
        Country neighbor = neighbors.next();
        if (neighbor.getOwner() == ID
            && !cluster.contains(neighbor)
            && neighbor.getContinent() == cont) {
          // Then <neighbor> is part of the cluster. fortify any armies back and add to the List
          board.fortifyArmies(neighbor.getMoveableArmies(), neighbor, (Country) cluster.get(i));
          cluster.add(neighbor);
        }
      }
    }
  }