/* * AttackStrongestStrategy.java * * Created on April 9, 2004, 2:39 AM */ package simulations.core.strategy.attackStrategy; import simulations.core.Player; import java.util.ArrayList; import java.util.Iterator; import simulations.core.history.Turn; /** This class describes an attack strategy that always attack the strongest * remaining players * @author tom */ public class AttackStrongestStrategy extends AttackStrategy { /** Creates a new instance of AttackStrongestStrategy */ public AttackStrongestStrategy() { super(); name="AttackStrongestStrategy"; memoryParam=false; abr="4"; } /** return the player to attack * @param player The attacking player * @param playerList The list of avalaible player * @return The player to attack */ public ArrayList getPlayerToAttack(simulations.core.Player player, java.util.ArrayList playerList) { playerList.remove(player); float max=0; ArrayList l = new ArrayList(); Player attackedPlayer = null; //Iterator it = playerList.iterator(); for(int i=0;imax) { l.clear(); l.add(p); max=p.getHitPoints(); } else if (p.getHitPoints()==max) { l.add(p); } } if (negative) { ArrayList l2 = new ArrayList(); Iterator 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, Player player, ArrayList remainingPlayers) { } /** return the description of this attack strategy * @return return the description of this attack strategy **/ public String getDescription() { if (negative) { return "Attack strategy :\n"+ "I always attack the strongest of the list\n"+ "COMPLEMENTARY"; } else { return "Attack strategy :\n"+ "I always attack the strongest of the list\n"; } } }