Example #1
0
def range_sum_equal(fold_range, passive_range, aggressive_range,
                    original_range):
    """
    Returns validity (boolean), and reason (string, or None if valid)
    """
    # pylint:disable=R0914
    all_ranges = [fold_range, passive_range, aggressive_range]
    original_hand_options = original_range.generate_options()
    all_ranges_hand_options = concatenate([r.generate_options()
                                           for r in all_ranges])
    original_hand_options.sort(cmp=_cmp_weighted_options)
    all_ranges_hand_options.sort(cmp=_cmp_weighted_options)
    prev = (None, -1)
    # pylint:disable=W0141
    for ori, new in map(None, original_hand_options, all_ranges_hand_options):
        # we compare two hands, each of which is a set of two Card
        if ori != new:
            # actually three scenarios:
            # hand is in multiple action ranges
            # (new is the same as the previous new) 
            # hand is in action ranges but not original range
            # (new < ori means new is not in original range)
            # hand is in original range but not action ranges
            # (new > ori means ori is not in action ranges)
            if new is None:
                message =  \
                    "hand in original range but not in action ranges: %s" %  \
                    _option_to_text(ori[0])
            elif ori is None:
                message =  \
                    "hand in action ranges but not in original range: %s" %  \
                    _option_to_text(new[0])
            else:
                newh, neww = new
                orih, oriw = ori
                if newh == prev[0]:
                    message = "hand in multiple ranges: %s" %  \
                        _option_to_text(newh)
                elif _cmp_options(newh, orih) > 0:
                    message = "hand in original range but not in " +  \
                        "action ranges: %s" % _option_to_text(orih)
                elif _cmp_options(newh, orih) < 0:
                    message = "hand in action ranges but not in " +  \
                        "original range: %s" % _option_to_text(newh)
                elif neww != oriw:
                    message = "weight changed from %d to %d for hand %s" %  \
                        (oriw, neww, _option_to_text(orih))
                else:
                    raise RuntimeError("hands not equal, but can't " +  \
                                       "figure out why: %s, %s" % \
                                       (_option_to_text(orih),
                                        _option_to_text(newh)))
            return False, message
        prev = new
    return True, None
Example #2
0
def range_sum_equal(fold_range, passive_range, aggressive_range,
                    original_range):
    """
    Returns validity (boolean), and reason (string, or None if valid)
    """
    # pylint:disable=R0914
    all_ranges = [fold_range, passive_range, aggressive_range]
    original_hand_options = original_range.generate_options()
    all_ranges_hand_options = concatenate(
        [r.generate_options() for r in all_ranges])
    original_hand_options.sort(cmp=_cmp_weighted_options)
    all_ranges_hand_options.sort(cmp=_cmp_weighted_options)
    prev = (None, -1)
    # pylint:disable=W0141
    for ori, new in map(None, original_hand_options, all_ranges_hand_options):
        # we compare two hands, each of which is a set of two Card
        if ori != new:
            # actually three scenarios:
            # hand is in multiple action ranges
            # (new is the same as the previous new)
            # hand is in action ranges but not original range
            # (new < ori means new is not in original range)
            # hand is in original range but not action ranges
            # (new > ori means ori is not in action ranges)
            if new is None:
                message =  \
                    "hand in original range but not in action ranges: %s" %  \
                    _option_to_text(ori[0])
            elif ori is None:
                message =  \
                    "hand in action ranges but not in original range: %s" %  \
                    _option_to_text(new[0])
            else:
                newh, neww = new
                orih, oriw = ori
                if newh == prev[0]:
                    message = "hand in multiple ranges: %s" %  \
                        _option_to_text(newh)
                elif _cmp_options(newh, orih) > 0:
                    message = "hand in original range but not in " +  \
                        "action ranges: %s" % _option_to_text(orih)
                elif _cmp_options(newh, orih) < 0:
                    message = "hand in action ranges but not in " +  \
                        "original range: %s" % _option_to_text(newh)
                elif neww != oriw:
                    message = "weight changed from %d to %d for hand %s" %  \
                        (oriw, neww, _option_to_text(orih))
                else:
                    raise RuntimeError("hands not equal, but can't " +  \
                                       "figure out why: %s, %s" % \
                                       (_option_to_text(orih),
                                        _option_to_text(newh)))
            return False, message
        prev = new
    return True, None
Example #3
0
 def test_cmp_options(self):
     """
     Test _cmp_options
     """
     cqh = Card.from_text("Qh")
     ckh = Card.from_text("Kh")
     cah = Card.from_text("Ah")
     cks = Card.from_text("Ks")
     ckc = Card.from_text("Kc")
     kh_qh = set([ckh, cqh])
     ah_kh = set([ckh, cah])
     ks_kh = set([ckh, cks])
     kh_kc = set([ckh, ckc])
     self.assertEqual(-1, _cmp_options(kh_qh, ah_kh))
     self.assertEqual(-1, _cmp_options(kh_qh, ks_kh))
     self.assertEqual(-1, _cmp_options(kh_qh, kh_kc))
     self.assertEqual(1, _cmp_options(ah_kh, kh_qh))
     self.assertEqual(1, _cmp_options(ah_kh, ks_kh))
     self.assertEqual(1, _cmp_options(ah_kh, kh_kc))
     self.assertEqual(1, _cmp_options(ks_kh, kh_qh))
     self.assertEqual(-1, _cmp_options(ks_kh, ah_kh))
     self.assertEqual(1, _cmp_options(ks_kh, kh_kc))
     self.assertEqual(1, _cmp_options(kh_kc, kh_qh))
     self.assertEqual(-1, _cmp_options(kh_kc, ah_kh))
     self.assertEqual(-1, _cmp_options(kh_kc, ks_kh))
Example #4
0
 def test_cmp_options(self):
     """
     Test _cmp_options
     """
     cqh = Card.from_text("Qh")
     ckh = Card.from_text("Kh")
     cah = Card.from_text("Ah")
     cks = Card.from_text("Ks")
     ckc = Card.from_text("Kc")
     kh_qh = set([ckh, cqh])
     ah_kh = set([ckh, cah])
     ks_kh = set([ckh, cks])
     kh_kc = set([ckh, ckc])
     self.assertEqual(-1, _cmp_options(kh_qh, ah_kh))
     self.assertEqual(-1, _cmp_options(kh_qh, ks_kh))
     self.assertEqual(-1, _cmp_options(kh_qh, kh_kc))
     self.assertEqual(1, _cmp_options(ah_kh, kh_qh))
     self.assertEqual(1, _cmp_options(ah_kh, ks_kh))
     self.assertEqual(1, _cmp_options(ah_kh, kh_kc))
     self.assertEqual(1, _cmp_options(ks_kh, kh_qh))
     self.assertEqual(-1, _cmp_options(ks_kh, ah_kh))
     self.assertEqual(1, _cmp_options(ks_kh, kh_kc))
     self.assertEqual(1, _cmp_options(kh_kc, kh_qh))
     self.assertEqual(-1, _cmp_options(kh_kc, ah_kh))
     self.assertEqual(-1, _cmp_options(kh_kc, ks_kh))