Example #1
0
 public void testCardMaskString() {
   long mask = maskAs | maskAh | mask2h;
   assertEquals("As Ah 2h", Deck.cardMaskString(mask));
   assertEquals("AsAh2h", Deck.cardMaskString(mask, ""));
   assertEquals("As Ah 2h", Deck.cardMaskString(mask, " "));
   assertEquals("As/Ah/2h", Deck.cardMaskString(mask, "/"));
 }
Example #2
0
 /** Convert specific starting hand to HoldemAtomicGroup object.
     @param groupSpec starting hand (e.g., AhKd, 8h3s)
 */
 public HoldemAtomicGroup(String groupSpec) {
   myspec = groupSpec;
   myhands = new HashSet();
   Perl5Compiler compiler = new Perl5Compiler();
   Perl5Matcher matcher = new Perl5Matcher();
   Pattern atomicPattern;
   try {
     atomicPattern = compiler.compile
       ("^([AKQJT98765432])([shdc])([AKQJT98765432])([shdc])$");
   } catch (MalformedPatternException e) {
     throw new RuntimeException("BUG: " + e.toString());
   }
   MatchResult result;
   if (matcher.matches(groupSpec, atomicPattern)) {
     result = matcher.getMatch();
     int rank1 = Deck.parseRank(result.group(1));
     int suit1 = Deck.parseSuit(result.group(2));
     int rank2 = Deck.parseRank(result.group(3));
     int suit2 = Deck.parseSuit(result.group(4));
     addAtomic(rank1, suit1, rank2, suit2);
   } else {
     throw new IllegalArgumentException("unable to parse groupSpec: " +
                                        groupSpec);
   }
 }
Example #3
0
 private void addAtomic(int rank1, int suit1, int rank2, int suit2) {
   if (rank1 == rank2 && suit1 == suit2)
     throw new IllegalArgumentException("atomic cards are identical");
   long card1 = Deck.createCardMask(rank1, suit1);
   long card2 = Deck.createCardMask(rank2, suit2);
   long hand = card1 | card2;
   myhands.add(new Long(hand));
 }
Example #4
0
 public void testCreateCardMask() {
   // should match macro StdDeck_MASK in deck_std.h
   assertEquals(maskAs, Deck.createCardMask(Deck.RANK_ACE, Deck.SUIT_SPADES));
   // should match macro JokerDeck_MASK in deck_joker.h
   assertEquals(maskJoker, Deck.createCardMask(Deck.RANK_JOKER, Deck.SUIT_JOKER));
   // create hand with "As Ah 2h"
   int[] ranks = {Deck.RANK_ACE, Deck.RANK_ACE, Deck.RANK_2};
   int[] suits = {Deck.SUIT_SPADES, Deck.SUIT_HEARTS, Deck.SUIT_HEARTS};
   long mask = Deck.createCardMask(ranks, suits);
   long expected = maskAs | maskAh | mask2h;
   assertEquals(expected, mask);
 }
Example #5
0
  // Pre-flop
  public char preFlopBasedInGMGroups(AdvancedClientPokerDynamics dynamics) {

    HoldemSMGroup gSM1 = new HoldemSMGroup("SM1");
    HoldemSMGroup gSM2 = new HoldemSMGroup("SM2");
    HoldemSMGroup gSM3 = new HoldemSMGroup("SM3");
    HoldemSMGroup gSM4 = new HoldemSMGroup("SM4");
    HoldemSMGroup gSM5 = new HoldemSMGroup("SM5");
    HoldemSMGroup gSM6 = new HoldemSMGroup("SM6");
    HoldemSMGroup gSM7 = new HoldemSMGroup("SM7");
    HoldemSMGroup gSM8 = new HoldemSMGroup("SM8");
    HoldemSMGroup gSM9 = new HoldemSMGroup("SM9");
    long longCards =
        Deck.parseCardMask(
            "" + dynamics.hole[dynamics.seatTaken][0] + dynamics.hole[dynamics.seatTaken][1]);

    if (gSM9.isHandInGroup(longCards)) return 'f';
    else if (gSM1.isHandInGroup(longCards)
        || gSM2.isHandInGroup(longCards)
        || gSM3.isHandInGroup(longCards)
        || gSM4.isHandInGroup(longCards)) return 'r';
    else if (gSM5.isHandInGroup(longCards)
        || gSM6.isHandInGroup(longCards)
        || gSM7.isHandInGroup(longCards)
        || gSM8.isHandInGroup(longCards)) return 'c';

    return 'f';
  }
Example #6
0
 /** A simple demonstration of AsianStudEval methods. */
 public static void main(String[] args) {
   int[] ranks = new int[5];
   int[] suits = new int[5];
   ranks[0] = Deck.RANK_ACE;
   suits[0] = Deck.SUIT_HEARTS;
   ranks[1] = Deck.RANK_7;
   suits[1] = Deck.SUIT_HEARTS;
   ranks[2] = Deck.RANK_8;
   suits[2] = Deck.SUIT_HEARTS;
   ranks[3] = Deck.RANK_9;
   suits[3] = Deck.SUIT_SPADES;
   ranks[4] = Deck.RANK_TEN;
   suits[4] = Deck.SUIT_SPADES;
   long mask = Deck.createCardMask(ranks, suits);
   System.out.println("In Java: cards=[" + Deck.cardMaskString(mask) + "]");
   try {
     long hival = EvalHigh(ranks, suits);
     System.out.println("In Java: hival=" + hival + "\n");
   } catch (Exception e) {
     System.out.println("In Java: caught exception: " + e);
   }
 }
Example #7
0
  public void testCreateCardIndex() {
    // should match macro StdDeck_MAKE_CARD in deck_std.h
    assertEquals(index2s, Deck.createCardIndex(Deck.RANK_2, Deck.SUIT_SPADES));
    assertEquals(index2h, Deck.createCardIndex(Deck.RANK_2, Deck.SUIT_HEARTS));
    assertEquals(index2d, Deck.createCardIndex(Deck.RANK_2, Deck.SUIT_DIAMONDS));
    assertEquals(index2c, Deck.createCardIndex(Deck.RANK_2, Deck.SUIT_CLUBS));
    assertEquals(indexAs, Deck.createCardIndex(Deck.RANK_ACE, Deck.SUIT_SPADES));
    assertEquals(indexAh, Deck.createCardIndex(Deck.RANK_ACE, Deck.SUIT_HEARTS));
    assertEquals(indexAd, Deck.createCardIndex(Deck.RANK_ACE, Deck.SUIT_DIAMONDS));
    assertEquals(indexAc, Deck.createCardIndex(Deck.RANK_ACE, Deck.SUIT_CLUBS));

    // should match macro JokerDeck_JOKER in deck_joker.h
    assertEquals(indexJoker, Deck.createCardIndex(Deck.RANK_JOKER, Deck.SUIT_JOKER));

    // check illegal cases
    try {
      Deck.createCardIndex(Deck.RANK_COUNT, Deck.SUIT_SPADES);
      fail("Should raise IllegalArgumentException");
    } catch (RuntimeException e) {
    }
    try {
      Deck.createCardIndex(Deck.RANK_2, Deck.SUIT_COUNT);
      fail("Should raise IllegalArgumentException");
    } catch (RuntimeException e) {
    }
    try {
      Deck.createCardIndex(Deck.RANK_JOKER, Deck.SUIT_SPADES);
      fail("Should raise IllegalArgumentException");
    } catch (RuntimeException e) {
    }
    try {
      Deck.createCardIndex(Deck.RANK_2, Deck.SUIT_JOKER);
      fail("Should raise IllegalArgumentException");
    } catch (RuntimeException e) {
    }
  }
Example #8
0
 public void testParseSuit() {
   assertEquals(Deck.SUIT_SPADES, Deck.parseSuit("s"));
   assertEquals(Deck.SUIT_HEARTS, Deck.parseSuit("h"));
   assertEquals(Deck.SUIT_DIAMONDS, Deck.parseSuit("d"));
   assertEquals(Deck.SUIT_CLUBS, Deck.parseSuit("c"));
 }
Example #9
0
 public void testParseRank() {
   assertEquals(Deck.RANK_ACE, Deck.parseRank("A"));
   assertEquals(Deck.RANK_TEN, Deck.parseRank("T"));
   assertEquals(Deck.RANK_2, Deck.parseRank("2"));
   assertEquals(Deck.RANK_JOKER, Deck.parseRank("X"));
 }
Example #10
0
 public void testCardString() {
   assertEquals("Td", Deck.cardString(Deck.RANK_TEN, Deck.SUIT_DIAMONDS));
   assertEquals("Xx", Deck.cardString(Deck.RANK_JOKER, Deck.SUIT_JOKER));
 }
Example #11
0
 public void testParseCardMask() {
   long mask = Deck.parseCardMask("As Ah 2h");
   long expected = maskAs | maskAh | mask2h;
   assertEquals(expected, mask);
 }