def addTrick(self, winner): """Add single trick This method awards a single trick to the player at given position. The position can be in either serialized or internal representation. Keyword Arguments: winner -- the position of the winner """ partnership = partnershipFor(winner) self._tricks[partnership] += 1 self._set_text_helper()
def _handle_get_reply(self, get=None, counter=None, **kwargs): if counter is not None: self._counter = counter else: logging.warning("No counter included in get reply") missing = object() pubstate = get.get(PUBSTATE_TAG) or {} privstate = get.get(PRIVSTATE_TAG) or {} _self = get.get(SELF_TAG) or {} position = _self.get(POSITION_TAG, missing) if position is not missing and position != self._position: self._position = position self._card_area.setPlayerPosition(position) position_in_turn = _self.get(POSITION_IN_TURN_TAG, missing) if position_in_turn is not missing: self._card_area.setPositionInTurn(position_in_turn) allowed_calls = _self.get(ALLOWED_CALLS_TAG, missing) if allowed_calls is not missing: self._call_panel.setAllowedCalls(allowed_calls) calls = pubstate.get(CALLS_TAG, missing) if calls is not missing: self._call_table.setCalls(calls) declarer = pubstate.get(DECLARER_TAG, missing) contract = pubstate.get(CONTRACT_TAG, missing) if declarer is not missing and contract is not missing: self._bidding_result_label.setBiddingResult( declarer, contract) cards = pubstate.get(CARDS_TAG, {}) cards.update(privstate.get(CARDS_TAG, {})) if cards: self._card_area.setCards(cards) allowed_cards = _self.get(ALLOWED_CARDS_TAG, missing) if allowed_cards is not missing: self._card_area.setAllowedCards(allowed_cards) tricks = pubstate.get(TRICKS_TAG, missing) if tricks is not missing: if tricks: trick = tricks[-1].get("cards") if trick: self._card_area.setTrick(trick) tricks_won = { partnership: 0 for partnership in positions.Partnership } for trick in tricks: winner = trick.get("winner") if winner: tricks_won[positions.partnershipFor(winner)] += 1 self._tricks_won_label.setTricksWon(tricks_won) vulnerability = pubstate.get(VULNERABILITY_TAG, missing) if vulnerability is not missing: self._call_table.setVulnerability(vulnerability)
def setVulnerability(self, vulnerability): """Set vulnerabilities for partnerships Set vulnerability indications (color of header items) according to the vulnerability object given as argument. The vulnerability object is a mapping from partnership tags to vulnerability status (see bridge protocol specification). """ vulnerable_partnerships = set() try: for tag, partnership in zip(positions.PARTNERSHIP_TAGS, positions.Partnership): if vulnerability.get(tag, False): vulnerable_partnerships.add(partnership) except Exception: raise messaging.ProtocolError("Invalid vulnerability object: %r" % vulnerability) for position in positions.Position: partnership = positions.partnershipFor(position) brush = self._VULNERABILITY_BRUSHES[partnership in vulnerable_partnerships] self.horizontalHeaderItem(position).setBackground(brush)
def testAddTrick(self): position = random.choice(positions.POSITION_TAGS) partnership = positions.partnershipFor(position) self._tricks_won_label.setTricksWon(self._tricks_won) self._tricks_won_label.addTrick(position) self._assert_text_helper(partnership, 1)