
jadex.bdi.examples.blackjack.dealer.DealerGameRoundMasterPlan 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.dealer;
import jadex.bdi.examples.blackjack.Card;
import jadex.bdi.examples.blackjack.CardSet;
import jadex.bdi.examples.blackjack.Dealer;
import jadex.bdi.examples.blackjack.GameStatistics;
import jadex.bdi.examples.blackjack.Player;
import jadex.bdi.runtime.IGoal;
import jadex.bdi.runtime.Plan;
import jadex.commons.SUtil;
/**
* Play a game round (controls the plans responsible for single players).
*/
public class DealerGameRoundMasterPlan extends Plan
{
//-------- methods --------
/**
* Plan body.
*/
public void body()
{
// long timeout = ((Long)getBeliefbase().getBelief("playerwaitmillis").getFact()).longValue();
// System.out.println("playerwaitmillis: "+timeout);
CardSet cardset = new CardSet();
getBeliefbase().getBelief("cardset").setFact(cardset);
Dealer me = (Dealer)getBeliefbase().getBelief("myself").getFact();
me.setState(Dealer.STATE_GAME_STARTED);
// Trigger plan for each player.
Player[] players = (Player[])getBeliefbase().getBeliefSet("players").getFacts();
IGoal[] goals = new IGoal[players.length];
for(int i=0; i 16
// this is a blackjack-rule
boolean first = true;
while(CardSet.calculateDeckValue(me.getCards()) <= 16)
{
// Wait for the dealer's turn.
getLogger().info("Now waiting for dealer's turn.");
// System.out.println("Now waiting for dealer's turn.");
if(first)
{
waitForCondition("dealers_first_turn");//, timeout*10); // Hmmm... use timeout???
first = false;
}
else
{
waitForCondition("dealers_second_turn");//, timeout)
}
getLogger().info("Dealer's turn. Players: "+SUtil.arrayToString(players));
// Wait until allowed to draw card (step-mode or delay).
if(((Boolean)getBeliefbase().getBelief("singleStepMode").getFact()).booleanValue())
{
waitForInternalEvent("step");
}
else
{
// System.out.println("Stepdelay: "+getBeliefbase().getBelief("stepdelay").getFact());
waitFor(1000*((Number)getBeliefbase().getBelief("stepdelay").getFact()).intValue());
}
// now go ahead, draw the card and update the beliefbase
Card dealerCard = cardset.drawCard();
me.addCard(dealerCard);
getLogger().info("Dealer draws a new card, it's " + dealerCard + " deck-value=" + CardSet.calculateDeckValue(me.getCards()));
}
// Dealer result calculation.
getLogger().info("Dealer finished drawing cards");
int newaccount = me.getAccount();
for(int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy