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);
       }
     }
   }
 }