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 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 _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_consistent(self, position, constraints=None): constraints = constraints if constraints is not None else z3.BoolVal(True) history = self._history_after_last_call_for(position) if not history: solver = _solver_pool.borrow() result = is_possible(solver, constraints) _solver_pool.restore(solver) return result return history._solve_for_consistency(constraints)
def possible_calls_for_hand(self, hand, expected_call): possible_calls = PossibleCalls(self.system.priority_ordering) solver = _solver_pool.solver_for_hand(hand) for call in self.history.legal_calls: rule = self.rule_for_call(call) if not rule: continue for priority, z3_meaning in rule.meaning_of(self.history, call): if is_possible(solver, z3_meaning): possible_calls.add_call_with_priority(call, priority) elif call == expected_call: print "%s does not fit hand: %s" % (rule, z3_meaning) return possible_calls
def _solve_for_more_points_than(self, points): return is_possible(self._solver(), model.points >= points)
def _solve_for_max_points(self): solver = self._solver() for cap in range(37, 0, -1): if is_possible(solver, cap == model.points): return cap return 0
def _solve_for_min_points(self): solver = self._solver() predicate = lambda points: is_possible(solver, model.playing_points == points) if predicate(0): return 0 return self._lower_bound(predicate, 1, 37)
def _solve_for_consistency(self, constraints): return is_possible(self._solver(), constraints)