
jadex.bdi.examples.blackjack.player.strategies.AbstractStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-bdi Show documentation
Show all versions of jadex-applications-bdi Show documentation
The Jadex BDI applications package contain
several example applications, benchmarks and
testcases using BDI agents.
The newest version!
package jadex.bdi.examples.blackjack.player.strategies;
import jadex.bdi.examples.blackjack.Card;
import jadex.commons.SReflect;
import java.util.ArrayList;
import java.util.List;
/**
* Abstract base class for strategies.
*/
public abstract class AbstractStrategy implements IStrategy
{
//-------- constants --------
/** Constants for strategy names. */
public static final String CONSTANT_VERY_CAREFUL = "ConstantVeryCareful";
public static final String CONSTANT_CAREFUL = "ConstantCareful";
public static final String CONSTANT_RISKY = "ConstantRisky";
public static final String CONSTANT_VERY_RISKY = "ConstantVeryRisky";
public static final String STOCHASTIC_TABLE = "StochasticTable";
public static final String HUMAN_PLAYER = "HumanPlayer";
//-------- attributes --------
/** The strategy name. */
protected String name;
/** The strategies. */
protected static final List strategies;
//-------- constructors --------
/**
* Create a new strategy.
*/
public AbstractStrategy(String name)
{
this.name = name;
}
//-------- methods --------
/**
* Depending on the strategy, this methods calculates the bet-amount.
* @param account The account-status of the player.
* @return how much money the player should bet.
*/
public abstract int makeBet(int account);
/**
* Depending on the strategy, this methods decides whether to draw one more card or not.
* @param agentcards A String-array containing all the players cards.
* @param dealercard This String represents the dealer's open card.
* @return whether the player should draw one more card or not.
*/
public abstract boolean drawCard(Card[] agentcards, Card dealercard);
/**
* Get the name.
* @return The strategy name.
*/
public String getName()
{
return name;
}
/**
* Return a string representation.
*/
public String toString()
{
return SReflect.getInnerClassName(this.getClass());
}
/**
* Return the hash code.
*/
public int hashCode()
{
return getClass().hashCode();
}
/**
* Test if two strategies are equal.
*/
public boolean equals(Object o)
{
return o instanceof IStrategy && ((IStrategy)o).getName().equals(getName());
}
static
{
strategies = new ArrayList();
strategies.add(new ConstantStrategy(CONSTANT_VERY_CAREFUL, 10, 15));
strategies.add(new ConstantStrategy(CONSTANT_CAREFUL, 10, 16));
strategies.add(new ConstantStrategy(CONSTANT_RISKY, 10, 17));
strategies.add(new ConstantStrategy(CONSTANT_VERY_RISKY, 10, 18));
strategies.add(new StochasticTable(STOCHASTIC_TABLE));
}
/**
* Get the strategy names.
* @return The strategy names.
*/
public static String[] getStrategyNames()
{
List ret = new ArrayList();
for(int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy