def expr(self, history, call): # Nothing to say if partner hasn't bid more than one suit. if len(history.partner.bid_suits) < 2: return model.NO_CONSTRAINTS suit_expr = expr_for_suit(call.strain) # Including hearts >= hearts in this And doesn't hurt, but just reads funny when debugging. return z3.And([suit_expr >= expr_for_suit(suit) for suit in history.partner.bid_suits if suit != call.strain])
def _support_for_suits(self, suits, history): if len(suits) == 3: three_card_support_expr = z3.And([expr_for_suit(suit) >= 3 for suit in suits]) four_card_support_expr = z3.Or([self._four_in_almost_every_suit(missing_suit, suits) for missing_suit in suits]) return z3.And(three_card_support_expr, four_card_support_expr) if len(suits) == 2: return z3.And([expr_for_suit(suit) >= 4 for suit in suits]) assert False, "%s only supports 2 or 3 unbid suits, found %d: %s" % (self.__class__, len(suits), history.call_history)
def expr(self, history, call): unbid_suits = history.unbid_suits if len(unbid_suits) == 3: three_card_support_expr = z3.And([expr_for_suit(suit) >= 3 for suit in unbid_suits]) four_card_support_expr = z3.Or([self._four_in_almost_every_suit(missing_suit, unbid_suits) for missing_suit in unbid_suits]) return z3.And(three_card_support_expr, four_card_support_expr) if len(unbid_suits) == 2: return z3.And([expr_for_suit(suit) >= 4 for suit in unbid_suits]) assert False, "SupportForUnbidSuits only supports 2 or 3 unbid suits."
def _solve_for_max_length(self, suit): solver = self._solver() suit_expr = expr_for_suit(suit) for length in range(13, 0, -1): if is_possible(solver, suit_expr == length): return length return 0
def _solve_for_min_length(self, suit): solver = self._solver suit_expr = expr_for_suit(suit) for length in range(0, 13): if is_possible(solver, suit_expr == length): return length return 0
def is_unbid_suit(self, suit): suit_expr = expr_for_suit(suit) for position in positions: solver = self._solver_for_position(position) if not is_possible(solver, suit_expr < 3): return False return True
def is_bid_suit(self, suit, position): # Look for the annotation of bidding a suit. if did_bid_annotation(suit) in self.annotations_for_position(position): return True previous_history = self._history_after_last_call_for(position) if not previous_history: return False # Check for the a length of 4 or more. return is_certain(previous_history._solver(), expr_for_suit(suit) >= 4)
def expr(self, history, call): suit = call.strain if self.use_partners_last_suit: # We should assert here, except this is used to pass after a transfer accept (which is artificial) # assert annotations.Artificial not in history.partner.annotations_for_last_call suit = history.partner.last_call.strain partner_promised_length = history.partner.min_length(suit) implied_length = max(self.min_count - partner_promised_length, 0) return expr_for_suit(suit) >= implied_length
def expr(self, history, call): unbid_suits = sorted(list(history.unbid_suits))[:2] return z3.And([expr_for_suit(suit) >= 5 for suit in unbid_suits])
def _four_in_almost_every_suit(self, missing_suit, suits): return z3.And([expr_for_suit(suit) >= 4 for suit in set(suits) - set([missing_suit])])
def expr(self, history, call): partner_suit = history.partner.last_call.strain return expr_for_suit(partner_suit) >= self._min_count
def expr(self, history, call): # Written forward: level = partner_min + my_min - 6 my_count = call.level() + 6 - history.partner.min_length(call.strain) return expr_for_suit(call.strain) >= my_count
def expr(self, history, call): return expr_for_suit(call.strain) <= self.max_length
def expr(self, history, call): suit = call.strain partner_promised_length = history.partner.min_length(suit) implied_length = max(self.min_count - partner_promised_length, 0) return expr_for_suit(suit) >= implied_length
def expr(self, history, call): suit_expr = expr_for_suit(call.strain) # Including hearts >= hearts in this And doesn't hurt, but just reads funny when debugging. return z3.And([suit_expr >= expr_for_suit(suit) for suit in history.them.unbid_suits if suit != call.strain])
def expr(self, history, call): suits = self.suits or [call.strain] return z3.And([expr_for_suit(suit) >= self.min_length for suit in suits])
def expr(self, history, call): return z3.And([expr_for_suit(major) <= self.max_length for major in suit.MAJORS if major != call.strain])
def expr(self, history, call): return expr_for_suit(history.last_contract.strain) <= self.max_length