📄 betterpixie.java
字号:
enemyCount *= 1.3; CountryIterator continent = new ContinentIterator(cont, countries); while (continent.hasNext()) if (continent.next().getOwner() != ID) enemyCount++; // Count the friendlies (our armies in the cont and our armies in countries neighboring the cont) int friendlyCount = BoardHelper.getPlayerArmiesInContinent(ID, cont, countries); friendlyCount += BoardHelper.getPlayerArmiesAdjoiningContinent(ID, cont, countries); debug("Attacking in continent "+board.getContinentName(cont)+". friendlies = "+friendlyCount+", enemies = "+enemyCount); if (enemyCount > friendlyCount) return; boolean attackMade = true; while (attackMade) { // We cycle through the continent 2 seperate times... // Start by only attacking from our countries that have 1 enemy country while (attackMade) { attackMade = false; continent = new ContinentIterator(cont, countries); while (continent.hasNext()) { Country c = continent.next(); if (c.getOwner() == ID && getNumberOfEnemyNeighborsInOurConts(c) == 1 && c.getArmies() > 1) { // This country can only attack 1 good destination, so attack it Country[] adjoining = c.getAdjoiningList(); for(int i = 0; i < adjoining.length; i++) if (adjoining[i].getOwner() != ID && ourConts[adjoining[i].getContinent()] && c.getArmies() > adjoining[i].getArmies()*outnumberBy) { board.attack(c, adjoining[i], true); attackMade = true; } } } } // Now make any good attacks we can... 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); attackMade = true; } } } } } }// A check to see if someone else owns this continent. If they do then we try to kill itprotected void takeOutContinentCheck( int cont ) { if (BoardHelper.anyPlayerOwnsContinent( cont, countries ) && board.getContinentBonus(cont) > 0) { if (countries[BoardHelper.getCountryInContinent(cont, countries)].getOwner() != ID) { debug("enemy owns continent "+cont); // then an enemy owns this continent. // calculate if it's worth it to hit the continent/* int continentBonus = board.getContinentBonus(cont); int[] path = BoardHelper.cheapestRouteFromOwnerToCont(ID, cont, countries); if (path != null) { int costToHit = pathCost(path); if (costToHit < continentBonus) { System.out.println(board.getPlayerName(ID)+" thinks it is worth it to take out continent "+board.getContinentName(cont)+" from player "+board.getPlayerName(countries[BoardHelper.getCountryInContinent(cont, countries)].getOwner())+" ("+continentBonus+" bonus vs "+costToHit+" costToHit)"); } }*/ // Check all of it's borders for a weak spot int[] borders = BoardHelper.getContinentBorders(cont, countries); for (int b = 0; b < borders.length; b++) { Country[] neigbors = countries[borders[b]].getAdjoiningList(); for (int n = 0; n < neigbors.length; n++) { if (neigbors[n].getOwner() == ID && neigbors[n].getArmies() > countries[borders[b]].getArmies() * 2 && neigbors[n].canGoto(countries[borders[b]])) { // kill him debug("attacking to take out continent "+cont); if (board.attack(neigbors[n], countries[borders[b]], true) > 0) return; } } } } } }protected int getNumberOfEnemyNeighborsInOurConts(Country c) { int result = 0; Country[] adjoining = c.getAdjoiningList(); for(int i = 0; i < adjoining.length; i++) if (adjoining[i].getOwner() != ID && ourConts[adjoining[i].getContinent()]) result++; return result; }public int moveArmiesIn( int cca, int ccd) { int testCode = obviousMoveArmiesInTest(cca, ccd); if (testCode != -1) return testCode; testCode = memoryMoveArmiesInTest(cca, ccd); if (testCode != -1) return testCode; // test if they border any enemies at all: int attackerEnemies = countries[cca].getNumberEnemyNeighbors(); int defenderEnemies = countries[ccd].getNumberEnemyNeighbors(); if (attackerEnemies == 0 && defenderEnemies != 0) return 1000000; else if (attackerEnemies != 0 && defenderEnemies == 0) return 0; // Possibly they both have 0 enemies: else if (defenderEnemies == 0) return countries[cca].getArmies()/2; // OK, so they both have some enemies. Look again only considering the enemies that are in conts we care about. // (And make a note of the enemies for later) List attackerEnemyList = new ArrayList(), defenderEnemyList = new ArrayList(); attackerEnemies = 0; defenderEnemies = 0; Country[] adjoining = countries[cca].getAdjoiningList(); for(int i = 0; i < adjoining.length; i++) if (adjoining[i].getOwner() != ID && ourConts[adjoining[i].getContinent()]) attackerEnemyList.add(adjoining[i]); adjoining = countries[ccd].getAdjoiningList(); for(int i = 0; i < adjoining.length; i++) if (adjoining[i].getOwner() != ID && ourConts[adjoining[i].getContinent()]) defenderEnemyList.add(adjoining[i]); if (attackerEnemyList.size() == 0 && defenderEnemyList.size() != 0) return 1000000; else if (attackerEnemyList.size() != 0 && defenderEnemyList.size() == 0) return 0; // Possibly they both have 0 enemies in conts we want: else if (attackerEnemyList.size() == 0) return countries[cca].getArmies()/2; // OK, so they both have some enemies in continents we care about. Do they connect? List allEnemies = new ArrayList(attackerEnemyList); for (int i = 0; i < defenderEnemyList.size(); i++) if (! allEnemies.contains(defenderEnemyList.get(i))) allEnemies.add(defenderEnemyList.get(i)); CountryClusterSet enemySet = CountryClusterSet.getHostileCountries(ID, allEnemies); // If they all connect then move everyone in if (enemySet.numberOfClusters() == 1) return 1000000; return countries[cca].getArmies()/2; }public void fortifyPhase() { for (int i = 0; i < numContinents; i++) { if (BoardHelper.playerOwnsContinent(ID, i, countries)) { while( fortifyContinent( i )) { debug("Fortifying continent "+board.getContinentName(i)); } } else { fortifyContinentScraps(i); } } } // End of fortifyPhase() methodprotected boolean fortifyContinent( int cont ) { boolean fortifiedSomething = false; // 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 && neighbor.getMoveableArmies() > 0) { debug(" -> fortify "+neighbor.getMoveableArmies()+" armies from "+neighbor+" to "+cluster.get(i)); // Then <neighbor> is part of the cluster. fortify any armies back and add to the List if (board.fortifyArmies( neighbor.getMoveableArmies(), neighbor, (Country)cluster.get(i) ) == 1) fortifiedSomething = true; cluster.add(neighbor); } } } return fortifiedSomething; }// 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 ); } } } }public String youWon() { String[] answers = new String[] { "Poof! I win" }; return answers[ rand.nextInt(answers.length) ]; }} // End of Pixie class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -