Beispiel #1
0
 def __init__(self, bid_name,
         artificial=None,
         opening=None,
         transfer_to=None,
         takeout_double=None,
         negative_double=None,
         penalty_double=None,
         lead_directing_double=None,
         blackwood=None,
         gerber=None,
         michaels_cuebid=None,
         michaels_minor_request=None,
         unusual_two_nt=None,
         stayman=None,
         jacoby_two_nt=None,
         jacoby_transfer=None,
         two_spades_puppet=None,
         fourth_suit_forcing=None,
         preempt=None,
         jordan=None,
         two_nt_feature_request=None):
     Call.__init__(self, bid_name)
     self.artificial = artificial or False
     self.preempt = preempt or False
     self.opening = opening or False
     self.transfer_to = transfer_to
     self.takeout_double = takeout_double or False
     self.negative_double = negative_double or False
     self.penalty_double = penalty_double or False
     self.lead_directing_double = lead_directing_double or False
     self.blackwood = blackwood or False
     self.gerber = gerber or False
     # FIXME: Stayman could be written more generically on HandConstraints by promising a 4-card major.
     self.stayman = stayman or False
     # FIXME: Michaels could be written more generically on HandConstraints by promising a 5-card minor.
     self.michaels_cuebid = michaels_cuebid or False
     self.michaels_minor_request = michaels_minor_request or False
     # FIXME: Unusual2NT could be written more generically on HandConstraints by promising a 5-card major.
     self.unusual_two_nt = unusual_two_nt or False
     self.jacoby_two_nt = jacoby_two_nt or False
     self.jacoby_transfer = jacoby_transfer or False
     # FIXME: TwoSpadesPuppet could be written more generically on HandConstraints by promising a 6-card minor.
     self.two_spades_puppet = two_spades_puppet or False
     self.fourth_suit_forcing = fourth_suit_forcing or False
     self.two_nt_feature_request = two_nt_feature_request or False
     self.jordan = jordan or False  # Jordan doesn't really need its own flag, no one ever checks it.
Beispiel #2
0
 def from_expectation_tuple_in_group(cls, expectation, test_group):
     hand_string = expectation[0]
     assert '.' in hand_string, "_split_expectation expectes C.D.H.S formatted hands, missing '.': %s" % hand_string
     expected_call = Call.from_string(expectation[1])
     history_string = expectation[2] if len(expectation) > 2 else ""
     vulnerability_string = expectation[3] if len(expectation) > 3 else None
     hand = Hand.from_cdhs_string(hand_string)
     call_history = CallHistory.from_string(history_string, vulnerability_string=vulnerability_string)
     return cls(test_group, hand, call_history, expected_call)
Beispiel #3
0
 def call(cls, callstring, who):
     bidder = cls.position(who)
     if pattern_pass.match(callstring):
         return CallWithStateInfo(Pass(), bidder)
     elif pattern_rdbl.match(callstring):
         return CallWithStateInfo(Rdbl(), bidder)
     elif pattern_dbl.match(callstring):
         return CallWithStateInfo(Dbl(), bidder)
     else:
         return CallWithStateInfo(Call(callstring.upper()), bidder)
Beispiel #4
0
    def possible_calls_over(self, history):
        if history.is_complete():
            return

        yield Call('P')

        last_non_pass = history.last_non_pass()
        caller = history.position_to_call()
        if last_non_pass and history.last_to_not_pass() != caller.partner:
            if last_non_pass.is_contract():
                yield Call('X')
            elif last_non_pass.is_double():
                yield Call('XX')

        last_contract = history.last_contract()
        for level in range(1, 8):
            if last_contract and level < last_contract.level:
                continue
            for strain in STRAINS:
                if last_contract and level == last_contract.level and strain <= last_contract.strain:
                    continue
                yield Call.from_level_and_strain(level, strain)
Beispiel #5
0
 def test_names(self):
     self.assertEqual(list(Call.suited_names_between('1C', '1H')), ['1C', '1D', '1H'])
     self.assertEqual(list(Call.suited_names_between('2D', '4H')), ['2D', '2H', '2S', '3C', '3D', '3H', '3S', '4C', '4D', '4H'])
     self.assertEqual(list(Call.notrump_names_between('1N', '7N')), ['1N', '2N', '3N', '4N', '5N', '6N', '7N'])
     self.assertEqual(list(Call.notrump_names_between('3N', '5N')), ['3N', '4N', '5N'])
Beispiel #6
0
 def _glob_helper(self, history, call_name):
     call = Call.from_string(call_name)
     # call_name can be empty if the original string is emtpy or there is trailing whitespace.
     if call and history.is_legal_call(call):
         yield call
Beispiel #7
0
 def _assert_is_legal_call(self, history_string, bid, is_legal=True):
     call_history = CallHistory.from_string(history_string)
     bid = Call.from_string(bid)
     self.assertEquals(call_history.is_legal_call(bid), is_legal)
Beispiel #8
0
 def _assert_is_legal_call(self, history_string, call_name, is_legal=True):
     call_history = CallHistory.from_string(history_string)
     call = Call.from_string(call_name)
     self.assertEquals(call_history.is_legal_call(call), is_legal)
Beispiel #9
0
# found in the LICENSE file.

from core import suit
from z3b import enum
from z3b.constraints import *
from z3b.model import *
from z3b.preconditions import *
from z3b.rule_compiler import Rule, rule_order, categories
from core.call import Call


def copy_dict(d, keys):
    return {key: d.get(key) for key in keys}


natural = enum.Enum(*Call.suited_names())
notrump_without_stoppers = enum.Enum(*Call.notrump_names())
notrump_with_stoppers = enum.Enum(*Call.notrump_names())


natural_slams = rule_order.order(
    notrump_without_stoppers.get('6N'), 

    natural.get('6C'),
    natural.get('6D'),
    natural.get('6H'),
    natural.get('6S'),

    notrump_with_stoppers.get('6N'), 
    notrump_without_stoppers.get('7N'),