示例#1
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;
 }
示例#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;
  }
示例#3
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);
        }
      }
    }
  }