// returns true if we want at least one continent boolean setupOurConts(int numberOfArmies) { if (ourConts == null) ourConts = new boolean[numContinents]; // calculate the armies needed to conquer each continent int[] neededForCont = new int[numContinents]; for (int i = 0; i < numContinents; i++) { neededForCont[i] = BoardHelper.getEnemyArmiesInContinent(ID, i, countries); // enemies in the cont neededForCont[i] -= BoardHelper.getPlayerArmiesInContinent(ID, i, countries); // minus our armies in the cont // also minus our armies in countries neighboring the cont neededForCont[i] -= BoardHelper.getPlayerArmiesAdjoiningContinent(ID, i, countries); } // say we can give at most (1/numContinents)*numberOfArmies armies to each continent. boolean wantACont = false; // if we think we can take/hold any continents for (int i = 0; i < numContinents; i++) { if (neededForCont[i] < (1.0 / numContinents) * numberOfArmies && board.getContinentBonus(i) > 0) { ourConts[i] = true; wantACont = true; } else ourConts[i] = false; } return wantACont; }
// a test of whether or not we should send some armies this cont's way protected boolean continentNeedsHelp(int cont) { // if we don't own it then it deffinately needs some help if (!BoardHelper.playerOwnsContinent(ID, cont, countries)) return true; // otherwise we own it. // check each border int[] borders = BoardHelper.getContinentBorders(cont, countries); for (int i = 0; i < borders.length; i++) { if (borderCountryNeedsHelp(countries[borders[i]])) return true; } return false; }
public int pickCountry() { // our first choice is the continent with the least # of borders that is totally empty if (goalCont == -1 || !BoardHelper.playerOwnsContinentCountry(-1, goalCont, countries)) { setGoalToLeastBordersCont(); } // so now we have picked a cont... return pickCountryInContinent(goalCont); }
public void fortifyPhase() { for (int i = 0; i < numContinents; i++) { if (BoardHelper.playerOwnsContinent(ID, i, countries)) { fortifyContinent(i); } else { fortifyContinentScraps(i); } } } // End of fortifyPhase() method
// 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; }
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); } } } }