/* * SpitefulAttackStrategy2.java * * Created on April 21, 2004, 2:08 AM */ package simulations.core.strategy.attackStrategy; import simulations.core.Player; import simulations.core.Attack; import simulations.core.history.PlayerTurn; import simulations.core.strategy.PlayerIntElement; import java.util.ArrayList; import java.util.Iterator; /** * This class describes a second spiteful strategy. It attack the player(s) * that attack me directly or indirectly * @author tom */ public class SpitefulAttackStrategy2 extends AttackStrategy { /** This list store the player that have already attack me or support an attack on me and are * still in the game **/ private ArrayList attackList; /** Creates a new instance of SpitefulAttackStrategy2 */ public SpitefulAttackStrategy2() { super(); attackList = new ArrayList(); name="SpitefulAttackStrategy2"; memoryParam=true; abr="16"; } /** 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 attack the players that have attacked me \n"+ "or have support an attack on me\n"+ "memory="+memory+" COMPLEMENTARY\n"; } else { return "Attack strategy \n"+ "I attack the players that have attacked me \n"+ "or have support an attack on me\n"+ "memory="+memory+"\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(); if (simulations.SimulationParameters.debug) { System.out.println("attackList = "+attackList); } Iterator it = attackList.iterator(); while (it.hasNext()) { l.add(((PlayerIntElement)it.next()).getPlayer()); } 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 returns true if the player p is already in notAskingList * @return true if the player p is already in notAskingList false otherwise **/ private boolean containsPlayer(Player p) { for(int i=0;i