/*
* AttackTheMostAttackedPlayerStrategy.java
*
* Created on April 24, 2004, 2:58 AM
*/
package simulations.core.strategy.attackStrategy;
import java.util.ArrayList;
import java.util.Iterator;
import simulations.core.strategy.PlayerIntElement;
import simulations.core.strategy.PlayerObjectElement;
import simulations.core.strategy.ObjectIntElement;
import simulations.core.Player;
import simulations.core.history.PlayerTurn;
/**
* This class describes an attack strategy that attack the player
* the most attacked in the game
* @author tom
*/
public class AttackTheMostAttackedPlayerStrategy extends AttackStrategy {
/** This list store the players an the number of time
* they have been attacked **/
private ArrayList playersStatList;
/** Creates a new instance of AttackTheMostAttackedPlayerStrategy */
public AttackTheMostAttackedPlayerStrategy() {
super();
name="AttackTheMostAttackedPlayerStrategy";
playersStatList=new ArrayList();
memoryParam=true;
abr="6";
}
/** 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 player that have been\n"+
"the most attacked memory="+memory+"\n"+
"COMPLEMENTARY";
} else {
return "Attack strategy \n"+
"I attack the player that have been\n"+
"the most attacked 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) {
Iterator it = playersStatList.iterator();
// This list will store
if (simulations.SimulationParameters.debug) {
System.out.println("PlayersStatList : ");
}
ArrayList l = new ArrayList();
int max=-1;
while (it.hasNext()) {
ObjectIntElement obj = (ObjectIntElement)it.next();
PlayerIntElement elt = (PlayerIntElement)obj.getObject();
if (simulations.SimulationParameters.debug) {
System.out.println(elt.getPlayer()+" "+elt.getNb()+" "+obj.getNb());
}
if (elt.getPlayer().equals(player)) {
continue;
}
if (elt.getNb()==max) {
l.add(elt.getPlayer());
} else if (elt.getNb()>max) {
max=elt.getNb();
l.clear();
l.add(elt.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