/* * AttackStrongestThanMeStrategy.java * * Created on May 16, 2004, 12:27 AM */ package simulations.core.strategy.attackStrategy; import java.util.ArrayList; import java.util.Iterator; import simulations.core.Player; import simulations.core.history.Turn; /** * This class describes an attack strategy that attack all players that have more points than me * @author tom */ public class AttackStrongestThanMeStrategy extends AttackStrategy { /** Creates a new instance of AttackStrongestThanMeStrategy */ public AttackStrongestThanMeStrategy() { super(); name="AttackStrongestThanMeStrategy"; memoryParam=false; abr="5"; } /** return the description of this attack strategy * @return return the description of this attack strategy **/ public String getDescription() { if (negative) { return "attack : I attack all players\n"+ "that have more points than me\n"+ "COMPLEMENTARY"; } else { return "attack : I attack all players\n"+ "that have more points than me\n"; } } /** return the player to attack * @param player The attacking player * @param playerList The list of avalaible player * @return The player to attack */ public java.util.ArrayList getPlayerToAttack(simulations.core.Player player, java.util.ArrayList playerList) { ArrayList l = new ArrayList(); Iterator it = playerList.iterator(); while (it.hasNext()) { Player p = (Player)it.next(); if (p.getHitPoints()>player.getHitPoints()) { l.add(p); } } if (negative) { ArrayList l2 = new ArrayList(); it = playerList.iterator(); while (it.hasNext()) { Player p = (Player)it.next(); if (p.equals(player)) { continue; } if (!(l.contains(p))) { l2.add(p); } } return l2; } else { return l; } } /** This method is called by the judge to inform players of the last turn * @param turn The turn * @param player The owner of the strategy * @param remainingPlayers The list of the remaining players */ public void updateLastTurn(simulations.core.history.Turn turn, simulations.core.Player player, java.util.ArrayList remainingPlayers) { } }