/** 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); } }
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")); }