/*
* SpitefulAttackStrategy.java
*
* Created on April 14, 2004, 3:14 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 spiteful strategy for attack
* It attack the players that had attacked me
* @author tom
*/
public class SpitefulAttackStrategy extends AttackStrategy {
/** This list store the player that have already attack me and are
* still in the game **/
private ArrayList attackList;
/** Creates a new instance of SpitefulAttackStrategy */
public SpitefulAttackStrategy() {
super();
attackList = new ArrayList();
name="SpitefulAttackStrategy";
memoryParam=true;
abr="15";
}
/** 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) {
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