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