def generate_all_twos(skip_rank_ix: int = -1) -> Iterable[Tuple[DeucesCard]]: rs = DeucesCard.RANK_ORDER if skip_rank_ix == -1 else ( DeucesCard.RANK_ORDER[:skip_rank_ix] + DeucesCard.RANK_ORDER[skip_rank_ix+1:]) s1_ss = DeucesCard.SUIT_ORDER[1:] for r in rs: for s1_ix, s1 in enumerate(s1_ss, start=1): s0_ss = DeucesCard.SUIT_ORDER[:s1_ix] for s0 in s0_ss: yield DeucesCard(r, s0), DeucesCard(r, s1)
def _generate_four_of_a_kind() -> Iterable[Tuple[DeucesCard]]: for foak_r_ix, foak_r in enumerate(DeucesCard.RANK_ORDER): single_rs = DeucesCard.RANK_ORDER[:foak_r_ix] + DeucesCard.RANK_ORDER[foak_r_ix+1:] for single_r in single_rs: for single_s in DeucesCard.SUIT_ORDER: if DeucesCard.RANK_TO_ORDER[foak_r] < DeucesCard.RANK_TO_ORDER[single_r]: yield tuple([ *(DeucesCard(foak_r, foak_s) for foak_s in DeucesCard.SUIT_ORDER), DeucesCard(single_r, single_s), ]) else: yield tuple([ DeucesCard(single_r, single_s), *(DeucesCard(foak_r, foak_s) for foak_s in DeucesCard.SUIT_ORDER), ])
def _generate_straights(include_straight_flushes=False) -> Iterable[Tuple[DeucesCard]]: for vs_ixs in VALID_STRAIGHTS_BY_RANK_IXS: for s4 in DeucesCard.SUIT_ORDER: for s3 in DeucesCard.SUIT_ORDER: for s2 in DeucesCard.SUIT_ORDER: for s1 in DeucesCard.SUIT_ORDER: for s0 in DeucesCard.SUIT_ORDER: if ( include_straight_flushes or not s0 == s1 == s2 == s3 == s4 ): yield ( DeucesCard(DeucesCard.RANK_ORDER[r], s) for r, s in zip(vs_ixs, (s0, s1, s2, s3, s4)) )
def _generate_flushes(include_straight_flushes=False) -> Iterable[Tuple[DeucesCard]]: r4_rs = DeucesCard.RANK_ORDER[4:] # possible end cards for s in DeucesCard.SUIT_ORDER: for r4_ix, r4 in enumerate(r4_rs, start=4): r3_rs = DeucesCard.RANK_ORDER[3:r4_ix] # start at lowest possible card and go up to previous card's index for r3_ix, r3 in enumerate(r3_rs, start=3): r2_rs = DeucesCard.RANK_ORDER[2:r3_ix] for r2_ix, r2 in enumerate(r2_rs, start=2): r1_rs = DeucesCard.RANK_ORDER[1:r2_ix] for r1_ix, r1 in enumerate(r1_rs, start=1): r0_rs = DeucesCard.RANK_ORDER[:r1_ix] for r0_ix, r0 in enumerate(r0_rs): if ( include_straight_flushes or not ( # a straight (r0_ix+4) == (r1_ix+3) == (r2_ix+2) == (r3_ix+1) == r4_ix != 12 or (r0_ix, r1_ix, r2_ix, r3_ix, r4_ix) in [(0, 1, 2, 11, 12), (0, 1, 2, 3, 12)] ) ): yield (DeucesCard(r, s) for r in (r0, r1, r2, r3, r4))
def generate_all_fours() -> Iterable[Tuple[DeucesCard]]: for r in DeucesCard.RANK_ORDER: yield tuple(DeucesCard(r, s) for s in DeucesCard.SUIT_ORDER)
def generate_all_singles(skip_rank_ix: int = -1) -> Iterable[Tuple[DeucesCard]]: rs = DeucesCard.RANK_ORDER if skip_rank_ix == -1 else ( DeucesCard.RANK_ORDER[:skip_rank_ix] + DeucesCard.RANK_ORDER[skip_rank_ix+1:]) for r in rs: for s in DeucesCard.SUIT_ORDER: yield DeucesCard(r, s), # returns tuple
def _generate_straight_flush() -> Iterable[Tuple[DeucesCard]]: for vs_ixs in VALID_STRAIGHTS_BY_RANK_IXS: for s in DeucesCard.SUIT_ORDER: yield (DeucesCard(DeucesCard.RANK_ORDER[r], s) for r in vs_ixs)