Package org.cspoker.common.elements.cards

Examples of org.cspoker.common.elements.cards.Card


  protected void drawOpenCard() {
    game.addOpenCard(drawCard());
  }
 
  protected void drawOpenCardAndPublishCommonCard() {
    Card card = drawCard();
    game.addOpenCard(card);
    gameMediator.publishNewCommonCardsEvent(new NewCommunityCardsEvent(EnumSet.of(card)));
  }
View Full Code Here


      int nbSamplesPerBucket = 6;
      int nbSamples = nbBuckets*nbSamplesPerBucket;
      for(int i=0;i<nbSamples;i++){

        int rank = startRank;
        Card sampleCard1;
        do{
          sampleCard1 = Card.values()[random.nextInt(Card.values().length)];
        }while(cards.contains(sampleCard1));
        rank = handRanks[sampleCard1.ordinal() + 1 + rank];

        Card sampleCard2;
        do{
          sampleCard2 = Card.values()[random.nextInt(Card.values().length)];
        }while(cards.contains(sampleCard2) || sampleCard2.equals(sampleCard1));
        rank = handRanks[sampleCard2.ordinal() + 1 + rank];

        int type = (rank >>> 12) - 1;
        rank = rank & 0xFFF;
        rank = offsets[type] + rank - 1;

View Full Code Here

   * Returns the card with the highest rank in this hand. If there are plural
   * cards with equal highest rank, the suits of the cards are used.(clubs
   * ranking the lowest, followed by diamonds,hearts, and spades as in bridge)
   */
  public Card getHighestRankCard() {
    Card highestRankCard = null;
    for(Card card:cards){
      if(highestRankCard==null || card.compareTo(highestRankCard)==1){
        highestRankCard  = card;
      }
    }
View Full Code Here

    }

  };

  protected Card drawNewCard(EnumSet<Card> usedCards) {
    Card communityCard;
    do {
      communityCard = getRandomCard();
    } while (usedCards.contains(communityCard));
    usedCards.add(communityCard);
    return communityCard;
View Full Code Here

    for (int i = 0; i < nbCommunitySamples; i++) {
      int communitySampleRank = fixedRank;
      EnumSet<Card> usedCommunityAndBotCards = EnumSet.copyOf(usedFixedCommunityAndBotCards);
      EnumSet<Card> usedCommunityCards = EnumSet.copyOf(usedFixedCommunityCards);
      for (int j = 0; j < nbMissingCommunityCards; j++) {
        Card communityCard = drawNewCard(usedCommunityAndBotCards);
        if (traceEnabled) {
          logger.trace("Evaluating sampled community card "
              + communityCard);
        }
        usedCommunityCards.add(communityCard);
        communitySampleRank = updateIntermediateRank(
            communitySampleRank, communityCard);
      }
      if (traceEnabled) {
        logger.trace("Evaluating bot cards " + botCard1 + " "
            + botCard2);
      }
      int botRank = getFinalRank(communitySampleRank, botCard1, botCard2);

      //      int minSampleRank = Integer.MAX_VALUE;
      //      int maxSampleRank = Integer.MIN_VALUE;
      //      int sum = 0;
      Multiset<Integer> ranks = new TreeMultiset<Integer>();
      Multiset<Integer> deadRanks = new TreeMultiset<Integer>();
      int n = 100;
      for (int j = 0; j < n; j++) {
        EnumSet<Card> handCards = EnumSet.copyOf(usedCommunityCards);
        Card sampleCard1 = drawNewCard(handCards);
        Card sampleCard2 = drawNewCard(handCards);
        int sampleRank = getFinalRank(communitySampleRank, sampleCard1, sampleCard2);
        ranks.add(sampleRank);
        if(botCard1.equals(sampleCard1) || botCard1.equals(sampleCard2)
            || botCard2.equals(sampleCard1) || botCard2.equals(sampleCard2)){
          deadRanks.add(sampleRank);
View Full Code Here

    for (int i = 0; i < nbCommunitySamples; i++) {
      int communitySampleRank = fixedRank;
      EnumSet<Card> usedCommunityAndBotCards = EnumSet
          .copyOf(usedFixedCommunityAndBotCards);
      for (int j = 0; j < nbMissingCommunityCards; j++) {
        Card communityCard = drawNewCard(usedCommunityAndBotCards);
        if (traceEnabled) {
          logger.trace("Evaluating sampled community card "
              + communityCard);
        }
        communitySampleRank = updateIntermediateRank(
            communitySampleRank, communityCard);
      }
      if (traceEnabled) {
        logger.trace("Evaluating bot cards " + botCard1 + " "
            + botCard2);
      }
      int botRank = getFinalRank(communitySampleRank, botCard1, botCard2);
      for (int j = 0; j < nbOpponentSamples; j++) {
        EnumSet<Card> usedOpponentCards = EnumSet
            .copyOf(usedCommunityAndBotCards);
        double logProb = 0;
        int maxOpponentWin = 0;
        drawers.clear();
        for (PlayerState opponentThatCanWin : activeOpponents) {
          Card opponentCard1 = drawNewCard(usedOpponentCards);
          Card opponentCard2 = drawNewCard(usedOpponentCards);
          int opponentRank = getFinalRank(communitySampleRank,opponentCard1, opponentCard2);
          if (traceEnabled) {
            logger.trace("Evaluating sampled opponent cards "
                + opponentCard1 + " " + opponentCard2);
          }
View Full Code Here

    for (int i = 0; i < nbCommunitySamples; i++) {
      EnumSet<Card> fixedAndCommunityCards = EnumSet
      .copyOf(usedFixedCards);
      EnumSet<Card> communityCards = EnumSet.copyOf(fixedCommunityCards);
      for (int j = 0; j < nbMissingCommunityCards; j++) {
        Card communityCard;
        do {
          communityCard = getRandomCard();
        } while (fixedAndCommunityCards.contains(communityCard));
        fixedAndCommunityCards.add(communityCard);
        communityCards.add(communityCard);
      }
      for (int j = 0; j < nbOpponentSamples; j++) {
        EnumSet<Card> fixedAndCommunityAndOpponentCards = EnumSet
        .copyOf(fixedAndCommunityCards);
        // fixedAndCommunityCards coincidentally contains the bot's
        // hand!
        int botRank = getRank(fixedAndCommunityCards);
        boolean botWins = true;
        for (int k = 0; k < nbOpponents; k++) {
          Card opponentFirst;
          do {
            opponentFirst = getRandomCard();
          } while (fixedAndCommunityAndOpponentCards
              .contains(opponentFirst));
          fixedAndCommunityAndOpponentCards.add(opponentFirst);
          Card opponentSecond;
          do {
            opponentSecond = getRandomCard();
          } while (fixedAndCommunityAndOpponentCards
              .contains(opponentSecond));
          fixedAndCommunityAndOpponentCards.add(opponentSecond);
View Full Code Here

    for (int i = 0; i < nbCommunitySamples; i++) {
      EnumSet<Card> fixedAndCommunityCards = EnumSet
      .copyOf(usedFixedCards);
      EnumSet<Card> communityCards = EnumSet.copyOf(fixedCommunityCards);
      for (int j = 0; j < nbMissingCommunityCards; j++) {
        Card communityCard;
        do {
          communityCard = getRandomCard();
        } while (fixedAndCommunityCards.contains(communityCard));
        fixedAndCommunityCards.add(communityCard);
        communityCards.add(communityCard);
      }
      for (int j = 0; j < nbOpponentSamples; j++) {
        EnumSet<Card> fixedAndCommunityAndOpponentCards = EnumSet
        .copyOf(fixedAndCommunityCards);
        // fixedAndCommunityCards coincidentally contains the bot's
        // hand!
        int botRank = getRank(fixedAndCommunityCards);
        boolean botWins = true;
        for (int k = 0; k < nbOpponents; k++) {
          Card opponentFirst;
          do {
            opponentFirst = getRandomCard();
          } while (fixedAndCommunityAndOpponentCards
              .contains(opponentFirst));
          fixedAndCommunityAndOpponentCards.add(opponentFirst);
          Card opponentSecond;
          do {
            opponentSecond = getRandomCard();
          } while (fixedAndCommunityAndOpponentCards
              .contains(opponentSecond));
          fixedAndCommunityAndOpponentCards.add(opponentSecond);
View Full Code Here

    return state.getGameState();
  }
 
  public boolean havePocketPair() {
    Set<Card> cards = getPocketCards();
    Card previous = null;
    for (Card card : cards) {
      if (previous == null) {
        previous = card;
      } else {
        if (previous.getRank().equals(card.getRank())) {
          return true;
        }
      }
    }
    return false;
View Full Code Here

    @Override
    public void onPlayerCards(PlayerCards playerCards) {
      //don't consider card 255 which is a hidden card
      if(playerCards.getSerial() == serial
          && gameStateContainer.getGameState().getPlayer(new PlayerId(serial)).getCards().size()==0){
        Card card0 = Card.fromPokersourceInt(playerCards.getCards()[0]);
        Card card1 = Card.fromPokersourceInt(playerCards.getCards()[1]);
        smartListener.onNewPocketCards(new NewPocketCardsEvent(EnumSet.of(card0, card1)));
      }
    }
View Full Code Here

TOP

Related Classes of org.cspoker.common.elements.cards.Card

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.